[wpiutil] Change StringExtras split() to template (#7636)

It now calls back a function for each part rather than creating a SmallVector.
This commit is contained in:
Peter Johnson
2025-01-05 20:53:43 -08:00
committed by GitHub
parent 0f6693594c
commit 03d9e96877
17 changed files with 161 additions and 171 deletions

View File

@@ -1015,7 +1015,8 @@ void NetworkTablesModel::RebuildTreeImpl(std::vector<TreeNode>* tree,
continue;
}
parts.clear();
wpi::split(entry->info.name, parts, '/', -1, false);
wpi::split(entry->info.name, '/', -1, false,
[&](auto part) { parts.emplace_back(part); });
// ignore a raw "/" key
if (parts.empty()) {

View File

@@ -68,7 +68,8 @@ void NetworkTablesProvider::DisplayMenu() {
wpi::SmallString<64> name;
for (auto&& entry : m_viewEntries) {
path.clear();
wpi::split(entry->name, path, '/', -1, false);
wpi::split(entry->name, '/', -1, false,
[&](auto name) { path.emplace_back(name); });
bool fullDepth = true;
int depth = 0;

View File

@@ -12,7 +12,6 @@
#include <imgui.h>
#include <imgui_stdlib.h>
#include <ntcore_cpp.h>
#include <wpi/SmallVector.h>
#include <wpi/StringExtras.h>
#include "glass/Context.h"
@@ -69,12 +68,10 @@ void NetworkTablesSettings::Thread::Main() {
(team = wpi::parse_integer<unsigned int>(serverTeam, 10))) {
nt::SetServerTeam(m_inst, team.value(), m_port);
} else {
wpi::SmallVector<std::string_view, 4> serverNames;
std::vector<std::pair<std::string_view, unsigned int>> servers;
wpi::split(serverTeam, serverNames, ',', -1, false);
for (auto&& serverName : serverNames) {
wpi::split(serverTeam, ',', -1, false, [&](auto serverName) {
servers.emplace_back(serverName, m_port);
}
});
nt::SetServer(m_inst, servers);
}