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
74inline std::vector<ParsedLine>
75parse_section(const std::vector<std::string>& raw_lines)
76{
77 std::vector<ParsedLine> result;
78 std::string pending;
79
80 for (const auto& raw : raw_lines) {
81 if (raw.empty()) continue;
82
83 if (raw[0] == ';') {
84 if (raw.size() >= 2 && raw[1] == ';') {
85 // ";;" column-header or dashes line — discard and reset pending
86 pending.clear();
87 } else {
88 // Single-';' object-comment line — append to pending
89 if (!pending.empty()) pending += "\\n";
90 pending += raw.substr(1); // strip leading ';'
91 }
92 continue;
93 }
94
95 // Data line — package with accumulated comment
96 result.push_back({raw, std::move(pending)});
97 pending.clear();
98 }
99 return result;
100}
101
102} // namespace openswmm::input
Definition CatchmentHandler.cpp:69
std::vector< ParsedLine > parse_section(const std::vector< std::string > &raw_lines)
Split raw section lines into (data, comment) pairs.
Definition SectionParser.hpp:75
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