OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
SectionParser.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
34
35#pragma once
36
37#include <string>
38#include <vector>
39
40namespace openswmm::input {
41
51struct ParsedLine {
52 std::string data;
53 std::string comment;
54};
55
68inline std::vector<ParsedLine> parse_section(const std::vector<std::string>& raw_lines) {
69 std::vector<ParsedLine> result;
70 std::string pending;
71
72 for (const auto& raw : raw_lines) {
73 if (raw.empty())
74 continue;
75
76 if (raw[0] == ';') {
77 if (raw.size() >= 2 && raw[1] == ';') {
78 // ";;" column-header or dashes line — discard and reset pending
79 pending.clear();
80 } else {
81 // Single-';' object-comment line — append to pending
82 if (!pending.empty())
83 pending += "\\n";
84 pending += raw.substr(1); // strip leading ';'
85 }
86 continue;
87 }
88
89 // Data line — package with accumulated comment
90 result.push_back({raw, std::move(pending)});
91 pending.clear();
92 }
93 return result;
94}
95
96} // namespace openswmm::input
Definition CatchmentHandler.cpp:70
std::vector< ParsedLine > parse_section(const std::vector< std::string > &raw_lines)
Pair raw section data rows with preceding object-comment text.
Definition SectionParser.hpp:68
One data row together with its associated object comment.
Definition SectionParser.hpp:51
std::string comment
Object comment joined with literal "\\n"; "" = none.
Definition SectionParser.hpp:53
std::string data
Stripped data line ready for tokenisation.
Definition SectionParser.hpp:52