[wpiutil] Add remove_prefix() and remove_suffix() (#6118)

This commit is contained in:
Joseph Eng
2024-06-04 21:01:52 -07:00
committed by GitHub
parent 8def7b2222
commit d6b66bfa55
12 changed files with 131 additions and 68 deletions

View File

@@ -157,7 +157,8 @@ void NetworkTablesProvider::Update() {
}
auto topicName = nt::GetTopicName(valueData->topic);
auto tableName = wpi::drop_back(topicName, 6);
auto tableName =
wpi::remove_suffix(topicName, "/.type").value_or(topicName);
GetOrCreateView(builderIt->second, nt::Topic{valueData->topic},
tableName);
@@ -196,9 +197,8 @@ void NetworkTablesProvider::Show(ViewEntry* entry, Window* window) {
if (!window) {
return;
}
if (wpi::starts_with(entry->name, "/SmartDashboard/")) {
window->SetDefaultName(
fmt::format("{} (SmartDashboard)", wpi::drop_front(entry->name, 16)));
if (auto name = wpi::remove_prefix(entry->name, "/SmartDashboard/")) {
window->SetDefaultName(fmt::format("{} (SmartDashboard)", *name));
}
entry->window = window;