12 #ifndef __UT_STRINGUTILS_H__
13 #define __UT_STRINGUTILS_H__
24 #include <type_traits>
33 bool case_sensitive =
true,
36 if (!
UTisstring(str.data()) || !(prefix && *prefix))
42 if (
len > str.length())
45 const char*
start = str.data();
47 return strncmp(start, prefix,
len) == 0;
56 bool case_sensitive =
true,
59 if (!
UTisstring(str.data()) || !(suffix && *suffix))
65 if (
len > str.length())
68 const char*
start = (str.data() + str.length()) -
len;
70 return strncmp(start, suffix,
len) == 0;
83 const char*
data = str.data();
86 if (!SYSisdigit(data[i]))
92 template <
typename StringT>
118 template <
typename StringT>
148 template <
typename StringT>
153 return str_extension.
equal(extension,
false);
156 template <
typename StringT>
173 while (pos < str.length())
175 pos = str.findFirstOf(static_cast<char>(
c), pos);
187 template <
typename StringT>
191 bool skip_spaces =
false,
193 bool allow_underscore =
false)
195 const char*
data = str.data();
202 for (; SYSisspace(data[i]); i++)
205 for (; data[i] ==
'-' || data[i] ==
'+'; i++)
215 if (SYSisdigit(data[i]))
236 if (ecount || dotcount)
241 if (allow_underscore)
268 if (!SYSisspace(data[i]))
282 return (digit || loose);
291 bool allow_underscore)
295 return str.isFloat(skip_spaces, loose, allow_underscore);
298 template <
typename StringT>
302 const char* cur = str.data();
310 for (; SYSisspace(*cur); ++cur)
315 for (; *cur ==
'-' || *cur ==
'+'; ++cur)
319 for (; SYSisdigit(*cur); ++cur)
325 for (; SYSisspace(*cur); ++cur)
341 return str.isInteger(skip_spaces);
344 #endif // __UT_STRINGUTILS_H__
SYS_NO_DISCARD_RESULT bool UTstringEndsWith(const T &str, const char *suffix, bool case_sensitive=true, exint len=-1)
OIIO_API std::string extension(const std::string &filepath, bool include_dot=true) noexcept
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const_iterator end() const
Returns a constant iterator pointing to the end of the string.
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.
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)
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_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_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)
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)