24 #ifndef PXR_BASE_TF_STRING_UTILS_H
25 #define PXR_BASE_TF_STRING_UTILS_H
45 #include <type_traits>
75 ARCH_PRINTF_FUNCTION(1, 2)
96 ARCH_PRINTF_FUNCTION(1, 0)
213 char const *prefix,
size_t prelen)
215 return slen >= prelen && strncmp(s, prefix, prelen) == 0;
223 s.c_str(), s.length(), prefix, strlen(prefix));
234 char const *suffix,
size_t suflen)
236 return slen >= suflen && strcmp(s + (slen - suflen), suffix) == 0;
243 suffix, strlen(suffix));
301 const char* trimChars =
" \n\t\r");
309 const char* trimChars =
" \n\t\r");
318 const char* trimChars =
" \n\t\r");
373 template <
class ForwardIterator>
375 ForwardIterator
begin, ForwardIterator
end,
376 const char* separator =
" ")
388 ForwardIterator i =
begin;
389 for (i = begin; i !=
end; ++i)
391 retVal.reserve(sum + strlen(separator) * (distance - 1));
396 retVal.append(separator);
409 const char* separator =
" ");
417 const char* separator =
" ");
439 const char* delimiters =
" \t\n");
446 const char* delimiters =
" \t\n");
458 std::vector<std::string>
460 const char* delimiters =
" \t\n",
474 std::vector<std::string>
478 char escapeCharacter =
'\0',
488 std::vector<std::string>
495 closeDelimiter,
'\0', errors);
547 const unsigned char l = lhs.c_str()[0],
r = rhs.c_str()[0];
548 const bool bothAscii = l < 0x80 &&
r < 0x80;
549 const bool differsIgnoringCase = (l & ~0x20) != (r & ~0x20);
550 const bool inLetterZone = (l >= 0x40) && (r >= 0x40);
551 if (
ARCH_LIKELY(bothAscii && differsIgnoringCase && inLetterZone)) {
554 return ((l + 5) & 31) < ((r + 5) & 31);
557 return _LessImpl(lhs, rhs);
570 template <
typename T>
578 std::ostringstream
stream;
600 double d,
char*
buffer,
int len,
bool emitTrailingZero);
629 template <
typename T>
634 std::istringstream
stream(instring);
636 if (status && !stream)
714 char const *p = identifier.c_str();
715 auto letter = [](
unsigned c) {
return ((
c-
'A') < 26) || ((
c-
'a') < 26); };
716 auto number = [](
unsigned c) {
return (
c-
'0') < 10; };
717 auto under = [](
unsigned c) {
return c ==
'_'; };
719 if (!x || number(x)) {
722 while (letter(x) || number(x) || under(x)) {
745 #endif // PXR_BASE_TF_STRING_UTILS_H
TF_API std::string TfGetXmlEscapedString(const std::string &in)
TF_API std::string TfStringPrintf(const char *fmt,...)
TF_API unsigned long TfStringToULong(const std::string &txt, bool *outOfRange=NULL)
std::string TfSafeString(const char *ptr)
bool TfStringEndsWith(const std::string &s, const char *suffix)
Returns true if s ends with suffix.
TF_API long TfStringToLong(const std::string &txt, bool *outOfRange=NULL)
TF_API std::string TfStringGetSuffix(const std::string &name, char delimiter= '.')
GLsizei const GLchar *const * string
TF_API std::vector< std::string > TfStringSplit(std::string const &src, std::string const &separator)
GLsizei const GLfloat * value
TF_API std::string TfStringTrimRight(const std::string &s, const char *trimChars=" \n\t\r")
TF_API std::ostream & operator<<(std::ostream &o, TfStreamFloat t)
GLboolean GLboolean GLboolean GLboolean a
bool TfStringStartsWith(const std::string &s, const char *prefix)
Returns true if s starts with prefix.
TF_API std::set< std::string > TfStringTokenizeToSet(const std::string &source, const char *delimiters=" \t\n")
TF_API double TfStringToDouble(const std::string &txt)
TF_API std::string TfStringGlobToRegex(const std::string &s)
TF_API std::string TfMakeValidIdentifier(const std::string &in)
TF_API std::string TfStringToLower(const std::string &source)
Makes all characters in source lowercase, and returns the result.
TF_API std::string TfStringTrim(const std::string &s, const char *trimChars=" \n\t\r")
bool operator()(const std::string &lhs, const std::string &rhs) const
TF_API std::vector< std::string > TfQuotedStringTokenize(const std::string &source, const char *delimiters=" \t\n", std::string *errors=NULL)
TF_API std::vector< std::string > TfMatchedStringTokenize(const std::string &source, char openDelimiter, char closeDelimiter, char escapeCharacter= '\0', std::string *errors=NULL)
TF_API bool TfDoubleToString(double d, char *buffer, int len, bool emitTrailingZero)
std::string TfIntToString(int i)
Returns the given integer as a string.
TF_API std::string TfVStringPrintf(const std::string &fmt, va_list ap)
TF_API uint64_t TfStringToUInt64(const std::string &txt, bool *outOfRange=NULL)
GLsizei GLsizei GLchar * source
std::string TfStringify(const T &v)
TF_API bool TfStringContains(const std::string &s, const char *substring)
Returns true if s contains substring.
GLuint const GLchar * name
GLsizei const GLchar *const * strings
GLboolean GLboolean GLboolean b
std::string TfStringJoin(ForwardIterator begin, ForwardIterator end, const char *separator=" ")
TF_API std::string TfStringCapitalize(const std::string &source)
TF_API std::string TfStringToUpper(const std::string &source)
Makes all characters in source uppercase, and returns the result.
TF_API std::string TfStringGetCommonPrefix(std::string a, std::string b)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
TF_API std::string TfStringToLowerAscii(const std::string &source)
#define PXR_NAMESPACE_CLOSE_SCOPE
T TfUnstringify(const std::string &instring, bool *status=NULL)
TF_API std::string TfGetBaseName(const std::string &fileName)
Returns the base name of a file (final component of the path).
static TF_API std::string GetName(TfEnum val)
bool Tf_StringStartsWithImpl(char const *s, size_t slen, char const *prefix, size_t prelen)
TF_API std::string TfStringGetBeforeSuffix(const std::string &name, char delimiter= '.')
bool TfIsValidIdentifier(std::string const &identifier)
TF_API void TfEscapeStringReplaceChar(const char **in, char **out)
SIM_API const UT_StringHolder distance
TF_API std::vector< std::string > TfStringTokenize(const std::string &source, const char *delimiters=" \t\n")
TF_API int64_t TfStringToInt64(const std::string &txt, bool *outOfRange=NULL)
TF_API std::string TfStringReplace(const std::string &source, const std::string &from, const std::string &to)
TF_API std::string TfStringTrimLeft(const std::string &s, const char *trimChars=" \n\t\r")
TF_API std::string TfStringCatPaths(const std::string &prefix, const std::string &suffix)
TF_API std::string TfEscapeString(const std::string &in)
bool Tf_StringEndsWithImpl(char const *s, size_t slen, char const *suffix, size_t suflen)
TF_API std::string TfGetPathName(const std::string &fileName)
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.