delpi
0.0.1
DElta-complete LP solver
Toggle main menu visibility
Loading...
Searching...
No Matches
strings.hpp
1
8
#pragma once
9
10
#include <algorithm>
11
#include <cctype>
12
#include <string_view>
13
14
namespace
delpi
{
15
23
inline
bool
ichar_equals
(
const
char
a,
const
char
b)
noexcept
{
24
return
std::tolower(
static_cast<
unsigned
char
>
(a)) == std::tolower(
static_cast<
unsigned
char
>
(b));
25
}
26
34
inline
bool
ieq
(std::string_view a, std::string_view b) {
return
std::ranges::equal(a, b,
ichar_equals
); }
35
43
inline
std::string_view
nextToken
(std::string_view &line)
noexcept
{
44
// Skip leading whitespace
45
std::size_t i = 0;
46
while
(i < line.size() && std::isspace(line[i])) ++i;
47
if
(i == line.size()) {
48
line = {};
49
return
{};
50
}
51
line.remove_prefix(i);
52
53
// Find end of token
54
std::size_t j = 0;
55
while
(j < line.size() && !std::isspace(line[j])) ++j;
56
57
const
std::string_view tok = line.substr(0, j);
58
line.remove_prefix(j);
59
return
tok;
60
}
61
68
inline
std::string_view
peakNextToken
(
const
std::string_view line)
noexcept
{
69
// Skip leading whitespace
70
std::size_t i = 0;
71
while
(i < line.size() && std::isspace(line[i])) ++i;
72
if
(i >= line.size())
return
{};
73
74
// Find end of token
75
std::size_t j = i + 1;
76
while
(j < line.size() && !std::isspace(line[j])) ++j;
77
return
line.substr(i, j - i);
78
}
79
87
inline
std::string_view
trim
(
const
std::string_view str)
noexcept
{
88
std::size_t start = 0, end = str.size() - 1;
89
while
(start < str.size() && std::isspace(str[start])) ++start;
90
while
(end > start && std::isspace(str[end])) --end;
91
return
str.substr(start, end - start + 1);
92
}
93
94
}
// namespace delpi
delpi
Global namespace for the delpi library.
delpi::peakNextToken
std::string_view peakNextToken(const std::string_view line) noexcept
Given a string, find the next word token contained within ignoring all whitespaces.
Definition
strings.hpp:68
delpi::nextToken
std::string_view nextToken(std::string_view &line) noexcept
Given a string, find the next word token contained within ignoring all whitespaces.
Definition
strings.hpp:43
delpi::ichar_equals
bool ichar_equals(const char a, const char b) noexcept
Check whether two characters are equal, ignoring case.
Definition
strings.hpp:23
delpi::trim
std::string_view trim(const std::string_view str) noexcept
Remove leading and trailing whitespace from a string.
Definition
strings.hpp:87
delpi::ieq
bool ieq(std::string_view a, std::string_view b)
Check whether two strings are the same, ignoring the case of the characters.
Definition
strings.hpp:34
delpi
util
strings.hpp
Generated by
1.17.0