Skip to content

Commit

Permalink
Use StringExtras utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
rzblue committed Sep 1, 2023
1 parent 91b229e commit 517000f
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions hal/src/main/native/athena/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,21 +363,19 @@ void InitializeTeamNumber(void) {
return;
}

std::string hostname{hostnameBuf, sizeof(hostnameBuf)};

auto start = hostname.find('-') + 1;
auto end = hostname.find('-', start);

if (start == std::string::npos || end == std::string::npos) {
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;
}

try {
teamNumber = std::stoi(hostname.substr(start, end - start));
} catch (...) {
teamNumber = 0;
}
teamNumber = wpi::parse_integer<int32_t>(elements[1], 10).value_or(0);
}

int32_t HAL_GetTeamNumber(void) {
Expand Down

0 comments on commit 517000f

Please sign in to comment.