Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fac7267

Browse files
committed
add uppercase/lowercase helpers
1 parent b2e68ea commit fac7267

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/parsegen_string.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "parsegen_string.hpp"
22

33
#include <stdexcept>
4+
#include <cctype>
45

56
namespace parsegen {
67

@@ -71,4 +72,22 @@ std::string unquote(std::string const& s)
7172
return unescape(s.substr(1, s.length() - 2));
7273
}
7374

75+
std::string lowercase(std::string const& s) {
76+
std::string result = s;
77+
std::transform(result.begin(), result.end(), result.begin(),
78+
[] (unsigned char c) {
79+
return std::tolower(c);
80+
});
81+
return result;
82+
}
83+
84+
std::string uppercase(std::string const& s) {
85+
std::string result = s;
86+
std::transform(result.begin(), result.end(), result.begin(),
87+
[] (unsigned char c) {
88+
return std::toupper(c);
89+
});
90+
return result;
91+
}
92+
7493
}

src/parsegen_string.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ std::string unescape(std::string const& s);
2727
std::string double_quote(std::string const& s);
2828
std::string single_quote(std::string const& s);
2929
std::string unquote(std::string const& s);
30+
std::string lowercase(std::string const& s);
31+
std::string uppercase(std::string const& s);
3032

3133
} // namespace parsegen

0 commit comments

Comments
 (0)