11 #ifndef __UT_StringView__
12 #define __UT_StringView__
57 myEnd = myStart + __builtin_strlen(myStart);
68 myEnd = myStart + len;
76 : myStart(start), myEnd(end)
78 UT_ASSERT((!myStart && !myEnd) || myStart <= myEnd);
108 bool isEmpty()
const {
return myStart == myEnd; }
121 {
return inclusive ?
sizeof(*this) : 0; }
137 const char*
data() const noexcept {
return myStart; }
145 "Undefined behaviour trying to get front of empty string.");
154 "Undefined behaviour trying to get back of empty string.");
155 return myStart[
length() - 1];
165 UT_ASSERT(pos >= 0 && myStart + pos >= myStart);
166 for (
const char *
c = myStart + pos;
c < myEnd; ++
c)
169 return static_cast<exint>(
c - myStart);
210 UT_ASSERT(pos >= 0 && myStart + pos >= myStart);
211 for (
const char *
c = myStart + pos;
c < myEnd; ++
c)
214 return static_cast<exint>(
c - myStart);
269 void clear() { myStart = myEnd =
nullptr; }
275 {
return trimInternal(
c,
true,
true); }
281 {
return trimInternal(
c,
true,
false); }
287 {
return trimInternal(
c,
false,
true); }
291 UT_StringView firstToken(
const char *sep_chars =
" \t\n\r")
const;
299 bool group_separators =
true)
const;
308 int max_split = INT_MAX)
const;
320 void removePrefix(
exint n);
323 void removeSuffix(
exint n);
336 bool case_sensitive=
true)
const;
339 bool case_sensitive=
true)
const;
345 bool equal(
const char *str,
bool case_sensitive=
true)
const
347 case_sensitive) == 0; }
350 bool case_sensitive=
true)
const
351 {
return compare(other, case_sensitive) == 0; }
359 {
return compare(other) == 0; }
367 {
return compare(other) != 0; }
379 const_iterator
find(
char c, const_iterator
start)
const;
385 const_iterator
find(
const char *str, const_iterator
start)
const;
393 const_iterator
rfind(
char c, const_iterator pos)
const;
399 bool startsWith(
const char* prefix,
400 bool case_sensitive =
true,
401 exint len = -1)
const;
403 bool endsWith(
const char* prefix,
404 bool case_sensitive =
true,
405 exint len = -1)
const;
410 bool isFloat(
bool skip_spaces =
false,
412 bool allow_underscore =
false)
const;
415 bool isInteger(
bool skip_spaces =
false)
const;
420 return SYSstring_hash(myStart,
length(),
true);
426 const char *myStart, *myEnd;
458 #endif // __UT_StringView__
UT_API std::ostream & operator<<(std::ostream &os, const UT_StringView &sv)
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const_iterator find(const char *str) const
SYS_NO_DISCARD_RESULT exint findFirstNotOf(const char *s, exint pos) const
Returns the length of the string in bytes.
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const char & back() const
constexpr SYS_FORCE_INLINE UT_StringView(const char *str)
Construct a string view from the entirety of a null-terminated string.
SYS_NO_DISCARD_RESULT exint findLastNotOf(const char *s, exint pos) const
Returns the length of the string in bytes.
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const_iterator find(char c) const
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool operator<(const UT_StringView &other) const
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool operator<(const char *str) const
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE UT_StringView trimLeft(const char *c=" \t\n\r") const
CompareResults OIIO_API compare(const ImageBuf &A, const ImageBuf &B, float failthresh, float warnthresh, float failrelative, float warnrelative, ROI roi={}, int nthreads=0)
constexpr SYS_FORCE_INLINE UT_StringView()
Default constructor. Constructs an empty non-string.
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const_iterator end() const
Returns a constant iterator pointing to the end of the string.
GLuint GLsizei GLsizei * length
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
SYS_NO_DISCARD_RESULT exint findLastOf(const char *s, exint pos, exint count) const
Returns the length of the string in bytes.
size_t operator()(const UT_StringView &s) const
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool operator==(const char *str) const
Returns true if the two strings compare as being equal.
SYS_NO_DISCARD_RESULT unsigned hash() const
const char * const_iterator
The iterator type. UT_StringView only provides read-only iterators.
#define UT_ASSERT_MSG(ZZ,...)
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const char * data() const noexcept
Returns a pointer to the first character of a view.
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE int64 getMemoryUsage(bool inclusive) const
Returns the memory, in bytes, used by this object.
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.
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE constexpr T * SYSaddressof(T &val) noexcept
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool equal(const UT_StringView &other, bool case_sensitive=true) const
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const_iterator rfind(char c) const
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const char & at(exint pos) const
Returns the character at index i.
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const char & front() const
size_t OIIO_UTIL_API rfind(string_view a, string_view b)
static constexpr exint npos
#define SYS_NO_DISCARD_RESULT
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool operator==(const UT_StringView &other) const
constexpr SYS_FORCE_INLINE UT_StringView(const char *str, exint len)
Construct a string view on a string of a given length.
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE char operator[](exint i) const
Returns the character at index i. No bounds checking is performed.
SYS_NO_DISCARD_RESULT exint findFirstNotOf(const char *s, exint pos, exint count) const
Returns the length of the string in bytes.
__hostdev__ bool isInteger(GridType gridType)
Return true if the GridType maps to a POD integer type.
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool equal(const char *str, bool case_sensitive=true) const
SYS_NO_DISCARD_RESULT exint findFirstOf(const char *s, exint pos, exint count) const
Returns the length of the string in bytes.
SYS_NO_DISCARD_RESULT exint findLastOf(const char *s, exint pos=npos) const
Returns the length of the string in bytes.
LeafData & operator=(const LeafData &)=delete
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const_iterator begin() const
Returns a constant iterator pointing to the beginning of the string.
SYS_FORCE_INLINE UT_StringView(const char *start, const char *end)
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool isstring() const
Returns true if the view points to a non-empty string.
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE UT_StringView trimRight(const char *c=" \t\n\r") const
UT_Array< UT_StringView > UT_StringViewArray
void OIIO_UTIL_API split(string_view str, std::vector< string_view > &result, string_view sep=string_view(), int maxsplit=-1)
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool operator!=(const UT_StringView &other) const
SYS_NO_DISCARD_RESULT exint findLastNotOf(const char *s, exint pos, exint count) const
Returns the length of the string in bytes.
size_t hash_value(const CH_ChannelRef &ref)
SYS_NO_DISCARD_RESULT exint findFirstOf(const char *s, exint pos) const
Returns the length of the string in bytes.
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE UT_StringView trim(const char *c=" \t\n\r") const
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE bool operator!=(const char *str) const
Returns true if the two strings compare as being not equal.
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.