11 #ifndef __UT_StringView__
12 #define __UT_StringView__
56 myEnd = myStart + __builtin_strlen(myStart);
67 myEnd = myStart + len;
75 : myStart(start), myEnd(end)
77 UT_ASSERT((!myStart && !myEnd) || myStart <= myEnd);
107 bool isEmpty()
const {
return myStart == myEnd; }
120 {
return inclusive ?
sizeof(*this) : 0; }
136 const char*
data() const noexcept {
return myStart; }
144 "Undefined behaviour trying to get front of empty string.");
153 "Undefined behaviour trying to get back of empty string.");
154 return myStart[
length() - 1];
164 UT_ASSERT(pos >= 0 && myStart + pos >= myStart);
165 for (
const char *
c = myStart + pos;
c < myEnd; ++
c)
168 return static_cast<exint>(
c - myStart);
189 return findLastOf(
UT_StringView(std::addressof(item), 1), pos);
209 UT_ASSERT(pos >= 0 && myStart + pos >= myStart);
210 for (
const char *
c = myStart + pos;
c < myEnd; ++
c)
213 return static_cast<exint>(
c - myStart);
235 return findLastNotOf(
UT_StringView(std::addressof(item), 1), pos);
268 void clear() { myStart = myEnd =
nullptr; }
274 {
return trimInternal(
c,
true,
true); }
280 {
return trimInternal(
c,
true,
false); }
286 {
return trimInternal(
c,
false,
true); }
290 UT_StringView firstToken(
const char *sep_chars =
" \t\n\r")
const;
298 bool group_separators =
true)
const;
307 int max_split = INT_MAX)
const;
319 void removePrefix(
exint n);
322 void removeSuffix(
exint n);
335 bool case_sensitive=
true)
const;
338 bool case_sensitive=
true)
const;
344 bool equal(
const char *str,
bool case_sensitive=
true)
const
346 case_sensitive) == 0; }
349 bool case_sensitive=
true)
const
350 {
return compare(other, case_sensitive) == 0; }
358 {
return compare(other) == 0; }
366 {
return compare(other) != 0; }
378 const_iterator
find(
char c, const_iterator
start)
const;
384 const_iterator
find(
const char *str, const_iterator
start)
const;
392 const_iterator
rfind(
char c, const_iterator pos)
const;
398 bool startsWith(
const char* prefix,
399 bool case_sensitive =
true,
400 exint len = -1)
const;
402 bool endsWith(
const char* prefix,
403 bool case_sensitive =
true,
404 exint len = -1)
const;
409 bool isFloat(
bool skip_spaces =
false,
411 bool allow_underscore =
false)
const;
414 bool isInteger(
bool skip_spaces =
false)
const;
419 return SYSstring_hash(myStart,
length(),
true);
425 const char *myStart, *myEnd;
457 #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
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
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.
CompareResults OIIO_API compare(const ImageBuf &A, const ImageBuf &B, float failthresh, float warnthresh, ROI roi={}, int nthreads=0)
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 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.
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.