12 #ifndef __UT_STRINGUTILS_H__
13 #define __UT_STRINGUTILS_H__
25 #include <type_traits>
34 bool case_sensitive =
true,
37 if (!
UTisstring(str.data()) || !(prefix && *prefix))
43 if (
len > str.length())
46 const char*
start = str.data();
48 return strncmp(start, prefix,
len) == 0;
57 bool case_sensitive =
true,
60 if (!
UTisstring(str.data()) || !(suffix && *suffix))
66 if (
len > str.length())
69 const char*
start = (str.data() + str.length()) -
len;
71 return strncmp(start, suffix,
len) == 0;
84 const char*
data = str.data();
87 if (!SYSisdigit(data[i]))
93 template <
typename StringT>
120 template <
typename StringT>
135 return std::make_tuple(str, str, str);
155 return std::make_tuple(dir, fname, fext);
158 template <
typename StringT>
188 template <
typename StringT>
193 return str_extension.
equal(extension,
false);
196 template <
typename StringT>
213 while (pos < str.length())
215 pos = str.findFirstOf(static_cast<char>(
c), pos);
227 template <
typename StringT>
231 bool skip_spaces =
false,
233 bool allow_underscore =
false)
235 const char*
data = str.data();
242 for (; SYSisspace(data[i]); i++)
245 for (; data[i] ==
'-' || data[i] ==
'+'; i++)
255 if (SYSisdigit(data[i]))
276 if (ecount || dotcount)
281 if (allow_underscore)
308 if (!SYSisspace(data[i]))
322 return (digit || loose);
331 bool allow_underscore)
335 return str.isFloat(skip_spaces, loose, allow_underscore);
338 template <
typename StringT>
342 const char* cur = str.data();
350 for (; SYSisspace(*cur); ++cur)
355 for (; *cur ==
'-' || *cur ==
'+'; ++cur)
359 for (; SYSisdigit(*cur); ++cur)
365 for (; SYSisspace(*cur); ++cur)
381 return str.isInteger(skip_spaces);
384 #endif // __UT_STRINGUTILS_H__
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.
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)
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 std::tuple< UT_StringView, UT_StringView, UT_StringView > UTstringSplitPath(const StringT &str)
Split the given path into the directory, filename, and file extension.
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)
OIIO_UTIL_API std::string extension(string_view filepath, bool include_dot=true) noexcept