39 #elif defined (TR_APPLE) 47 #define strCmp _stricmp 52 #define strCmp strcasecmp 58 const std::string&
Trim(std::string& toTrim)
60 while (!toTrim.empty() && isspace(static_cast<unsigned char>(toTrim[toTrim.length() - 1])))
62 toTrim.erase(toTrim.length() - 1);
65 while (!toTrim.empty() && isspace(static_cast<unsigned char>(toTrim[0])))
74 int StrCompare(
const std::string& one,
const std::string& two,
bool caseSensitive)
79 result = one.compare(two);
83 result =
strCmp(one.c_str(), two.c_str());
91 for (
unsigned i = 0; i < str.size(); ++i)
93 str[i] = tolower(str[i]);
100 std::string newStr = str;
109 for (
unsigned i = 0; i < str.size(); ++i)
111 str[i] = toupper(str[i]);
118 std::string newStr = str;
128 return u ==
"1" || u ==
"true" || u ==
"True" || u ==
"TRUE";
133 static bool Scan(
const char*& wildCards,
const char*& str)
138 for (wildCards++; *str !=
'\0' && (*wildCards ==
'?' || *wildCards ==
'*'); ++wildCards)
140 if (*wildCards ==
'?')
146 while (*wildCards ==
'*')
153 if (*str ==
'\0' && *wildCards !=
'\0')
157 else if (*str ==
'\0' && *wildCards ==
'\0')
164 const char* wdsCopy = wildCards;
165 const char* strCopy = str;
169 if (!
Match(wildCards, str)) { ++strCopy; }
172 while ((*wildCards != *str) && (*str !=
'\0')) { ++str; }
175 }
while ((*str !=
'\0') ? !
Match(wildCards, str) : (Yes =
false) !=
false);
177 if (*str ==
'\0' && *wildCards ==
'\0')
187 static bool WildMatch(
const char* wildCards,
const char* str)
192 while (*wildCards !=
'\0' && Yes && *str !=
'\0')
194 if (*wildCards ==
'?')
198 else if (*wildCards ==
'*')
200 Yes =
Scan(wildCards, str);
205 Yes = (*wildCards == *str);
210 while (*wildCards ==
'*' && Yes) { ++wildCards; }
212 return Yes && *str ==
'\0' && *wildCards ==
'\0';
216 bool Match(
const char* Wildcards,
const char* str)
224 std::ostringstream ss;
225 ss << std::setfill(
'0') << std::setw(paddedLength);
227 ss.str().swap(toFill);
231 bool TakeToken(std::string& data, std::string& outToken,
char openChar,
char closeChar)
242 else if (data.c_str()[0] != openChar)
251 while (!data.empty())
253 bool appendChar =
true;
256 if (data[dataIndex] == openChar)
266 else if (data[dataIndex] == closeChar)
279 outToken.append(data.c_str(), 1);
284 if (data.length() > 1)
310 void FindAndReplace(std::string& modifiedString,
const std::string& findWhat,
const std::string& replaceWith)
312 if (!findWhat.empty())
315 while ((pos = modifiedString.find(findWhat, pos)) != std::string::npos)
317 modifiedString.replace(pos, findWhat.length(), replaceWith);
318 pos += replaceWith.length();
323 LOG_E(
"Trying to find an empty string within a string.");
static bool WildMatch(const char *wildCards, const char *str)
static const std::string DEFAULT_LOCALE_NAME
static bool Scan(const char *&wildCards, const char *&str)
bool TR_UTIL_EXPORT Match(const char *wildCards, const char *str)
Matches.
bool TR_UTIL_EXPORT TakeToken(std::string &data, std::string &outToken, char openChar, char closeChar)
Reads the next token fromm the given string data.
void TR_UTIL_EXPORT FindAndReplace(std::string &modifiedString, const std::string &findWhat, const std::string &replaceWith)
Finds all instances of the findWhat string in the string modifiedString and replaces them with the re...
bool TR_UTIL_EXPORT FromString< bool >(const std::string &u)
Special exception for bool where things like "True", "TRUE", and "true" should be accepted...
#define LOG_E(msg)
Log an ERROR message.
TR_UTIL_EXPORT const std::string & Trim(std::string &toTrim)
Trims whitespace off the front and end of a string.
TR_UTIL_EXPORT void ToUpperCase(std::string &str)
Converts the whole string to upper case.
TR_UTIL_EXPORT int StrCompare(const std::string &one, const std::string &two, bool caseSensitive=true)
Compares strings like strcmp or stricmp or strcasecmp.
void TR_UTIL_EXPORT MakeIndexString(unsigned index, std::string &toFill, unsigned paddedLength=4)
Makes index string.
TR_UTIL_EXPORT void ToLowerCase(std::string &str)
Converts the whole string to lower case.