26 cmp_nocase(
const string &s,
const string &s2) {
27 string::const_iterator p = s.begin();
28 string::const_iterator p2 = s2.begin();
30 while (p != s.end() && p2 != s2.end()) {
31 if (toupper(*p) != toupper(*p2)) {
32 return (toupper(*p) < toupper(*p2)) ? -1 : 1;
38 return (s2.size() == s.size()) ? 0 :
39 (s.size() < s2.size()) ? -1 : 1;
44 return (ch ==
'_') ?
'-' : toupper(ch);
49 cmp_nocase_uh(
const string &s,
const string &s2) {
50 string::const_iterator p = s.begin();
51 string::const_iterator p2 = s2.begin();
53 while (p != s.end() && p2 != s2.end()) {
54 if (toupper_uh(*p) != toupper_uh(*p2)) {
55 return (toupper_uh(*p) < toupper_uh(*p2)) ? -1 : 1;
61 return (s2.size() == s.size()) ? 0 :
62 (s.size() < s2.size()) ? -1 : 1;
73 result.reserve(s.size());
74 string::const_iterator p;
75 for (p = s.begin(); p != s.end(); ++p) {
76 result += tolower(*p);
87 result.reserve(s.size());
88 string::const_iterator p;
89 for (p = s.begin(); p != s.end(); ++p) {
90 result += toupper(*p);
109 while (pos < str.length() && isspace((
unsigned int)str[pos])) {
112 while (pos < str.length()) {
113 size_t word_start = pos;
114 while (pos < str.length() && !isspace((
unsigned int)str[pos])) {
117 words.push_back(str.substr(word_start, pos - word_start));
120 while (pos < str.length() && isspace((
unsigned int)str[pos])) {
144 while (pos < str.length()) {
145 size_t word_start = pos;
149 words.push_back(str.substr(word_start, pos - word_start));
170 tokenize(
const string &str, vector_string &words,
const string &delimiters,
171 bool discard_repeated_delimiters) {
173 while (p < str.length()) {
174 size_t q = str.find_first_of(delimiters, p);
175 if (q == string::npos) {
176 if (q - p || !discard_repeated_delimiters){
177 words.push_back(str.substr(p));
181 if (q - p || !discard_repeated_delimiters){
182 words.push_back(str.substr(p, q - p));
186 words.push_back(
string());
200 bool discard_repeated_delimiters) {
202 while (p < str.length()) {
203 size_t q = str.find_first_of(delimiters, p);
204 if (q == string::npos) {
205 if (q - p || !discard_repeated_delimiters){
206 words.push_back(str.substr(p));
210 if (q - p || !discard_repeated_delimiters){
211 words.push_back(str.substr(p, q - p));
215 words.push_back(wstring());
225 while (begin < str.size() && isspace((
unsigned int)str[begin])) {
229 return str.substr(begin);
243 return str.substr(begin);
253 size_t end = str.size();
254 while (end > begin && isspace((
unsigned int)str[end - 1])) {
258 return str.substr(begin, end - begin);
268 size_t end = str.size();
273 return str.substr(begin, end - begin);
283 while (begin < str.size() && isspace((
unsigned int)str[begin])) {
287 size_t end = str.size();
288 while (end > begin && isspace((
unsigned int)str[end - 1])) {
292 return str.substr(begin, end - begin);
306 size_t end = str.size();
311 return str.substr(begin, end - begin);
325 const char *nptr = str.c_str();
327 int result = strtol(nptr, &endptr, 10);
355 const char *nptr = str.c_str();
357 double result =
pstrtod(nptr, &endptr);
378 string_to_float(
const string &str,
float &result) {
388 string_to_stdfloat(
const string &str, PN_stdfloat &result) {
int string_to_int(const string &str, string &tail)
A string-interface wrapper around the C library strtol().
double string_to_double(const string &str, string &tail)
A string-interface wrapper around the C library strtol().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
double pstrtod(const char *nptr, char **endptr)
This function re-implements strtod, to avoid the problems that occur when the LC_NUMERIC locale gets ...
string downcase(const string &s)
Returns the input string with all uppercase letters converted to lowercase.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL vector.
int extract_words(const string &str, vector_string &words)
Divides the string into a number of words according to whitespace.
string trim(const string &str)
Returns a new string representing the contents of the given string with both leading and trailing whi...
void tokenize(const string &str, vector_string &words, const string &delimiters, bool discard_repeated_delimiters)
Chops the source string up into pieces delimited by any of the characters specified in delimiters.
string trim_left(const string &str)
Returns a new string representing the contents of the given string with the leading whitespace remove...
string upcase(const string &s)
Returns the input string with all lowercase letters converted to uppercase.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static bool unicode_isspace(char32_t character)
Returns true if the indicated character is a whitespace letter, false otherwise.
string trim_right(const string &str)
Returns a new string representing the contents of the given string with the trailing whitespace remov...