12 #ifndef __UT_STRINGUTILS_H__
13 #define __UT_STRINGUTILS_H__
36 bool case_sensitive =
true,
39 if (!
UTisstring(str.data()) || !(prefix && *prefix))
45 if (len > str.length())
48 const char*
start = str.data();
50 return strncmp(start, prefix, len) == 0;
59 bool case_sensitive =
true,
62 if (!
UTisstring(str.data()) || !(suffix && *suffix))
68 if (len > str.length())
71 const char*
start = (str.data() + str.length()) - len;
73 return strncmp(start, suffix, len) == 0;
86 const char*
data = str.data();
89 if (!SYSisdigit(data[i]))
95 template <
typename StringT>
122 template <
typename StringT>
137 return std::make_tuple(str, str, str);
149 if (file.length() > 0 && file[0] ==
'.')
162 return std::make_tuple(dir, fname, fext);
165 template <
typename StringT>
195 template <
typename StringT>
200 return str_extension.
equal(extension,
false);
203 template <
typename StringT>
220 while (pos < str.length())
222 pos = str.findFirstOf(static_cast<char>(
c), pos);
234 template <
typename StringT>
238 bool skip_spaces =
false,
240 bool allow_underscore =
false)
242 const char*
data = str.data();
249 for (; SYSisspace(data[i]); i++)
252 for (; data[i] ==
'-' || data[i] ==
'+'; i++)
262 if (SYSisdigit(data[i]))
283 if (ecount || dotcount)
288 if (allow_underscore)
315 if (!SYSisspace(data[i]))
329 return (digit || loose);
338 bool allow_underscore)
342 return str.isFloat(skip_spaces, loose, allow_underscore);
345 template <
typename StringT>
349 const char* cur = str.data();
357 for (; SYSisspace(*cur); ++cur)
362 for (; *cur ==
'-' || *cur ==
'+'; ++cur)
366 for (; SYSisdigit(*cur); ++cur)
372 for (; SYSisspace(*cur); ++cur)
388 return str.isInteger(skip_spaces);
402 template <
typename StringT>
411 if (str.length() == 0)
return false;
413 const char *
data = str.data();
422 const char*
filename = strrchr(data,
'/');
423 if (filename ==
nullptr)
426 int len =strlen(filename);
429 const char* fileend = filename + len -1;
430 while(*fileend !=
'.' && fileend > filename)
433 if(fileend == filename)
434 fileend = filename + len -1;
437 for(itr = fileend; itr >=
filename; itr-- )
438 if (SYSisdigit(*itr))
453 if (!(SYSisdigit(*itr) ||
454 (negative && *itr ==
'-') ||
455 (fractional && *itr ==
'.')))
473 template <
typename StringT>
482 template <
typename StringT>
486 int len = str.length();
487 const char*
data = str.data();
489 return len >= 2 && data[0] == delimiter && data[len - 1] == delimiter
490 && data[len - 2] !=
'\\';
493 template <
typename StringT,
typename IntT>
501 const char*
b = str.data();
502 const char* e = b+str.length();
506 template <
typename IntT,
typename StringT>
513 IntT number = IntT{};
514 const char*
b = str.data();
515 const char* e = b+str.length();
520 #endif // __UT_STRINGUTILS_H__
GT_API const UT_StringHolder filename
T negative(const T &val)
Return the unary negation of the given value.
SYS_NO_DISCARD_RESULT bool UTstringEndsWith(const T &str, const char *suffix, bool case_sensitive=true, exint len=-1)
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const_iterator end() const
Returns a constant iterator pointing to the end of the string.
bool UTstringIsQuoted(const StringT &str, char delimiter)
A utility class to do read-only operations on a subset of an existing string.
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool isEmpty() const
Returns true if the string is empty.
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE exint length() const
Returns the length of the string in bytes.
int SYSstrncasecmp(const char *a, const char *b, size_t n)
SYS_NO_DISCARD_RESULT UT_StringView UTstringFileName(const StringT &str)
SYS_NO_DISCARD_RESULT bool UTstringIsFloat(const StringT &str, bool skip_spaces=false, bool loose=false, bool allow_underscore=false)
SYS_API SYS_ParseStatus SYSparseInteger(const char *begin, const char *&end, int8 &number, int base=0, SYS_ParseFlags flags=SYS_ParseFlags::None)
fpreal64 dot(const CE_VectorT< T > &a, const CE_VectorT< T > &b)
SYS_NO_DISCARD_RESULT int UTstringCountChar(const StringT &str, int c)
SYS_NO_DISCARD_RESULT bool UTstringStartsWith(const T &str, const char *prefix, bool case_sensitive=true, exint len=-1)
static constexpr exint npos
#define SYS_NO_DISCARD_RESULT
SYS_ParseStatus UTstringToInt(const StringT &str, IntT &number, int base=0, SYS_ParseFlags flags=SYS_ParseFlags::None)
SYS_NO_DISCARD_RESULT std::tuple< UT_StringView, UT_StringView, UT_StringView > UTstringSplitPath(const StringT &str)
Split the given path into the directory, filename, and file extension.
GLboolean GLboolean GLboolean b
SYS_NO_DISCARD_RESULT bool UTstringIsInteger(const StringT &str, bool skip_spaces=false)
SYS_NO_DISCARD_RESULT bool UTstringIsInteger< UT_StringView >(const UT_StringView &str, bool skip_spaces)
SYS_NO_DISCARD_RESULT UT_StringView UTstringFileExtension(const StringT &str)
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool equal(const char *str, bool case_sensitive=true) const
SYS_ParseStatus
List of possible states the parsing ended in.
SYS_NO_DISCARD_RESULT bool UTstringMatchFileExtension(const StringT &str, const char *extension)
SYS_NO_DISCARD_RESULT UT_StringView UTstringFileExtension< UT_StringView >(const UT_StringView &str)
SYS_NO_DISCARD_RESULT const char * UTstringNumericSuffix(const T &str)
bool UTstringParseNumberedFilename(const StringT &str, UT_StringView &prefix, UT_StringView &frame, UT_StringView &suffix, bool negative, bool fractional)
SYS_FORCE_INLINE bool UTisstring(const char *s)
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const_iterator begin() const
Returns a constant iterator pointing to the beginning of the string.
SYS_NO_DISCARD_RESULT bool UTstringIsFloat< UT_StringView >(const UT_StringView &str, bool skip_spaces, bool loose, bool allow_underscore)
SYS_NO_DISCARD_RESULT exint findLastOf(UT_StringView view, exint pos=npos) const noexcept
SYS_NO_DISCARD_RESULT int UTstringCountChar< UT_StringView >(const UT_StringView &str, int c)
OIIO_UTIL_API std::string extension(string_view filepath, bool include_dot=true) noexcept