This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
stringUtils.h File Reference

Definitions of basic string utilities in tf. More...

+ Include dependency graph for stringUtils.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

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...
 

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.
 
template<>
TF_API std::string 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

Definitions of basic string utilities in tf.

Definition in file stringUtils.h.

Function Documentation

◆ TfUnstringify()

TF_API std::string 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.