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
62
63#ifndef OPENSWMM_ENGINE_TOKENIZER_HPP
64#define OPENSWMM_ENGINE_TOKENIZER_HPP
65
66#include <string>
67#include <string_view>
68#include <vector>
69
70namespace openswmm::input {
71
79class Tokenizer {
80public:
84 Tokenizer() = delete;
85
86 // -----------------------------------------------------------------------
87 // Comment handling
88 // -----------------------------------------------------------------------
89
99 static std::string_view strip_comment(std::string_view line) noexcept;
100
101 // -----------------------------------------------------------------------
102 // Tokenization
103 // -----------------------------------------------------------------------
104
117 static std::vector<std::string> tokenize(std::string_view line);
118
128 static std::vector<std::string_view> tokenize_views(std::string_view line);
129
141 static void tokenize_views_into(std::string_view line, std::vector<std::string_view>& out);
142
143 // -----------------------------------------------------------------------
144 // Utilities
145 // -----------------------------------------------------------------------
146
155 static void to_upper_inplace(std::string& s) noexcept;
156
163 static std::string to_upper(std::string_view s);
164
173 static std::string_view trim(std::string_view s) noexcept;
174
185 static bool is_numeric(std::string_view sv) noexcept;
186
193 static bool is_boolean(std::string_view sv) noexcept;
194
203 static bool parse_boolean(std::string_view sv) noexcept;
204
205private:
212 static bool is_space(char c) noexcept { return c == ' ' || c == '\t'; }
213
223 static bool is_pure_csv_line(std::string_view line) noexcept;
224
234 static bool comma_separates(std::string_view line, std::size_t pos, bool pure_csv) noexcept;
235};
236
237} /* namespace openswmm::input */
238
239#endif /* OPENSWMM_ENGINE_TOKENIZER_HPP */
static std::string_view trim(std::string_view s) noexcept
Borrow the substring without leading/trailing C-locale whitespace.
Definition Tokenizer.cpp:227
static std::vector< std::string_view > tokenize_views(std::string_view line)
Split an unquoted line into borrowed nonempty token views.
Definition Tokenizer.cpp:170
static void tokenize_views_into(std::string_view line, std::vector< std::string_view > &out)
Replace a reusable vector with borrowed nonempty token views.
Definition Tokenizer.cpp:176
static bool parse_boolean(std::string_view sv) noexcept
Interpret an untrimmed affirmative boolean token.
Definition Tokenizer.cpp:265
static std::vector< std::string > tokenize(std::string_view line)
Split a line into owned tokens using whitespace and positional comma rules.
Definition Tokenizer.cpp:87
Tokenizer()=delete
Disallow tokenizer instances; all operations are static.
static bool is_numeric(std::string_view sv) noexcept
Test whether a trimmed token parses completely as a double.
Definition Tokenizer.cpp:241
static bool is_boolean(std::string_view sv) noexcept
Recognize an untrimmed boolean token.
Definition Tokenizer.cpp:252
static std::string to_upper(std::string_view s)
Copy bytes and uppercase the copy using the current C locale.
Definition Tokenizer.cpp:221
static void to_upper_inplace(std::string &s) noexcept
Uppercase bytes in place using the current C locale.
Definition Tokenizer.cpp:215
static std::string_view strip_comment(std::string_view line) noexcept
Borrow the line prefix before its first unquoted semicolon.
Definition Tokenizer.cpp:44
Definition CatchmentHandler.cpp:70