From 517000fca642f17621291a076372bba8f1880271 Mon Sep 17 00:00:00 2001 From: Ryan Blue Date: Thu, 31 Aug 2023 23:13:09 -0400 Subject: [PATCH] Use StringExtras utilities --- hal/src/main/native/athena/HAL.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/hal/src/main/native/athena/HAL.cpp b/hal/src/main/native/athena/HAL.cpp index c8dcfe91cf5..c59e9bbe03b 100644 --- a/hal/src/main/native/athena/HAL.cpp +++ b/hal/src/main/native/athena/HAL.cpp @@ -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 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(elements[1], 10).value_or(0); } int32_t HAL_GetTeamNumber(void) {