mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
[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:
@@ -352,16 +352,15 @@ void InitializeTeamNumber(void) {
|
||||
std::string_view hostname{hostnameBuf, sizeof(hostnameBuf)};
|
||||
|
||||
// hostname is frc-{TEAM}-roborio
|
||||
// Split string around '-' (max of 2 splits), take the second element of the
|
||||
// resulting array.
|
||||
wpi::SmallVector<std::string_view> elements;
|
||||
wpi::split(hostname, elements, "-", 2);
|
||||
if (elements.size() < 3) {
|
||||
teamNumber = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
teamNumber = wpi::parse_integer<int32_t>(elements[1], 10).value_or(0);
|
||||
// Split string around '-' (max of 2 splits), take the second element
|
||||
teamNumber = 0;
|
||||
int i = 0;
|
||||
wpi::split(hostname, '-', 2, false, [&](auto part) {
|
||||
if (i == 1) {
|
||||
teamNumber = wpi::parse_integer<int32_t>(part, 10).value_or(0);
|
||||
}
|
||||
++i;
|
||||
});
|
||||
}
|
||||
|
||||
int32_t HAL_GetTeamNumber(void) {
|
||||
|
||||
@@ -245,7 +245,8 @@ void SerialHelper::QueryHubPaths(int32_t* status) {
|
||||
|
||||
wpi::SmallVector<std::string_view, 16> pathSplitVec;
|
||||
// Split path into individual directories
|
||||
wpi::split(path, pathSplitVec, '/', -1, false);
|
||||
wpi::split(path, '/', -1, false,
|
||||
[&](auto part) { pathSplitVec.emplace_back(part); });
|
||||
|
||||
// Find each individual item index
|
||||
int findusb = -1;
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/SmallVector.h>
|
||||
#include <wpi/StringExtras.h>
|
||||
#include <wpi/fs.h>
|
||||
#include <wpi/print.h>
|
||||
@@ -100,7 +99,6 @@ int HAL_LoadOneExtension(const char* library) {
|
||||
|
||||
int HAL_LoadExtensions(void) {
|
||||
int rc = 1;
|
||||
wpi::SmallVector<std::string_view, 2> libraries;
|
||||
const char* e = std::getenv("HALSIM_EXTENSIONS");
|
||||
if (!e) {
|
||||
if (GetShowNotFoundMessage()) {
|
||||
@@ -109,13 +107,11 @@ int HAL_LoadExtensions(void) {
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
wpi::split(e, libraries, DELIM, -1, false);
|
||||
for (auto& library : libraries) {
|
||||
rc = HAL_LoadOneExtension(std::string(library).c_str());
|
||||
if (rc < 0) {
|
||||
break;
|
||||
wpi::split(e, DELIM, -1, false, [&](auto library) {
|
||||
if (rc >= 0) {
|
||||
rc = HAL_LoadOneExtension(std::string(library).c_str());
|
||||
}
|
||||
}
|
||||
});
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <utility>
|
||||
|
||||
#include <wpi/MemoryBuffer.h>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/StringExtras.h>
|
||||
#include <wpi/fs.h>
|
||||
#include <wpi/mutex.h>
|
||||
@@ -233,16 +232,15 @@ void InitializeTeamNumber(void) {
|
||||
std::string_view hostname{hostnameBuf, sizeof(hostnameBuf)};
|
||||
|
||||
// hostname is frc-{TEAM}-roborio
|
||||
// Split string around '-' (max of 2 splits), take the second element of the
|
||||
// resulting array.
|
||||
wpi::SmallVector<std::string_view> elements;
|
||||
wpi::split(hostname, elements, "-", 2);
|
||||
if (elements.size() < 3) {
|
||||
teamNumber = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
teamNumber = wpi::parse_integer<int32_t>(elements[1], 10).value_or(0);
|
||||
// Split string around '-' (max of 2 splits), take the second element
|
||||
teamNumber = 0;
|
||||
int i = 0;
|
||||
wpi::split(hostname, '-', 2, false, [&](auto part) {
|
||||
if (i == 1) {
|
||||
teamNumber = wpi::parse_integer<int32_t>(part, 10).value_or(0);
|
||||
}
|
||||
++i;
|
||||
});
|
||||
}
|
||||
|
||||
int32_t HAL_GetTeamNumber(void) {
|
||||
|
||||
Reference in New Issue
Block a user