Panda3D
Functions
string_utils.h File Reference

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

#include "dtoolbase.h"
#include <string>
#include "vector_string.h"
#include "pdtoa.h"
#include "string_utils.I"

Go to the source code of this file.

Functions

EXPCL_DTOOL_DTOOLUTIL int cmp_nocase (const std::string &s, const std::string &s2)
 
EXPCL_DTOOL_DTOOLUTIL int cmp_nocase_uh (const std::string &s, const std::string &s2)
 
EXPCL_DTOOL_DTOOLUTIL std::string downcase (const std::string &s)
 Returns the input string with all uppercase letters converted to lowercase. More...
 
EXPCL_DTOOL_DTOOLUTIL int extract_words (const std::string &str, vector_string &words)
 Divides the string into a number of words according to whitespace. More...
 
EXPCL_DTOOL_DTOOLUTIL int extract_words (const std::wstring &str, pvector< std::wstring > &words)
 Divides the string into a number of words according to whitespace. More...
 
template<class Thing >
std::string format_string (const Thing &thing)
 
std::string format_string (const std::string &value)
 
std::string format_string (bool value)
 
std::string format_string (float value)
 
std::string format_string (double value)
 
std::string format_string (unsigned int value)
 
std::string format_string (int value)
 
std::string format_string (int64_t value)
 
EXPCL_DTOOL_DTOOLUTIL double string_to_double (const std::string &str, std::string &tail)
 A string-interface wrapper around the C library strtol(). More...
 
EXPCL_DTOOL_DTOOLUTIL bool string_to_double (const std::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...
 
EXPCL_DTOOL_DTOOLUTIL bool string_to_float (const std::string &str, float &result)
 
EXPCL_DTOOL_DTOOLUTIL int string_to_int (const std::string &str, std::string &tail)
 A string-interface wrapper around the C library strtol(). More...
 
EXPCL_DTOOL_DTOOLUTIL bool string_to_int (const std::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...
 
EXPCL_DTOOL_DTOOLUTIL bool string_to_stdfloat (const std::string &str, PN_stdfloat &result)
 
EXPCL_DTOOL_DTOOLUTIL void tokenize (const std::string &str, vector_string &words, const std::string &delimiters, bool discard_repeated_delimiters=false)
 Chops the source string up into pieces delimited by any of the characters specified in delimiters. More...
 
EXPCL_DTOOL_DTOOLUTIL void tokenize (const std::wstring &str, pvector< std::wstring > &words, const std::wstring &delimiters, bool discard_repeated_delimiters=false)
 Chops the source string up into pieces delimited by any of the characters specified in delimiters. More...
 
EXPCL_DTOOL_DTOOLUTIL std::string trim (const std::string &str)
 Returns a new string representing the contents of the given string with both leading and trailing whitespace removed. More...
 
EXPCL_DTOOL_DTOOLUTIL std::wstring trim (const std::wstring &str)
 Returns a new string representing the contents of the given string with both leading and trailing whitespace removed. More...
 
EXPCL_DTOOL_DTOOLUTIL std::string trim_left (const std::string &str)
 Returns a new string representing the contents of the given string with the leading whitespace removed. More...
 
EXPCL_DTOOL_DTOOLUTIL std::wstring trim_left (const std::wstring &str)
 Returns a new string representing the contents of the given string with the leading whitespace removed. More...
 
EXPCL_DTOOL_DTOOLUTIL std::string trim_right (const std::string &str)
 Returns a new string representing the contents of the given string with the trailing whitespace removed. More...
 
EXPCL_DTOOL_DTOOLUTIL std::wstring trim_right (const std::wstring &str)
 Returns a new string representing the contents of the given string with the trailing whitespace removed. More...
 
EXPCL_DTOOL_DTOOLUTIL std::string upcase (const std::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.h.

Function Documentation

◆ downcase()

EXPCL_DTOOL_DTOOLUTIL std::string downcase ( const std::string &  s)

◆ extract_words() [1/2]

EXPCL_DTOOL_DTOOLUTIL 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]

EXPCL_DTOOL_DTOOLUTIL 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]

EXPCL_DTOOL_DTOOLUTIL 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]

EXPCL_DTOOL_DTOOLUTIL bool string_to_double ( const std::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]

EXPCL_DTOOL_DTOOLUTIL 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]

EXPCL_DTOOL_DTOOLUTIL bool string_to_int ( const std::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]

EXPCL_DTOOL_DTOOLUTIL 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]

EXPCL_DTOOL_DTOOLUTIL 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]

EXPCL_DTOOL_DTOOLUTIL std::string trim ( const std::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]

EXPCL_DTOOL_DTOOLUTIL std::wstring trim ( const std::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]

EXPCL_DTOOL_DTOOLUTIL std::string trim_left ( const std::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]

EXPCL_DTOOL_DTOOLUTIL std::wstring trim_left ( const std::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]

EXPCL_DTOOL_DTOOLUTIL std::string trim_right ( const std::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]

EXPCL_DTOOL_DTOOLUTIL std::wstring trim_right ( const std::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()

EXPCL_DTOOL_DTOOLUTIL std::string upcase ( const std::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().