OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
StringCase.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
41
42#ifndef OPENSWMM_ENGINE_STRING_CASE_HPP
43#define OPENSWMM_ENGINE_STRING_CASE_HPP
44
45#include <cstddef>
46#include <cstdint>
47#include <string_view>
48
49namespace openswmm {
50
52inline constexpr char ci_upper(char c) noexcept {
53 return (c >= 'a' && c <= 'z') ? static_cast<char>(c & ~32) : c;
54}
55
57inline bool ieq(std::string_view a, std::string_view b) noexcept {
58 if (a.size() != b.size()) return false;
59 for (std::size_t i = 0; i < a.size(); ++i)
60 if (ci_upper(a[i]) != ci_upper(b[i])) return false;
61 return true;
62}
63
65struct CiHash {
66 using is_transparent = void;
67 std::size_t operator()(std::string_view s) const noexcept {
68 std::uint64_t h = 14695981039346656037ull;
69 for (char c : s) {
70 h ^= static_cast<std::uint64_t>(
71 static_cast<unsigned char>(ci_upper(c)));
72 h *= 1099511628211ull;
73 }
74 return static_cast<std::size_t>(h);
75 }
76};
77
79struct CiEqual {
80 using is_transparent = void;
81 bool operator()(std::string_view a, std::string_view b) const noexcept {
82 return ieq(a, b);
83 }
84};
85
86} /* namespace openswmm */
87
88#endif /* OPENSWMM_ENGINE_STRING_CASE_HPP */
Definition NodeCoupling.cpp:16
constexpr char ci_upper(char c) noexcept
ASCII-only uppercase fold; mirrors legacy hash.c UCHAR exactly.
Definition StringCase.hpp:52
bool ieq(std::string_view a, std::string_view b) noexcept
Case-insensitive equality (ASCII fold), matching legacy samestr().
Definition StringCase.hpp:57
Transparent case-insensitive equality for unordered containers.
Definition StringCase.hpp:79
void is_transparent
Definition StringCase.hpp:80
bool operator()(std::string_view a, std::string_view b) const noexcept
Definition StringCase.hpp:81
Transparent case-insensitive hash (FNV-1a over the uppercase fold).
Definition StringCase.hpp:65
void is_transparent
Definition StringCase.hpp:66
std::size_t operator()(std::string_view s) const noexcept
Definition StringCase.hpp:67