Loading...
Searching...
No Matches
String Utilities

Functions/classes for string manipulation. More...

Files

file  hash.h
 
file  patternMatcher.h
 A simple glob and regex matching utility.
 
file  stringUtils.h
 Definitions of basic string utilities in tf.
 
file  unicodeUtils.h
 Definitions of basic UTF-8 utilities in tf.
 

Classes

class  TfDictionaryLessThan
 Provides dictionary ordering binary predicate function on strings. More...
 
struct  TfStreamFloat
 A type which offers streaming for floats in a canonical format that can safely roundtrip with the minimal number of digits. More...
 
struct  TfStreamDouble
 A type which offers streaming for doubles in a canonical format that can safely roundtrip with the minimal number of digits. More...
 
class  TfHash
 A user-extensible hashing mechanism for use with runtime hash tables. More...
 
class  TfPatternMatcher
 Class for matching regular expressions. More...
 
class  TfTemplateString
 TfTemplateString provides simple string substitutions based on named placeholders. More...
 
class  TfToken
 Token for efficient comparison, assignment, and hashing of known strings. More...
 
class  TfUtf8CodePoint
 Wrapper for a 32-bit code point value that can be encoded as UTF-8. More...
 
class  TfUtf8CodePointView
 Wrapper for a UTF-8 encoded std::string_view that can be iterated over as code points instead of bytes. More...
 

Functions

TF_API std::string TfStringPrintf (const char *fmt,...)
 Returns a string formed by a printf()-like specification.
 
TF_API std::string TfVStringPrintf (const std::string &fmt, va_list ap)
 Returns a string formed by a printf()-like specification.
 
TF_API std::string TfVStringPrintf (const char *fmt, va_list ap)
 Bloat-avoidance version of TfVStringPrintf()
 
std::string TfSafeString (const char *ptr)
 Safely create a std::string from a (possibly NULL) char*.
 
std::string TfIntToString (int i)
 Returns the given integer as a string.
 
TF_API double TfStringToDouble (const std::string &txt)
 Converts text string to double.
 
TF_API double TfStringToDouble (const char *text)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
TF_API double TfStringToDouble (const char *text, int len)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
TF_API long TfStringToLong (const std::string &txt, bool *outOfRange=NULL)
 Convert a sequence of digits in txt to a long int value.
 
TF_API long TfStringToLong (const char *txt, bool *outOfRange=NULL)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
TF_API unsigned long TfStringToULong (const std::string &txt, bool *outOfRange=NULL)
 Convert a sequence of digits in txt to an unsigned long value.
 
TF_API unsigned long TfStringToULong (const char *txt, bool *outOfRange=NULL)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
TF_API int64_t TfStringToInt64 (const std::string &txt, bool *outOfRange=NULL)
 Convert a sequence of digits in txt to an int64_t value.
 
TF_API int64_t TfStringToInt64 (const char *txt, bool *outOfRange=NULL)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
TF_API uint64_t TfStringToUInt64 (const std::string &txt, bool *outOfRange=NULL)
 Convert a sequence of digits in txt to a uint64_t value.
 
TF_API uint64_t TfStringToUInt64 (const char *txt, bool *outOfRange=NULL)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool TfStringStartsWith (const std::string &s, const char *prefix)
 Returns true if s starts with prefix.
 
bool TfStringStartsWith (const std::string &s, const std::string &prefix)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool TfStringEndsWith (const std::string &s, const char *suffix)
 Returns true if s ends with suffix.
 
bool TfStringEndsWith (const std::string &s, const std::string &suffix)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
TF_API bool TfStringContains (const std::string &s, const char *substring)
 Returns true if s contains substring.
 
bool TfStringContains (const std::string &s, const std::string &substring)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
TF_API bool TfStringContains (const std::string &s, const TfToken &substring)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
TF_API std::string TfStringToLower (const std::string &source)
 Makes all characters in source lowercase, and returns the result.
 
TF_API std::string TfStringToUpper (const std::string &source)
 Makes all characters in source uppercase, and returns the result.
 
TF_API std::string TfStringCapitalize (const std::string &source)
 Returns a copy of the source string with only its first character capitalized.
 
TF_API std::string TfStringToLowerAscii (const std::string &source)
 Locale-independent case folding of [A-Z] for ASCII or UTF-8 encoded source strings.
 
TF_API std::string TfStringTrimLeft (const std::string &s, const char *trimChars=" \n\t\r")
 Trims characters (by default, whitespace) from the left.
 
TF_API std::string TfStringTrimRight (const std::string &s, const char *trimChars=" \n\t\r")
 Trims characters (by default, whitespace) from the right.
 
TF_API std::string TfStringTrim (const std::string &s, const char *trimChars=" \n\t\r")
 Trims characters (by default, whitespace) from the beginning and end of string.
 
TF_API std::string TfStringGetCommonPrefix (std::string a, std::string b)
 Returns the common prefix of the input strings, if any.
 
TF_API std::string TfStringGetSuffix (const std::string &name, char delimiter='.')
 Returns the suffix of a string.
 
TF_API std::string TfStringGetBeforeSuffix (const std::string &name, char delimiter='.')
 Returns everything up to the suffix of a string.
 
TF_API std::string TfGetBaseName (const std::string &fileName)
 Returns the base name of a file (final component of the path).
 
TF_API std::string TfGetPathName (const std::string &fileName)
 Returns the path component of a file (complement of TfGetBaseName()).
 
TF_API std::string TfStringReplace (const std::string &source, const std::string &from, const std::string &to)
 Replaces all occurrences of string from with to in source.
 
template<class ForwardIterator >
std::string TfStringJoin (ForwardIterator begin, ForwardIterator end, const char *separator=" ")
 Concatenates the strings (begin, end), with default separator.
 
TF_API std::string TfStringJoin (const std::vector< std::string > &strings, const char *separator=" ")
 Concatenates strings, with default separator.
 
TF_API std::string TfStringJoin (const std::set< std::string > &strings, const char *separator=" ")
 Concatenates strings, with default separator.
 
TF_API std::vector< std::string > TfStringSplit (std::string const &src, std::string const &separator)
 Breaks the given string apart, returning a vector of strings.
 
TF_API std::vector< std::string > TfStringTokenize (const std::string &source, const char *delimiters=" \t\n")
 Breaks the given string apart, returning a vector of strings.
 
TF_API std::set< std::string > TfStringTokenizeToSet (const std::string &source, const char *delimiters=" \t\n")
 Breaks the given string apart, returning a set of strings.
 
TF_API std::vector< std::string > TfQuotedStringTokenize (const std::string &source, const char *delimiters=" \t\n", std::string *errors=NULL)
 Breaks the given quoted string apart, returning a vector of strings.
 
TF_API std::vector< std::string > TfMatchedStringTokenize (const std::string &source, char openDelimiter, char closeDelimiter, char escapeCharacter='\0', std::string *errors=NULL)
 Breaks the given string apart by matching delimiters.
 
std::vector< std::string > TfMatchedStringTokenize (const std::string &source, char openDelimiter, char closeDelimiter, std::string *errors)
 This overloaded version of TfMatchedStringTokenize does not take an escapeCharacter parameter but does take.
 
template<typename T >
std::string TfStringify (const T &v)
 Convert an arbitrary type into a string.
 
TF_API std::string TfStringify (bool v)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
TF_API std::string TfStringify (std::string const &)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
TF_API std::string TfStringify (float)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
TF_API std::string TfStringify (double)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
TF_API bool TfDoubleToString (double d, char *buffer, int len, bool emitTrailingZero)
 Writes the string representation of d to buffer of length len.
 
TF_API std::ostream & operator<< (std::ostream &o, TfStreamFloat t)
 
TF_API std::ostream & operator<< (std::ostream &o, TfStreamDouble t)
 
template<typename T >
TfUnstringify (const std::string &instring, bool *status=NULL)
 Convert a string to an arbitrary type.
 
template<>
TF_API bool TfUnstringify (const std::string &instring, bool *status)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
TF_API std::string TfStringGlobToRegex (const std::string &s)
 Returns a string with glob characters converted to their regular expression equivalents.
 
TF_API std::string TfEscapeString (const std::string &in)
 Process escape sequences in ANSI C string constants.
 
TF_API void TfEscapeStringReplaceChar (const char **in, char **out)
 
TF_API std::string TfStringCatPaths (const std::string &prefix, const std::string &suffix)
 Concatenate two strings containing '/' and '..' tokens like a file path or scope name.
 
bool TfIsValidIdentifier (std::string const &identifier)
 Test whether identifier is valid.
 
TF_API std::string TfMakeValidIdentifier (const std::string &in)
 Produce a valid identifier (see TfIsValidIdentifier) from in by replacing invalid characters with '_'.
 
TF_API std::string TfGetXmlEscapedString (const std::string &in)
 Escapes characters in in so that they are valid XML.
 

Detailed Description

Functions/classes for string manipulation.

Function Documentation

◆ TfDoubleToString()

TF_API bool TfDoubleToString ( double  d,
char *  buffer,
int  len,
bool  emitTrailingZero 
)

Writes the string representation of d to buffer of length len.

If emitTrailingZero is true, the string representation will end with .0 in the case where d is an integer otherwise it will be omitted. The buffer length must be at least 25 in order to ensure that all doubles values can be represented. Returns whether the conversion was successful.

◆ TfEscapeString()

TF_API std::string TfEscapeString ( const std::string &  in)

Process escape sequences in ANSI C string constants.

The following escape sequences are accepted:

  • \\: backslash
  • \a: ring the bell
  • \b: backspace
  • \f: form feed
  • \n: new line
  • \r: carriage return
  • \t: tab
  • \v: vertical tab
  • \xdd: hex constant
  • \ddd: octal constant

So, if the two-character sequence "\\n" appears in the string, it is replaced by an actual newline. Each hex and octal constant translates into one character in the output string. Hex constants can be up to 2 digits, octal constants can be up to 3 digits. Both are terminated by a character that is not a valid constant. Note that it is good practice to encode hex and octal constants with maximum width (2 and 3 digits, respectively) using leading zeroes if necessary. This avoids problems where characters after the hex/octal constant that shouldn't be part of the constant get interpreted as part of it. For example, the sequence "\x2defaced" will produce the characters "-efaced" when what was probably intended was the character 0x02 (STX) followed by "defaced". Illegal escape sequences are replaced by the character following the backslash, so the two character sequence "\\c" would become "c". Processing continues until the input hits a NUL character in the input string - anything appearing after the NUL will be ignored.

◆ TfGetBaseName()

TF_API std::string TfGetBaseName ( const std::string &  fileName)

Returns the base name of a file (final component of the path).

◆ TfGetPathName()

TF_API std::string TfGetPathName ( const std::string &  fileName)

Returns the path component of a file (complement of TfGetBaseName()).

The returned string ends in a '/' (or possibly a '\' on Windows), unless none was found in fileName, in which case the empty string is returned. In particular, TfGetPathName(s)+TfGetBaseName(s) == s for any string s (as long as s doesn't end with multiple adjacent slashes, which is illegal).

◆ TfGetXmlEscapedString()

TF_API std::string TfGetXmlEscapedString ( const std::string &  in)

Escapes characters in in so that they are valid XML.

Returns the name with special characters (&, <, >, ", ') replaced with the corresponding escape sequences.

◆ TfIntToString()

std::string TfIntToString ( int  i)
inline

Returns the given integer as a string.

Definition at line 108 of file stringUtils.h.

◆ TfIsValidIdentifier()

bool TfIsValidIdentifier ( std::string const &  identifier)
inline

Test whether identifier is valid.

An identifier is valid if it follows the C/Python identifier convention; that is, it must be at least one character long, must start with a letter or underscore, and must contain only letters, underscores, and numerals.

Definition at line 712 of file stringUtils.h.

◆ TfMakeValidIdentifier()

TF_API std::string TfMakeValidIdentifier ( const std::string &  in)

Produce a valid identifier (see TfIsValidIdentifier) from in by replacing invalid characters with '_'.

If in is empty, return "_".

◆ TfMatchedStringTokenize() [1/2]

TF_API std::vector< std::string > TfMatchedStringTokenize ( const std::string &  source,
char  openDelimiter,
char  closeDelimiter,
char  escapeCharacter = '\0',
std::string *  errors = NULL 
)

Breaks the given string apart by matching delimiters.

The string source is broken apart into individual words, where a word begins with openDelimiter and ends with a matching closeDelimiter. Any delimiters within the matching delimiters become part of the word, and anything outside matching delimiters gets dropped. For example, TfMatchedStringTokenize("{a} string {to {be} split}", '{', '}') would return a vector containing "a" and "to {be} split". If openDelimiter and closeDelimiter cannot be the same. errors, if provided, contains any error messages.

◆ TfMatchedStringTokenize() [2/2]

std::vector< std::string > TfMatchedStringTokenize ( const std::string &  source,
char  openDelimiter,
char  closeDelimiter,
std::string *  errors 
)
inline

This overloaded version of TfMatchedStringTokenize does not take an escapeCharacter parameter but does take.

Parameters
errors.It allows TfMatchedStringTokenize to be called with or without an escapeCharacter and with or without errors.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 489 of file stringUtils.h.

◆ TfQuotedStringTokenize()

TF_API std::vector< std::string > TfQuotedStringTokenize ( const std::string &  source,
const char *  delimiters = " \t\n",
std::string *  errors = NULL 
)

Breaks the given quoted string apart, returning a vector of strings.

The string source is broken apart into individual words, where a word is delimited by the characters in delimiters. This function is similar to TfStringTokenize, except it considers a quoted string as a single word. The function will preserve quotes that are nested within other quotes or are preceded by a backslash character. errors, if provided, contains any error messages. Delimiters default to white space (space, tab, and newline).

◆ TfSafeString()

std::string TfSafeString ( const char *  ptr)
inline

Safely create a std::string from a (possibly NULL) char*.

If ptr is NULL, the empty string is safely returned.

Definition at line 103 of file stringUtils.h.

◆ TfStringCapitalize()

TF_API std::string TfStringCapitalize ( const std::string &  source)

Returns a copy of the source string with only its first character capitalized.

This emulates the behavior of Python's str.capitalize().

◆ TfStringCatPaths()

TF_API std::string TfStringCatPaths ( const std::string &  prefix,
const std::string &  suffix 
)

Concatenate two strings containing '/' and '..' tokens like a file path or scope name.

Tokenize the input strings using a '/' delimiter. Look for '..' tokens in the suffix and construct the appropriate result.

Examples:

  • TfStringCatPaths( "foo/bar", "jive" ) => "foo/bar/jive"
  • TfStringCatPaths( "foo/bar", "../jive" ) => "foo/jive"

◆ TfStringContains() [1/3]

TF_API bool TfStringContains ( const std::string &  s,
const char *  substring 
)

Returns true if s contains substring.

◆ TfStringContains() [2/3]

bool TfStringContains ( const std::string &  s,
const std::string &  substring 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 260 of file stringUtils.h.

◆ TfStringContains() [3/3]

TF_API bool TfStringContains ( const std::string &  s,
const TfToken substring 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ TfStringEndsWith() [1/2]

bool TfStringEndsWith ( const std::string &  s,
const char *  suffix 
)
inline

Returns true if s ends with suffix.

Definition at line 240 of file stringUtils.h.

◆ TfStringEndsWith() [2/2]

bool TfStringEndsWith ( const std::string &  s,
const std::string &  suffix 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 248 of file stringUtils.h.

◆ TfStringGetBeforeSuffix()

TF_API std::string TfStringGetBeforeSuffix ( const std::string &  name,
char  delimiter = '.' 
)

Returns everything up to the suffix of a string.

Returns characters before the final character delimiter (default ".") of a string. Thus not-suffix of "abc.def" is "abc" using "." as the delimiter. If the delimiter does not occur, the original string is returned.

◆ TfStringGetCommonPrefix()

TF_API std::string TfStringGetCommonPrefix ( std::string  a,
std::string  b 
)

Returns the common prefix of the input strings, if any.

Copies of the input strings are compared. Returns a new string which is the longest prefix common to both input strings. If the strings have no common prefix, an empty string is returned.

◆ TfStringGetSuffix()

TF_API std::string TfStringGetSuffix ( const std::string &  name,
char  delimiter = '.' 
)

Returns the suffix of a string.

Returns characters after the final character delimiter (default ".") of a string. Thus suffix of "abc.def" is "def" using "." as the delimiter. If the delimiter does not occur, the empty string is returned.

◆ TfStringGlobToRegex()

TF_API std::string TfStringGlobToRegex ( const std::string &  s)

Returns a string with glob characters converted to their regular expression equivalents.

Currently, this transforms strings by replacing all instances of '.' with '.', '*' with '.*', and '?' with '.', in that order.

◆ TfStringify() [1/5]

TF_API std::string TfStringify ( bool  v)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ TfStringify() [2/5]

std::string TfStringify ( const T &  v)

Convert an arbitrary type into a string.

Use the type's stream output operator to convert it into a string. You are free to use the stream operators in ostreamMethods.h, but are not required to do so.

Definition at line 572 of file stringUtils.h.

◆ TfStringify() [3/5]

TF_API std::string TfStringify ( double  )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ TfStringify() [4/5]

TF_API std::string TfStringify ( float  )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ TfStringify() [5/5]

TF_API std::string TfStringify ( std::string const &  )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ TfStringJoin() [1/3]

TF_API std::string TfStringJoin ( const std::set< std::string > &  strings,
const char *  separator = " " 
)

Concatenates strings, with default separator.

Returns the concatenation of the strings in strings, with separator (by default, a space) added between each successive pair of strings.

◆ TfStringJoin() [2/3]

TF_API std::string TfStringJoin ( const std::vector< std::string > &  strings,
const char *  separator = " " 
)

Concatenates strings, with default separator.

Returns the concatenation of the strings in strings, with separator (by default, a space) added between each successive pair of strings.

◆ TfStringJoin() [3/3]

std::string TfStringJoin ( ForwardIterator  begin,
ForwardIterator  end,
const char *  separator = " " 
)

Concatenates the strings (begin, end), with default separator.

Returns the concatenation of the strings in the range begin to end, with separator (by default, a space) added between each successive pair of strings.

Definition at line 374 of file stringUtils.h.

◆ TfStringPrintf()

TF_API std::string TfStringPrintf ( const char *  fmt,
  ... 
)

Returns a string formed by a printf()-like specification.

TfStringPrintf() is a memory-safe way of forming a string using printf()-like formatting. For example,

string formatMsg(const string& caller, int i, double val[])
{
return TfStringfPrintf("%s: val[%d] = %g\n", caller.c_str(), i, val[i]);
}

The function is safe only to the extent that the arguments match the formatting string. In particular, be careful to pass strings themselves into TfStringPrintf() as in the above example (i.e. caller.c_str() as opposed to just passing caller).

Note
TfStringPrintf() is just a wrapper for ArchStringPrintf().

◆ TfStringReplace()

TF_API std::string TfStringReplace ( const std::string &  source,
const std::string &  from,
const std::string &  to 
)

Replaces all occurrences of string from with to in source.

Returns a new string which is created by copying source and replacing every occurrence of from with to. Correctly handles the case in which to contains from.

◆ TfStringSplit()

TF_API std::vector< std::string > TfStringSplit ( std::string const &  src,
std::string const &  separator 
)

Breaks the given string apart, returning a vector of strings.

The string source is broken apart into individual words, where a word is delimited by the string separator. This function behaves like pythons string split method.

◆ TfStringStartsWith() [1/2]

bool TfStringStartsWith ( const std::string &  s,
const char *  prefix 
)
inline

Returns true if s starts with prefix.

Definition at line 220 of file stringUtils.h.

◆ TfStringStartsWith() [2/2]

bool TfStringStartsWith ( const std::string &  s,
const std::string &  prefix 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 228 of file stringUtils.h.

◆ TfStringToDouble() [1/3]

TF_API double TfStringToDouble ( const char *  text)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ TfStringToDouble() [2/3]

TF_API double TfStringToDouble ( const char *  text,
int  len 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ TfStringToDouble() [3/3]

TF_API double TfStringToDouble ( const std::string &  txt)

Converts text string to double.

This method converts strings to floating point numbers. It is similar to libc's atof(), but performs the conversion much more quickly.

It expects somewhat valid input: it will continue parsing the input until it hits an unrecognized character, as described by the regexp below, and at that point will return the results up to that point.

(-?[0-9]+(.[0-9]*)?|-?.[0-9]+)([eE][-+]?[0-9]+)?

It will not check to see if there is any input at all, or whitespace after the digits. Ie: TfStringToDouble("") == 0.0 TfStringToDouble("blah") == 0.0 TfStringToDouble("-") == -0.0 TfStringToDouble("1.2foo") == 1.2

Note
TfStringToDouble is a wrapper around the extern-c TfStringToDouble

◆ TfStringToInt64() [1/2]

TF_API int64_t TfStringToInt64 ( const char *  txt,
bool *  outOfRange = NULL 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ TfStringToInt64() [2/2]

TF_API int64_t TfStringToInt64 ( const std::string &  txt,
bool *  outOfRange = NULL 
)

Convert a sequence of digits in txt to an int64_t value.

Caller must ensure that txt has content matching:

-?[0-9]+

If the digit sequence's value is out of range, set *outOfRange to true (if outOfRange is not NULL) and return either std::numeric_limits<int64_t>::min() or max(), whichever is closest to the true value.

◆ TfStringTokenize()

TF_API std::vector< std::string > TfStringTokenize ( const std::string &  source,
const char *  delimiters = " \t\n" 
)

Breaks the given string apart, returning a vector of strings.

The string source is broken apart into individual words, where a word is delimited by the characters in delimiters. Delimiters default to white space (space, tab, and newline).

No empty strings are returned: delimiters at the start or end are ignored, consecutive delimiters are treated as though they were one, and an empty input will result in an empty return vector.

◆ TfStringTokenizeToSet()

TF_API std::set< std::string > TfStringTokenizeToSet ( const std::string &  source,
const char *  delimiters = " \t\n" 
)

Breaks the given string apart, returning a set of strings.

Same as TfStringTokenize, except this one returns a set.

◆ TfStringToLong() [1/2]

TF_API long TfStringToLong ( const char *  txt,
bool *  outOfRange = NULL 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ TfStringToLong() [2/2]

TF_API long TfStringToLong ( const std::string &  txt,
bool *  outOfRange = NULL 
)

Convert a sequence of digits in txt to a long int value.

Caller is responsible for ensuring that txt has content matching:

-?[0-9]+

If the digit sequence's value is out of range, set *outOfRange to true (if outOfRange is not NULL) and return either std::numeric_limits<long>::min() or max(), whichever is closest to the true value.

◆ TfStringToLower()

TF_API std::string TfStringToLower ( const std::string &  source)

Makes all characters in source lowercase, and returns the result.

◆ TfStringToLowerAscii()

TF_API std::string TfStringToLowerAscii ( const std::string &  source)

Locale-independent case folding of [A-Z] for ASCII or UTF-8 encoded source strings.

This can be used for case insensitive matching where one of the strings being compared either known to be ASCII only by specification (like a URI scheme or an explicit token) or where the specification explicitly notes that only [A-Z] will be matched case insensitively.

TF_API std::string TfStringToLowerAscii(const std::string &source)
Locale-independent case folding of [A-Z] for ASCII or UTF-8 encoded source strings.
bool TfStringEndsWith(const std::string &s, const char *suffix)
Returns true if s ends with suffix.
Definition: stringUtils.h:240

◆ TfStringToUInt64() [1/2]

TF_API uint64_t TfStringToUInt64 ( const char *  txt,
bool *  outOfRange = NULL 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ TfStringToUInt64() [2/2]

TF_API uint64_t TfStringToUInt64 ( const std::string &  txt,
bool *  outOfRange = NULL 
)

Convert a sequence of digits in txt to a uint64_t value.

Caller is responsible for ensuring that txt has content matching:

[0-9]+

If the digit sequence's value is out of range, set *outOfRange to true (if outOfRange is not NULL) and return std::numeric_limits<unsigned long>::max().

◆ TfStringToULong() [1/2]

TF_API unsigned long TfStringToULong ( const char *  txt,
bool *  outOfRange = NULL 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ TfStringToULong() [2/2]

TF_API unsigned long TfStringToULong ( const std::string &  txt,
bool *  outOfRange = NULL 
)

Convert a sequence of digits in txt to an unsigned long value.

Caller is responsible for ensuring that txt has content matching:

[0-9]+

If the digit sequence's value is out of range, set *outOfRange to true (if outOfRange is not NULL) and return std::numeric_limits<unsigned long>::max().

◆ TfStringToUpper()

TF_API std::string TfStringToUpper ( const std::string &  source)

Makes all characters in source uppercase, and returns the result.

◆ TfStringTrim()

TF_API std::string TfStringTrim ( const std::string &  s,
const char *  trimChars = " \n\t\r" 
)

Trims characters (by default, whitespace) from the beginning and end of string.

Characters at the beginning and end of s are removed until a character not in trimChars is found; the result is returned.

◆ TfStringTrimLeft()

TF_API std::string TfStringTrimLeft ( const std::string &  s,
const char *  trimChars = " \n\t\r" 
)

Trims characters (by default, whitespace) from the left.

Characters from the beginning of s are removed until a character not in trimChars is found; the result is returned.

◆ TfStringTrimRight()

TF_API std::string TfStringTrimRight ( const std::string &  s,
const char *  trimChars = " \n\t\r" 
)

Trims characters (by default, whitespace) from the right.

Characters at the end of s are removed until a character not in trimChars is found; the result is returned.

◆ TfUnstringify() [1/2]

TF_API bool TfUnstringify ( const std::string &  instring,
bool *  status 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ TfUnstringify() [2/2]

T TfUnstringify ( const std::string &  instring,
bool *  status = NULL 
)

Convert a string to an arbitrary type.

Use the type's stream input operator to get it from a string. If status is non-NULL and instring cannot be converted to a T, *status is set to false; otherwise, *status is not modified.

Definition at line 631 of file stringUtils.h.

◆ TfVStringPrintf() [1/2]

TF_API std::string TfVStringPrintf ( const char *  fmt,
va_list  ap 
)

Bloat-avoidance version of TfVStringPrintf()

◆ TfVStringPrintf() [2/2]

TF_API std::string TfVStringPrintf ( const std::string &  fmt,
va_list  ap 
)

Returns a string formed by a printf()-like specification.

TfVStringPrintf() is equivalent to TfStringPrintf() except that it is called with a va_list instead of a variable number of arguments. TfVStringPrintf() does not call the va_end macro. Consequently, the value of ap is undefined after the call. A functions that calls TfVStringPrintf() should call va_end(ap) itself afterwards.

Note
TfVStringPrintf() is just a wrapper for ArchVStringPrintf().