12 #ifndef __UT_STRINGUTILS_H__
13 #define __UT_STRINGUTILS_H__
31 template <
typename T,
bool HasFastLength = true>
36 bool case_sensitive =
true,
39 if (!
UTisstring(str.data()) || !(prefix && *prefix))
45 if constexpr (HasFastLength)
47 if (len > str.length())
51 const char*
start = str.data();
53 return strncmp(start, prefix, len) == 0;
62 bool case_sensitive =
true,
65 if (!
UTisstring(str.data()) || !(suffix && *suffix))
71 if (len > str.length())
74 const char*
start = (str.data() + str.length()) - len;
76 return strncmp(start, suffix, len) == 0;
89 const char*
data = str.data();
92 if (!SYSisdigit(data[i]))
98 template <
typename StringT>
125 template <
typename StringT>
140 return std::make_tuple(str, str, str);
152 if (file.length() > 0 && file[0] ==
'.')
165 return std::make_tuple(dir, fname, fext);
168 template <
typename StringT>
198 template <
typename StringT>
203 return str_extension.
equal(extension,
false);
206 template <
typename StringT>
223 while (pos < str.length())
225 pos = str.findFirstOf(static_cast<char>(
c), pos);
237 template <
typename StringT>
241 bool skip_spaces =
false,
243 bool allow_underscore =
false)
245 const char*
data = str.data();
252 for (; SYSisspace(data[i]); i++)
255 for (; data[i] ==
'-' || data[i] ==
'+'; i++)
265 if (SYSisdigit(data[i]))
286 if (ecount || dotcount)
291 if (allow_underscore)
318 if (!SYSisspace(data[i]))
332 return (digit || loose);
341 bool allow_underscore)
345 return str.isFloat(skip_spaces, loose, allow_underscore);
348 template <
typename StringT>
352 const char* cur = str.data();
360 for (; SYSisspace(*cur); ++cur)
365 for (; *cur ==
'-' || *cur ==
'+'; ++cur)
369 for (; SYSisdigit(*cur); ++cur)
375 for (; SYSisspace(*cur); ++cur)
391 return str.isInteger(skip_spaces);
405 template <
typename StringT>
414 if (str.length() == 0)
return false;
416 const char *
data = str.data();
425 const char*
filename = strrchr(data,
'/');
426 if (filename ==
nullptr)
429 int len =strlen(filename);
432 const char* fileend = filename + len -1;
433 while(*fileend !=
'.' && fileend > filename)
436 if(fileend == filename)
437 fileend = filename + len -1;
440 for(itr = fileend; itr >=
filename; itr-- )
441 if (SYSisdigit(*itr))
456 if (!(SYSisdigit(*itr) ||
457 (negative && *itr ==
'-') ||
458 (fractional && *itr ==
'.')))
476 template <
typename StringT>
485 template <
typename StringT>
489 int len = str.length();
490 const char*
data = str.data();
492 return len >= 2 && data[0] == delimiter && data[len - 1] == delimiter
493 && data[len - 2] !=
'\\';
496 template <
typename StringT,
typename IntT>
504 const char*
b = str.data();
505 const char* e = b+str.length();
509 template <
typename IntT,
typename StringT>
516 IntT number = IntT{};
517 const char*
b = str.data();
518 const char* e = b+str.length();
523 #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 bool UTstringStartsWith(const T &str, const char *prefix, 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)
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