Panda3D
Functions
string_utils.cxx File Reference

PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University. More...

#include "string_utils.h"
#include "textEncoder.h"
#include "pstrtod.h"
#include <ctype.h>

Go to the source code of this file.

Functions

int cmp_nocase (const string &s, const string &s2)
 
int cmp_nocase_uh (const string &s, const string &s2)
 
string downcase (const string &s)
 Returns the input string with all uppercase letters converted to lowercase. More...
 
int extract_words (const string &str, vector_string &words)
 Divides the string into a number of words according to whitespace. More...
 
int extract_words (const wstring &str, pvector< wstring > &words)
 Divides the string into a number of words according to whitespace. More...
 
double string_to_double (const string &str, string &tail)
 A string-interface wrapper around the C library strtol(). More...
 
bool string_to_double (const string &str, double &result)
 Another flavor of string_to_double(), this one returns true if the string is a perfectly valid number (and sets result to that value), or false otherwise. More...
 
bool string_to_float (const string &str, float &result)
 
int string_to_int (const string &str, string &tail)
 A string-interface wrapper around the C library strtol(). More...
 
bool string_to_int (const string &str, int &result)
 Another flavor of string_to_int(), this one returns true if the string is a perfectly valid integer (and sets result to that value), or false otherwise. More...
 
bool string_to_stdfloat (const string &str, PN_stdfloat &result)
 
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. More...
 
void tokenize (const wstring &str, pvector< wstring > &words, const wstring &delimiters, bool discard_repeated_delimiters)
 Chops the source string up into pieces delimited by any of the characters specified in delimiters. More...
 
int toupper_uh (int ch)
 
string trim (const string &str)
 Returns a new string representing the contents of the given string with both leading and trailing whitespace removed. More...
 
wstring trim (const wstring &str)
 Returns a new string representing the contents of the given string with both leading and trailing whitespace removed. More...
 
string trim_left (const string &str)
 Returns a new string representing the contents of the given string with the leading whitespace removed. More...
 
wstring trim_left (const wstring &str)
 Returns a new string representing the contents of the given string with the leading whitespace removed. More...
 
string trim_right (const string &str)
 Returns a new string representing the contents of the given string with the trailing whitespace removed. More...
 
wstring trim_right (const wstring &str)
 Returns a new string representing the contents of the given string with the trailing whitespace removed. More...
 
string upcase (const string &s)
 Returns the input string with all lowercase letters converted to uppercase. More...
 

Detailed Description

PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.

All rights reserved.

All use of this software is subject to the terms of the revised BSD license. You should have received a copy of this license along with this source code in a file named "LICENSE."

Author
drose
Date
1999-01-18

Definition in file string_utils.cxx.

Function Documentation

◆ downcase()

string downcase ( const string &  s)

◆ extract_words() [1/2]

int extract_words ( const string &  str,
vector_string &  words 
)

Divides the string into a number of words according to whitespace.

The words vector should be cleared by the user before calling; otherwise, the list of words in the string will be appended to the end of whatever was there before.

The return value is the number of words extracted.

Definition at line 105 of file string_utils.cxx.

Referenced by QtessInputFile::read(), MovieTypeRegistry::register_audio_type(), TexturePool::register_texture_type(), LoaderFileTypeRegistry::register_type(), MovieTypeRegistry::register_video_type(), and LoaderFileTypeRegistry::write().

◆ extract_words() [2/2]

int extract_words ( const wstring &  str,
pvector< wstring > &  words 
)

Divides the string into a number of words according to whitespace.

The words vector should be cleared by the user before calling; otherwise, the list of words in the string will be appended to the end of whatever was there before.

The return value is the number of words extracted.

Definition at line 137 of file string_utils.cxx.

References TextEncoder::unicode_isspace().

◆ string_to_double() [1/2]

double string_to_double ( const string &  str,
string &  tail 
)

A string-interface wrapper around the C library strtol().

This parses the ASCII representation of an floating-point number, and then sets tail to everything that follows the first valid integer read. If, on exit, str == tail, there was no valid integer in the source string; if !tail.empty(), there was garbage after the number.

It is legal if str and tail refer to the same string.

Definition at line 354 of file string_utils.cxx.

References pstrtod().

Referenced by QtessInputFile::read(), and string_to_double().

◆ string_to_double() [2/2]

bool string_to_double ( const string &  str,
double &  result 
)

Another flavor of string_to_double(), this one returns true if the string is a perfectly valid number (and sets result to that value), or false otherwise.

Definition at line 368 of file string_utils.cxx.

References string_to_double().

◆ string_to_int() [1/2]

int string_to_int ( const string &  str,
string &  tail 
)

A string-interface wrapper around the C library strtol().

This parses the ASCII representation of an integer, and then sets tail to everything that follows the first valid integer read. If, on exit, str == tail, there was no valid integer in the source string; if !tail.empty(), there was garbage after the integer.

It is legal if str and tail refer to the same string.

Definition at line 324 of file string_utils.cxx.

Referenced by PT(), and string_to_int().

◆ string_to_int() [2/2]

bool string_to_int ( const string &  str,
int &  result 
)

Another flavor of string_to_int(), this one returns true if the string is a perfectly valid integer (and sets result to that value), or false otherwise.

Definition at line 338 of file string_utils.cxx.

References string_to_int().

◆ tokenize() [1/2]

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.

Repeated delimiter characters represent zero- length tokens.

It is the user's responsibility to ensure the output vector is cleared before calling this function; the results will simply be appended to the end of the vector.

Definition at line 170 of file string_utils.cxx.

Referenced by Shader::compile_parameter(), and Shader::cp_errchk_parameter_words().

◆ tokenize() [2/2]

void tokenize ( const wstring &  str,
pvector< wstring > &  words,
const wstring &  delimiters,
bool  discard_repeated_delimiters 
)

Chops the source string up into pieces delimited by any of the characters specified in delimiters.

Repeated delimiter characters represent zero- length tokens.

It is the user's responsibility to ensure the output vector is cleared before calling this function; the results will simply be appended to the end of the vector.

Definition at line 199 of file string_utils.cxx.

◆ trim() [1/2]

string trim ( const string &  str)

Returns a new string representing the contents of the given string with both leading and trailing whitespace removed.

Definition at line 281 of file string_utils.cxx.

Referenced by RangeDescription::parse_parameter(), PT(), and QtessInputFile::read().

◆ trim() [2/2]

wstring trim ( const wstring &  str)

Returns a new string representing the contents of the given string with both leading and trailing whitespace removed.

Definition at line 300 of file string_utils.cxx.

References TextEncoder::unicode_isspace().

◆ trim_left() [1/2]

string trim_left ( const string &  str)

Returns a new string representing the contents of the given string with the leading whitespace removed.

Definition at line 223 of file string_utils.cxx.

◆ trim_left() [2/2]

wstring trim_left ( const wstring &  str)

Returns a new string representing the contents of the given string with the leading whitespace removed.

Definition at line 237 of file string_utils.cxx.

References TextEncoder::unicode_isspace().

◆ trim_right() [1/2]

string trim_right ( const string &  str)

Returns a new string representing the contents of the given string with the trailing whitespace removed.

Definition at line 251 of file string_utils.cxx.

Referenced by QtessInputFile::read().

◆ trim_right() [2/2]

wstring trim_right ( const wstring &  str)

Returns a new string representing the contents of the given string with the trailing whitespace removed.

Definition at line 266 of file string_utils.cxx.

References TextEncoder::unicode_isspace().

◆ upcase()

string upcase ( const string &  s)

Returns the input string with all lowercase letters converted to uppercase.

Definition at line 85 of file string_utils.cxx.

Referenced by Texture::get_ram_image_as(), and Texture::set_ram_image_as().