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
57inline constexpr char ci_upper(char c) noexcept {
58 return (c >= 'a' && c <= 'z') ? static_cast<char>(c & ~32) : c;
59}
60
70inline bool ieq(std::string_view a, std::string_view b) noexcept {
71 if (a.size() != b.size())
72 return false;
73 for (std::size_t i = 0; i < a.size(); ++i)
74 if (ci_upper(a[i]) != ci_upper(b[i]))
75 return false;
76 return true;
77}
78
80struct CiHash {
81 using is_transparent = void;
90 std::size_t operator()(std::string_view s) const noexcept {
91 std::uint64_t h = 14695981039346656037ull;
92 for (char c : s) {
93 h ^= static_cast<std::uint64_t>(static_cast<unsigned char>(ci_upper(c)));
94 h *= 1099511628211ull;
95 }
96 return static_cast<std::size_t>(h);
97 }
98};
99
101struct CiEqual {
102 using is_transparent = void;
110 bool operator()(std::string_view a, std::string_view b) const noexcept { return ieq(a, b); }
111};
112
113} /* namespace openswmm */
114
115#endif /* OPENSWMM_ENGINE_STRING_CASE_HPP */
Definition ExchangeLaw.hpp:60
constexpr char ci_upper(char c) noexcept
Fold one ASCII lowercase letter to uppercase without locale rules.
Definition StringCase.hpp:57
bool ieq(std::string_view a, std::string_view b) noexcept
Compare two byte sequences using the legacy ASCII uppercase fold.
Definition StringCase.hpp:70
Transparent case-insensitive equality for unordered containers.
Definition StringCase.hpp:101
void is_transparent
Definition StringCase.hpp:102
bool operator()(std::string_view a, std::string_view b) const noexcept
Compare heterogeneous container keys with legacy name equality.
Definition StringCase.hpp:110
Transparent case-insensitive hash (FNV-1a over the uppercase fold).
Definition StringCase.hpp:80
void is_transparent
Definition StringCase.hpp:81
std::size_t operator()(std::string_view s) const noexcept
Hash borrowed bytes using 64-bit FNV-1a after ASCII uppercase folding.
Definition StringCase.hpp:90