1 #ifndef MISC_STRINGOPS_H
2 #define MISC_STRINGOPS_H
64 if (ch >= 0x0410 && ch < 0x0430)
72 if (ch >= 0x41 && ch < 0x60)
76 if (ch == 0xc4 || ch == 0xd6 || ch == 0xdc)
94 while (!stream.eof ())
98 if (character <= 0x7f)
99 out.append(1, static_cast<char>(character));
100 else if (character <= 0x7ff)
102 out.append(1, static_cast<char>(0xc0 | ((character >> 6) & 0x1f)));
103 out.append(1, static_cast<char>(0x80 | (character & 0x3f)));
105 else if (character <= 0xffff)
107 out.append(1, static_cast<char>(0xe0 | ((character >> 12) & 0x0f)));
108 out.append(1, static_cast<char>(0x80 | ((character >> 6) & 0x3f)));
109 out.append(1, static_cast<char>(0x80 | (character & 0x3f)));
113 out.append(1, static_cast<char>(0xf0 | ((character >> 18) & 0x07)));
114 out.append(1, static_cast<char>(0x80 | ((character >> 12) & 0x3f)));
115 out.append(1, static_cast<char>(0x80 | ((character >> 6) & 0x3f)));
116 out.append(1, static_cast<char>(0x80 | (character & 0x3f)));
125 static bool ciLess(
const std::string &x,
const std::string &y) {
126 return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(),
ci());
129 static bool ciEqual(
const std::string &x,
const std::string &y) {
130 if (x.size() != y.size()) {
133 std::string::const_iterator xit = x.begin();
134 std::string::const_iterator yit = y.begin();
135 for (; xit != x.end(); ++xit, ++yit) {
143 static int ciCompareLen(
const std::string &x,
const std::string &y,
size_t len)
145 std::string::const_iterator xit = x.begin();
146 std::string::const_iterator yit = y.begin();
147 for(;xit != x.end() && yit != y.end() && len > 0;++xit,++yit,--len)
156 int res = left - right;
158 return (res > 0) ? 1 : -1;
172 for (
unsigned int i=0; i<inout.size(); ++i)
179 std::string out = in;
186 bool operator()(
const std::string& left,
const std::string& right)
const
188 return ciLess(left, right);
194 template<
typename Iterator,
typename T>
197 const Iterator notFound = end;
201 const Iterator middle = begin + (
std::distance(begin, end) / 2);
226 static std::string &
replaceAll(std::string &str,
const char *what,
const char *with,
227 std::size_t whatLen=std::string::npos, std::size_t withLen=std::string::npos)
229 if (whatLen == std::string::npos)
230 whatLen = strlen(what);
232 if (withLen == std::string::npos)
233 withLen = strlen(with);
236 std::size_t offset = 0;
237 while((found = str.find(what, offset, whatLen)) != std::string::npos)
239 str.replace(found, whatLen, with, withLen);
240 offset = found + withLen;
Definition: stringops.hpp:13
static bool ciEqual(const std::string &x, const std::string &y)
Definition: stringops.hpp:129
bool operator()(const std::string &left, const std::string &right) const
Definition: stringops.hpp:186
static Iterator partialBinarySearch(Iterator begin, Iterator end, const T &key)
Performs a binary search on a sorted container for a string that 'key' starts with.
Definition: stringops.hpp:195
static bool ciLess(const std::string &x, const std::string &y)
Definition: stringops.hpp:125
static char toLower(char c)
Definition: stringops.hpp:27
static std::string lowerCase(const std::string &in)
Returns lower case copy of input string.
Definition: stringops.hpp:177
bool operator()(char x, char y) const
Definition: stringops.hpp:17
Definition: utf8stream.hpp:7
static int ciCompareLen(const std::string &x, const std::string &y, size_t len)
Definition: stringops.hpp:143
Definition: stringops.hpp:184
Definition: stringops.hpp:15
uint32_t UnicodeChar
Definition: utf8stream.hpp:11
static std::string & replaceAll(std::string &str, const char *what, const char *with, std::size_t whatLen=std::string::npos, std::size_t withLen=std::string::npos)
Replaces all occurrences of a string in another string.
Definition: stringops.hpp:226
float distance(const ESM::Pathgrid::Point &point, float x, float y, float z)
Definition: pathfinding.cpp:69
static void lowerCaseInPlace(std::string &inout)
Transforms input string to lower case w/o copy.
Definition: stringops.hpp:171
static std::string lowerCaseUtf8(const std::string str)
Definition: stringops.hpp:86
static Utf8Stream::UnicodeChar toLowerUtf8(Utf8Stream::UnicodeChar ch)
Definition: stringops.hpp:61