HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stringUtils.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef TF_STRINGUTILS_H
25 #define TF_STRINGUTILS_H
26 
27 /// \file tf/stringUtils.h
28 /// \ingroup group_tf_String
29 /// Definitions of basic string utilities in tf.
30 
31 #include "pxr/pxr.h"
32 
34 #include "pxr/base/arch/inttypes.h"
35 #include "pxr/base/tf/api.h"
36 #include "pxr/base/tf/enum.h"
37 
38 #include <cstdarg>
39 #include <cstring>
40 #include <list>
41 #include <set>
42 #include <sstream>
43 #include <string>
44 #include <type_traits>
45 #include <vector>
46 
48 
49 class TfToken;
50 
51 /// \addtogroup group_tf_String
52 ///@{
53 
54 /// Returns a string formed by a printf()-like specification.
55 ///
56 /// \c TfStringPrintf() is a memory-safe way of forming a string using
57 /// printf()-like formatting. For example,
58 /// \code
59 /// string formatMsg(const string& caller, int i, double val[])
60 /// {
61 /// return TfStringfPrintf("%s: val[%d] = %g\n", caller.c_str(), i, val[i]);
62 /// }
63 /// \endcode
64 ///
65 /// The function is safe only to the extent that the arguments match the
66 /// formatting string. In particular, be careful to pass strings themselves
67 /// into \c TfStringPrintf() as in the above example (i.e. \c caller.c_str()
68 /// as opposed to just passing \c caller).
69 ///
70 /// \note \c TfStringPrintf() is just a wrapper for \c ArchStringPrintf().
71 TF_API
72 std::string TfStringPrintf(const char *fmt, ...)
73 #ifndef doxygen
74  ARCH_PRINTF_FUNCTION(1, 2)
75 #endif /* doxygen */
76  ;
77 
78 /// Returns a string formed by a printf()-like specification.
79 ///
80 /// \c TfVStringPrintf() is equivalent to \c TfStringPrintf() except that it
81 /// is called with a \c va_list instead of a variable number of arguments. \c
82 /// TfVStringPrintf() does not call the \c va_end macro. Consequently, the
83 /// value of \c ap is undefined after the call. A functions that calls \c
84 /// TfVStringPrintf() should call \c va_end(ap) itself afterwards.
85 ///
86 /// \note \c TfVStringPrintf() is just a wrapper for \c ArchVStringPrintf().
87 TF_API
88 std::string TfVStringPrintf(const std::string& fmt, va_list ap);
89 
90 /// Bloat-avoidance version of TfVStringPrintf()
91 
92 TF_API
93 std::string TfVStringPrintf(const char *fmt, va_list ap)
94 #ifndef doxygen
95  ARCH_PRINTF_FUNCTION(1, 0)
96 #endif /* doxygen */
97  ;
98 
99 /// Safely create a std::string from a (possibly NULL) char*.
100 ///
101 /// If \p ptr is NULL, the empty string is safely returned.
102 inline std::string TfSafeString(const char* ptr) {
103  return ptr ? std::string(ptr) : std::string();
104 }
105 
106 /// Returns the given integer as a string.
107 inline std::string TfIntToString(int i) {
108  return TfStringPrintf("%d", i);
109 }
110 
111 /// Converts text string to double
112 ///
113 /// This method converts strings to floating point numbers. It is similar to
114 /// libc's atof(), but performs the conversion much more quickly.
115 ///
116 /// It expects somewhat valid input: it will continue parsing the input until
117 /// it hits an unrecognized character, as described by the regexp below, and
118 /// at that point will return the results up to that point.
119 ///
120 /// (-?[0-9]+(\.[0-9]*)?|-?\.[0-9]+)([eE][-+]?[0-9]+)?
121 ///
122 /// It will not check to see if there is any input at all, or whitespace
123 /// after the digits. Ie:
124 /// TfStringToDouble("") == 0.0
125 /// TfStringToDouble("blah") == 0.0
126 /// TfStringToDouble("-") == -0.0
127 /// TfStringToDouble("1.2foo") == 1.2
128 ///
129 /// \note \c TfStringToDouble is a wrapper around the extern-c TfStringToDouble
130 TF_API double TfStringToDouble(const std::string& txt);
131 
132 /// \overload
133 TF_API double TfStringToDouble(const char *text);
134 
135 /// Convert a sequence of digits in \p txt to a long int value. Caller is
136 /// responsible for ensuring that \p txt has content matching:
137 ///
138 /// \code
139 /// -?[0-9]+
140 /// \endcode
141 ///
142 /// If the digit sequence's value is out of range, set \p *outOfRange to true
143 /// (if \p outOfRange is not NULL) and return either
144 /// std::numeric_limits<long>::min() or max(), whichever is closest to the
145 /// true value.
146 TF_API
147 long TfStringToLong(const std::string &txt, bool *outOfRange=NULL);
148 
149 /// \overload
150 
151 TF_API
152 long TfStringToLong(const char *txt, bool *outOfRange=NULL);
153 
154 /// Convert a sequence of digits in \p txt to an unsigned long value. Caller
155 /// is responsible for ensuring that \p txt has content matching:
156 ///
157 /// \code
158 /// [0-9]+
159 /// \endcode
160 ///
161 /// If the digit sequence's value is out of range, set \p *outOfRange to true
162 /// (if \p outOfRange is not NULL) and return std::numeric_limits<unsigned
163 /// long>::max().
164 TF_API
165 unsigned long TfStringToULong(const std::string &txt, bool *outOfRange=NULL);
166 
167 /// \overload
168 
169 TF_API
170 unsigned long TfStringToULong(const char *txt, bool *outOfRange=NULL);
171 
172 /// Convert a sequence of digits in \p txt to an int64_t value. Caller must
173 /// ensure that \p txt has content matching:
174 ///
175 /// \code
176 /// -?[0-9]+
177 /// \endcode
178 ///
179 /// If the digit sequence's value is out of range, set \p *outOfRange to true
180 /// (if \p outOfRange is not NULL) and return either
181 /// std::numeric_limits<int64_t>::min() or max(), whichever is closest to the
182 /// true value.
183 TF_API
184 int64_t TfStringToInt64(const std::string &txt, bool *outOfRange=NULL);
185 
186 /// \overload
187 TF_API
188 int64_t TfStringToInt64(const char *txt, bool *outOfRange=NULL);
189 
190 /// Convert a sequence of digits in \p txt to a uint64_t value. Caller is
191 /// responsible for ensuring that \p txt has content matching:
192 ///
193 /// \code
194 /// [0-9]+
195 /// \endcode
196 ///
197 /// If the digit sequence's value is out of range, set \p *outOfRange to true
198 /// (if \p outOfRange is not NULL) and return std::numeric_limits<unsigned
199 /// long>::max().
200 TF_API
201 uint64_t TfStringToUInt64(const std::string &txt, bool *outOfRange=NULL);
202 
203 /// \overload
204 TF_API
205 uint64_t TfStringToUInt64(const char *txt, bool *outOfRange=NULL);
206 
207 inline bool
208 Tf_StringStartsWithImpl(char const *s, size_t slen,
209  char const *prefix, size_t prelen)
210 {
211  return slen >= prelen && strncmp(s, prefix, prelen) == 0;
212 }
213 
214 /// Returns true if \p s starts with \p prefix.
215 inline bool
216 TfStringStartsWith(const std::string& s, const char *prefix)
217 {
219  s.c_str(), s.length(), prefix, strlen(prefix));
220 }
221 
222 /// \overload
223 inline bool
224 TfStringStartsWith(const std::string& s, const std::string& prefix) {
225  return TfStringStartsWith(s, prefix.c_str());
226 }
227 
228 /// \overload
229 TF_API
230 bool TfStringStartsWith(const std::string &s, const TfToken& prefix);
231 
232 inline bool
233 Tf_StringEndsWithImpl(char const *s, size_t slen,
234  char const *suffix, size_t suflen)
235 {
236  return slen >= suflen && strcmp(s + (slen - suflen), suffix) == 0;
237 }
238 
239 /// Returns true if \p s ends with \p suffix.
240 inline bool TfStringEndsWith(const std::string& s, const char *suffix)
241 {
242  return Tf_StringEndsWithImpl(s.c_str(), s.length(),
243  suffix, strlen(suffix));
244 }
245 
246 /// \overload
247 inline bool
249 {
250  return TfStringEndsWith(s, suffix.c_str());
251 }
252 
253 /// \overload
254 TF_API
255 bool TfStringEndsWith(const std::string &s, const TfToken& suffix);
256 
257 /// Returns true if \p s contains \p substring.
258 // \ingroup group_tf_String
259 TF_API
260 bool TfStringContains(const std::string& s, const char *substring);
261 
262 /// \overload
263 inline bool
264 TfStringContains(const std::string &s, const std::string &substring) {
265  return TfStringContains(s, substring.c_str());
266 }
267 
268 /// \overload
269 TF_API
270 bool TfStringContains(const std::string &s, const TfToken& substring);
271 
272 /// Makes all characters in \p source lowercase, and returns the result.
273 TF_API
275 
276 /// Makes all characters in \p source uppercase, and returns the result.
277 TF_API
279 
280 /// Returns a copy of the \p source string with only its first character
281 /// capitalized. This emulates the behavior of Python's \c str.capitalize().
282 TF_API
284 
285 /// Trims characters (by default, whitespace) from the left.
286 ///
287 /// Characters from the beginning of \p s are removed until a character not in
288 /// \p trimChars is found; the result is returned.
289 TF_API
291  const char* trimChars = " \n\t\r");
292 
293 /// Trims characters (by default, whitespace) from the right.
294 ///
295 /// Characters at the end of \p s are removed until a character not in \p
296 /// trimChars is found; the result is returned.
297 TF_API
299  const char* trimChars = " \n\t\r");
300 
301 /// Trims characters (by default, whitespace) from the beginning and end of
302 /// string.
303 ///
304 /// Characters at the beginning and end of \p s are removed until a character
305 /// not in \p trimChars is found; the result is returned.
306 TF_API
308  const char* trimChars = " \n\t\r");
309 
310 /// Returns the common prefix of the input strings, if any.
311 ///
312 /// Copies of the input strings are compared. Returns a new string which is
313 /// the longest prefix common to both input strings. If the strings have no
314 /// common prefix, an empty string is returned.
315 TF_API
317 
318 /// Returns the suffix of a string
319 ///
320 /// Returns characters after the final character \c delimiter (default ".") of
321 /// a string. Thus suffix of "abc.def" is "def" using "." as the delimiter.
322 /// If the delimiter does not occur, the empty string is returned.
323 TF_API
324 std::string TfStringGetSuffix(const std::string& name, char delimiter = '.');
325 
326 /// Returns everything up to the suffix of a string
327 ///
328 /// Returns characters before the final character \c delimiter (default ".")
329 /// of a string. Thus not-suffix of "abc.def" is "abc" using "." as the
330 /// delimiter. If the delimiter does not occur, the original string is
331 /// returned.
332 TF_API
333 std::string TfStringGetBeforeSuffix(const std::string& name, char delimiter = '.');
334 
335 /// Returns the base name of a file (final component of the path).
336 TF_API
337 std::string TfGetBaseName(const std::string& fileName);
338 
339 /// Returns the path component of a file (complement of TfGetBaseName()).
340 ///
341 /// The returned string ends in a '/' (or possibly a '\' on Windows), unless
342 /// none was found in \c fileName, in which case the empty string is returned.
343 /// In particular, \c TfGetPathName(s)+TfGetBaseName(s) == \c s for any string
344 /// \c s (as long as \c s doesn't end with multiple adjacent slashes, which is
345 /// illegal).
346 TF_API
347 std::string TfGetPathName(const std::string& fileName);
348 
349 /// Replaces all occurrences of string \p from with \p to in \p source
350 ///
351 /// Returns a new string which is created by copying \p string and replacing
352 /// every occurrence of \p from with \p to. Correctly handles the case in which
353 /// \p to contains \p from.
354 TF_API
356  const std::string& to);
357 
358 /// Concatenates the strings (\p begin, \p end), with default separator.
359 ///
360 /// Returns the concatenation of the strings in the range \p begin to \p end,
361 /// with \p separator (by default, a space) added between each successive pair
362 /// of strings.
363 template <class ForwardIterator>
365  ForwardIterator begin, ForwardIterator end,
366  const char* separator = " ")
367 {
368  if (begin == end)
369  return std::string();
370 
371  size_t distance = std::distance(begin, end);
372  if (distance == 1)
373  return *begin;
374 
375  std::string retVal;
376 
377  size_t sum = 0;
378  ForwardIterator i = begin;
379  for (i = begin; i != end; ++i)
380  sum += i->size();
381  retVal.reserve(sum + strlen(separator) * (distance - 1));
382 
383  i = begin;
384  retVal.append(*i);
385  while (++i != end) {
386  retVal.append(separator);
387  retVal.append(*i);
388  }
389 
390  return retVal;
391 }
392 
393 /// Concatenates \p strings, with default separator.
394 ///
395 /// Returns the concatenation of the strings in \p strings, with \p separator
396 /// (by default, a space) added between each successive pair of strings.
397 TF_API
398 std::string TfStringJoin(const std::vector<std::string>& strings,
399  const char* separator = " ");
400 
401 /// Concatenates \p strings, with default separator.
402 ///
403 /// Returns the concatenation of the strings in \p strings, with \p separator
404 /// (by default, a space) added between each successive pair of strings.
405 TF_API
406 std::string TfStringJoin(const std::set<std::string>& strings,
407  const char* separator = " ");
408 
409 /// Breaks the given string apart, returning a vector of strings.
410 ///
411 /// The string \p source is broken apart into individual words, where a word
412 /// is delimited by the string \p separator. This function behaves like
413 /// pythons string split method.
414 TF_API
415 std::vector<std::string> TfStringSplit(std::string const &src,
416  std::string const &separator);
417 
418 /// Breaks the given string apart, returning a vector of strings.
419 ///
420 /// The string \p source is broken apart into individual words, where a word
421 /// is delimited by the characters in \p delimiters. Delimiters default to
422 /// white space (space, tab, and newline).
423 TF_API
424 std::vector<std::string> TfStringTokenize(const std::string& source,
425  const char* delimiters = " \t\n");
426 
427 /// Breaks the given string apart, returning a set of strings.
428 ///
429 /// Same as TfStringTokenize, except this one returns a set.
430 TF_API
431 std::set<std::string> TfStringTokenizeToSet(const std::string& source,
432  const char* delimiters = " \t\n");
433 
434 /// Breaks the given quoted string apart, returning a vector of strings.
435 ///
436 /// The string \p source is broken apart into individual words, where a word
437 /// is delimited by the characters in \p delimiters. This function is similar
438 /// to \c TfStringTokenize, except it considers a quoted string as a single
439 /// word. The function will preserve quotes that are nested within other
440 /// quotes or are preceded by a backslash character. \p errors, if provided,
441 /// contains any error messages. Delimiters default to white space (space,
442 /// tab, and newline).
443 TF_API
444 std::vector<std::string>
446  const char* delimiters = " \t\n",
447  std::string *errors = NULL);
448 
449 /// Breaks the given string apart by matching delimiters.
450 ///
451 /// The string \p source is broken apart into individual words, where a word
452 /// begins with \p openDelimiter and ends with a matching \p closeDelimiter.
453 /// Any delimiters within the matching delimiters become part of the word, and
454 /// anything outside matching delimiters gets dropped. For example, \c
455 /// TfMatchedStringTokenize("{a} string {to {be} split}", '{', '}') would
456 /// return a vector containing "a" and "to {be} split". If \p openDelimiter and
457 /// \p closeDelimiter cannot be the same. \p errors, if provided, contains any
458 /// error messages.
459 TF_API
460 std::vector<std::string>
462  char openDelimiter,
463  char closeDelimiter,
464  char escapeCharacter = '\0',
465  std::string *errors = NULL);
466 
467 /// This overloaded version of \c TfMatchedStringTokenize does not take an \c
468 /// escapeCharacter parameter but does take \param errors. It allows \c
469 /// TfMatchedStringTokenize to be called with or without an \c escapeCharacter
470 /// and with or without \c errors.
471 ///
472 /// \overload
473 inline
474 std::vector<std::string>
476  char openDelimiter,
477  char closeDelimiter,
478  std::string *errors)
479 {
480  return TfMatchedStringTokenize(source, openDelimiter,
481  closeDelimiter, '\0', errors);
482 }
483 
484 /// \class TfDictionaryLessThan
485 ///
486 /// Provides dictionary ordering binary predicate function on strings.
487 ///
488 /// The \c TfDictionaryLessThan class is a functor as defined by the STL
489 /// standard. It compares strings using "dictionary" order: for example, the
490 /// following strings are in dictionary order:
491 /// ["abacus", "Albert", "albert", "baby", "Bert", "file01", "file001", "file2",
492 /// "file10"]
493 ///
494 /// Note that capitalization matters only if the strings differ by
495 /// capitalization alone.
496 ///
497 /// Characters whose ASCII value are inbetween upper- and lowercase letters,
498 /// such as underscore, are sorted to come after all letters.
499 ///
501  /// Return true if \p lhs is less than \p rhs in dictionary order.
502  ///
503  /// Normally this functor is used to supply an ordering functor for STL
504  /// containers: for example,
505  /// \code
506  /// map<string, DataType, TfDictionaryLessThan> table;
507  /// \endcode
508  ///
509  /// If you simply need to compare two strings, you can do so as follows:
510  /// \code
511  /// bool aIsFirst = TfDictionaryLessThan()(aString, bString);
512  /// \endcode
513  TF_API bool operator()(const std::string &lhs, const std::string &rhs) const;
514 };
515 
516 /// Convert an arbitrary type into a string
517 ///
518 /// Use the type's stream output operator to convert it into a string. You are
519 /// free to use the stream operators in ostreamMethods.h, but are not required
520 /// to do so.
521 template <typename T>
523 TfStringify(const T& v)
524 {
525  std::ostringstream stream;
526  stream << v;
527  return stream.str();
528 }
529 
530 /// \overload
531 template <typename T>
533 TfStringify(const T& v)
534 {
535  return TfEnum::GetName(v);
536 }
537 
538 /// \overload
540 /// \overload
542 /// \overload
544 /// \overload
546 
547 /// Writes the string representation of \c d to \c buffer of length \c len.
548 /// If \c emitTrailingZero is true, the string representation will end with .0
549 /// in the case where d is an integer otherwise it will be omitted.
550 /// The buffer length must be at least 25 in order to ensure that all doubles
551 /// values can be represented.
552 /// Returns whether the conversion was successful.
554  double d, char* buffer, int len, bool emitTrailingZero);
555 
556 /// \struct TfStreamFloat
557 ///
558 /// A type which offers streaming for floats in a canonical
559 /// format that can safely roundtrip with the minimal number of digits.
561  explicit TfStreamFloat(float f) : value(f) {}
562  float value;
563 };
564 
565 TF_API std::ostream& operator<<(std::ostream& o, TfStreamFloat t);
566 
567 /// \struct TfStreamDouble
568 ///
569 /// A type which offers streaming for doubles in a canonical
570 /// format that can safely roundtrip with the minimal number of digits.
572  explicit TfStreamDouble(double d) : value(d) {}
573  double value;
574 };
575 
576 TF_API std::ostream& operator<<(std::ostream& o, TfStreamDouble t);
577 
578 /// Convert a string to an arbitrary type
579 ///
580 /// Use the type's stream input operator to get it from a string. If \p status
581 /// is non-NULL and \p instring cannot be converted to a \c T, \p *status is
582 /// set to \c false; otherwise, \p *status is not modified.
583 template <typename T>
584 T
585 TfUnstringify(const std::string &instring, bool* status = NULL)
586 {
587  T v = T();
588  std::istringstream stream(instring);
589  stream >> v;
590  if (status && !stream)
591  *status = false;
592  return v;
593 }
594 
595 /// \overload
596 template <>
597 TF_API
598 bool TfUnstringify(const std::string &instring, bool* status);
599 /// \overload
600 template <>
601 TF_API
602 std::string TfUnstringify(const std::string &instring, bool* status);
603 
604 /// Returns a string with glob characters converted to their regular
605 /// expression equivalents.
606 ///
607 /// Currently, this transforms strings by replacing all instances of '.' with
608 /// '\.', '*' with '.*', and '?' with '.', in that order.
609 TF_API
611 
612 /// Process escape sequences in ANSI C string constants.
613 ///
614 /// The following escape sequences are accepted:
615 ///
616 /// \li \\\\: backslash
617 /// \li \\a: ring the bell
618 /// \li \\b: backspace
619 /// \li \\f: form feed
620 /// \li \\n: new line
621 /// \li \\r: carriage return
622 /// \li \\t: tab
623 /// \li \\v: vertical tab
624 /// \li \\xdd: hex constant
625 /// \li \\ddd: octal constant
626 ///
627 /// So, if the two-character sequence "\\n" appears in the string, it is
628 /// replaced by an actual newline. Each hex and octal constant translates
629 /// into one character in the output string. Hex constants can be any length,
630 /// while octal constants are limited to 3 characters. Both are terminated by
631 /// a character that is not a valid constant. Illegal escape sequences are
632 /// replaced by the character following the backslash, so the two character
633 /// sequence "\\c" would become "c". Processing continues until the input
634 /// hits a NUL character in the input string - anything appearing after the
635 /// NUL will be ignored.
637 TF_API void TfEscapeStringReplaceChar(const char** in, char** out);
638 
639 /// Concatenate two strings containing '/' and '..' tokens like a file path or
640 /// scope name.
641 ///
642 /// Tokenize the input strings using a '/' delimiter. Look for '..' tokens in
643 /// the suffix and construct the appropriate result.
644 ///
645 /// Examples:
646 ///
647 /// \li TfStringCatPaths( "foo/bar", "jive" ) => "foo/bar/jive"
648 /// \li TfStringCatPaths( "foo/bar", "../jive" ) => "foo/jive"
649 TF_API
651  const std::string &suffix );
652 
653 /// Test whether \a identifier is valid.
654 ///
655 /// An identifier is valid if it follows the C/Python identifier convention;
656 /// that is, it must be at least one character long, must start with a letter
657 /// or underscore, and must contain only letters, underscores, and numerals.
658 inline bool
660 {
661  char const *p = identifier.c_str();
662  auto letter = [](unsigned c) { return ((c-'A') < 26) || ((c-'a') < 26); };
663  auto number = [](unsigned c) { return (c-'0') < 10; };
664  auto under = [](unsigned c) { return c == '_'; };
665  unsigned x = *p;
666  if (!x || number(x)) {
667  return false;
668  }
669  while (letter(x) || number(x) || under(x)) {
670  x = *p++;
671  };
672  return x == 0;
673 }
674 
675 /// Produce a valid identifier (see TfIsValidIdentifier) from \p in by
676 /// replacing invalid characters with '_'. If \p in is empty, return "_".
677 TF_API
680 
681 /// Escapes characters in \a in so that they are valid XML.
682 ///
683 /// Returns the name with special characters (&, <, >, ", ') replaced with the
684 /// corresponding escape sequences.
685 TF_API
687 
688 ///@}
689 
691 
692 #endif // TF_STRINGUTILS_H
TF_API std::string TfGetXmlEscapedString(const std::string &in)
GLdouble s
Definition: glew.h:1390
TF_API std::string TfStringPrintf(const char *fmt,...)
GLenum src
Definition: glew.h:2410
GLuint GLuint stream
Definition: glew.h:7265
GLuint const GLchar * name
Definition: glew.h:1814
#define TF_API
Definition: api.h:40
TF_API unsigned long TfStringToULong(const std::string &txt, bool *outOfRange=NULL)
std::string TfSafeString(const char *ptr)
Definition: stringUtils.h:102
bool TfStringEndsWith(const std::string &s, const char *suffix)
Returns true if s ends with suffix.
Definition: stringUtils.h:240
FMT_CONSTEXPR auto begin(const C &c) -> decltype(c.begin())
Definition: format.h:251
TF_API long TfStringToLong(const std::string &txt, bool *outOfRange=NULL)
TF_API std::string TfStringGetSuffix(const std::string &name, char delimiter= '.')
TF_API std::vector< std::string > TfStringSplit(std::string const &src, std::string const &separator)
TF_API std::string TfStringTrimRight(const std::string &s, const char *trimChars=" \n\t\r")
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
TF_API std::ostream & operator<<(std::ostream &o, TfStreamFloat t)
GLsizei GLsizei GLchar * source
Definition: glew.h:1832
bool TfStringStartsWith(const std::string &s, const char *prefix)
Returns true if s starts with prefix.
Definition: stringUtils.h:216
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")
const GLdouble * v
Definition: glew.h:1391
TfStreamFloat(float f)
Definition: stringUtils.h:561
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.
Definition: stringUtils.h:107
Definition: token.h:89
GLclampf f
Definition: glew.h:3499
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
TF_API std::string TfVStringPrintf(const std::string &fmt, va_list ap)
GLuint in
Definition: glew.h:11510
TF_API uint64_t TfStringToUInt64(const std::string &txt, bool *outOfRange=NULL)
GLuint buffer
Definition: glew.h:1680
GLuint GLuint end
Definition: glew.h:1253
const GLfloat * c
Definition: glew.h:16296
GLsizei GLsizei GLfloat distance
Definition: glew.h:13640
GLsizei const GLchar *const * strings
Definition: glew.h:5883
TF_API bool TfStringContains(const std::string &s, const char *substring)
Returns true if s contains substring.
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
std::string TfStringJoin(ForwardIterator begin, ForwardIterator end, const char *separator=" ")
Definition: stringUtils.h:364
TF_API std::string TfStringCapitalize(const std::string &source)
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
GLfloat GLfloat p
Definition: glew.h:16321
GLsizei const GLchar *const * string
Definition: glew.h:1844
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
Definition: path.h:1245
const void * ptr(const T *p)
Definition: format.h:3292
TfStreamDouble(double d)
Definition: stringUtils.h:572
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:83
T TfUnstringify(const std::string &instring, bool *status=NULL)
Definition: stringUtils.h:585
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)
TF_API bool operator()(const std::string &lhs, const std::string &rhs) const
bool Tf_StringStartsWithImpl(char const *s, size_t slen, char const *prefix, size_t prelen)
Definition: stringUtils.h:208
TF_API std::string TfStringGetBeforeSuffix(const std::string &name, char delimiter= '.')
bool TfIsValidIdentifier(std::string const &identifier)
Definition: stringUtils.h:659
std::enable_if<!std::is_enum< T >::value, std::string >::type TfStringify(const T &v)
Definition: stringUtils.h:523
TF_API void TfEscapeStringReplaceChar(const char **in, char **out)
TF_API std::vector< std::string > TfStringTokenize(const std::string &source, const char *delimiters=" \t\n")
GLsizei const GLfloat * value
Definition: glew.h:1849
TF_API int64_t TfStringToInt64(const std::string &txt, bool *outOfRange=NULL)
GLdouble GLdouble t
Definition: glew.h:1398
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)
GLenum GLsizei len
Definition: glew.h:7752
bool Tf_StringEndsWithImpl(char const *s, size_t slen, char const *suffix, size_t suflen)
Definition: stringUtils.h:233
TF_API std::string TfGetPathName(const std::string &fileName)