-
Notifications
You must be signed in to change notification settings - Fork 369
/
Copy pathstring.cpp
64 lines (51 loc) · 1.44 KB
/
string.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2022 ISciences LLC
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************/
#include <algorithm>
#include <geos/util/string.h>
namespace geos {
namespace util {
// https://stackoverflow.com/a/874160/2171894
bool endsWith(const std::string & s, const std::string & suffix) {
if (s.length() < suffix.length()) {
return false;
}
return s.compare(s.length() - suffix.length(),
suffix.length(),
suffix) == 0;
}
bool endsWith(const std::string & s, char suffix) {
if (s.empty()) {
return false;
}
return s[s.length() - 1] == suffix;
}
bool startsWith(const std::string & s, const std::string & prefix) {
if (s.length() < prefix.length()) {
return false;
}
auto cmp = s.compare(0, prefix.length(), prefix);
return cmp == 0;
}
bool startsWith(const std::string & s, char prefix) {
if (s.empty() == 0) {
return false;
}
return s[0] == prefix;
}
void toUpper(std::string& s)
{
std::transform(s.begin(), s.end(), s.begin(), ::toupper);
}
}
}