OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
Tokenizer.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2//
3// Copyright 2026 Caleb Buahin
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
45
46#ifndef OPENSWMM_ENGINE_TOKENIZER_HPP
47#define OPENSWMM_ENGINE_TOKENIZER_HPP
48
49#include <string>
50#include <string_view>
51#include <vector>
52
53namespace openswmm::input {
54
62class Tokenizer {
63public:
64 Tokenizer() = delete;
65
66 // -----------------------------------------------------------------------
67 // Comment handling
68 // -----------------------------------------------------------------------
69
83 static std::string_view strip_comment(std::string_view line) noexcept;
84
85 // -----------------------------------------------------------------------
86 // Tokenization
87 // -----------------------------------------------------------------------
88
108 static std::vector<std::string> tokenize(std::string_view line);
109
123 static std::vector<std::string_view> tokenize_views(std::string_view line);
124
137 static void tokenize_views_into(std::string_view line,
138 std::vector<std::string_view>& out);
139
140 // -----------------------------------------------------------------------
141 // Utilities
142 // -----------------------------------------------------------------------
143
148 static void to_upper_inplace(std::string& s) noexcept;
149
153 static std::string to_upper(std::string_view s);
154
158 static std::string_view trim(std::string_view s) noexcept;
159
165 static bool is_numeric(std::string_view sv) noexcept;
166
170 static bool is_boolean(std::string_view sv) noexcept;
171
177 static bool parse_boolean(std::string_view sv) noexcept;
178
179private:
181 static bool is_delimiter(char c) noexcept {
182 return c == ',' || c == '\t' || c == ' ';
183 }
184};
185
186} /* namespace openswmm::input */
187
188#endif /* OPENSWMM_ENGINE_TOKENIZER_HPP */
static std::string_view trim(std::string_view s) noexcept
Trim leading and trailing whitespace from a string_view.
Definition Tokenizer.cpp:176
static std::vector< std::string_view > tokenize_views(std::string_view line)
Split a line and return string_view tokens (zero-allocation).
Definition Tokenizer.cpp:125
static void tokenize_views_into(std::string_view line, std::vector< std::string_view > &out)
tokenize_views into a caller-owned buffer.
Definition Tokenizer.cpp:131
static bool parse_boolean(std::string_view sv) noexcept
Parse a boolean token.
Definition Tokenizer.cpp:211
static std::vector< std::string > tokenize(std::string_view line)
Split a SWMM input line into tokens.
Definition Tokenizer.cpp:61
static bool is_numeric(std::string_view sv) noexcept
Returns true if sv represents a numeric value.
Definition Tokenizer.cpp:188
static bool is_boolean(std::string_view sv) noexcept
Returns true if sv represents a boolean YES/NO/TRUE/FALSE/1/0.
Definition Tokenizer.cpp:198
static std::string to_upper(std::string_view s)
Convert a string to uppercase (returns new string).
Definition Tokenizer.cpp:170
static void to_upper_inplace(std::string &s) noexcept
Convert a string to uppercase in-place.
Definition Tokenizer.cpp:164
static std::string_view strip_comment(std::string_view line) noexcept
Strip trailing semicolon comment from a line.
Definition Tokenizer.cpp:44
Definition CatchmentHandler.cpp:69