39 #ifndef __UT_StringHolder_h__
40 #define __UT_StringHolder_h__
69 class ut_PatternRecord;
77 namespace UT {
inline namespace Literal {
102 , myHash(SYSstring_hash(str, myLength, true))
109 return myData ? myData :
"";
124 if (myLength != other.myLength || myHash != other.myHash)
126 if (myData ==
nullptr || other.myData ==
nullptr)
127 return (myData == other.myData);
128 return !SYSmemcmp(myData, other.myData, myLength);
132 return !(*
this == other);
139 if (other ==
nullptr)
140 return (str.myLength == 0);
141 if (str.myData ==
nullptr)
143 if (str.myLength != __builtin_strlen(other))
145 return !SYSmemcmp(str.myData, other, str.myLength);
150 return (str == other);
155 return !(str == other);
160 return !(str == other);
199 if (myStorageMode == STORE_INLINE)
200 return myDataIfInline;
217 if (myRefCount.add(-1) == 0)
221 int64 getMemoryUsage(
bool inclusive)
const;
225 return myRefCount.relaxedLoad() == 1 && myStorageMode != STORE_EXTERNAL;
230 return myDataIfInline;
235 if (myStorageMode == STORE_MALLOC && myRefCount.relaxedLoad() == 1)
237 myStorageMode = STORE_EXTERNAL;
238 return (
char*)myData;
253 char myDataIfInline[
sizeof(
const char *)];
271 _reference(str, strlen(str));
280 _reference(data, length);
311 , myLength(
s.myLength)
321 , myLength(
s.myLength)
343 , myHash(SENTINEL_HASH)
352 , myHash(str ? 0 : SENTINEL_HASH)
355 _reference(str, strlen(str));
361 return myHash == SENTINEL_HASH && !myLength;
370 myHash = SENTINEL_HASH;
377 return !myLength && myDataIfHolder && myDataIfHolder->isUnique();
386 myLength = s.myLength;
410 return myHash == s.myHash;
418 if (myHash && s.myHash && myHash != s.myHash)
421 return tl == s.
length() && SYSmemcmp(c_str(), s.
c_str(), tl) == 0;
427 return (!s || !*s) && !myHash;
434 if (myDataIfChars == s)
439 return ::strcmp(c_str(), s) == 0;
442 {
return operator==(s.
buffer()); }
445 {
return !operator==(s); }
447 {
return !operator==(s); }
449 {
return operator!=(s.
buffer()); }
460 int r = SYSmemcmp(c_str(), k.
c_str(), minlen);
463 else if (kl > minlen)
472 {
return spaceship(k) < 0; }
474 {
return spaceship(k) <= 0; }
476 {
return spaceship(k) > 0; }
478 {
return spaceship(k) >= 0; }
480 bool ignore_case=
false)
const
486 bool ignore_case=
false)
const
487 {
return compare(str, ignore_case) == 0; }
513 char separator)
const
516 pattern, case_sensitive, separator);
519 const char *separators =
", ",
520 bool *explicitly_excluded = 0,
521 int *match_index = 0,
522 ut_PatternRecord *pattern_record=
nullptr)
const
525 pattern, case_sensitive, separators, explicitly_excluded,
526 match_index, pattern_record);
529 bool *explicitly_excluded = 0,
530 int *match_index = 0,
531 ut_PatternRecord *pattern_record=
nullptr)
const
534 pattern, explicitly_excluded, match_index, pattern_record);
539 bool matchRegex(
const char *expr)
const;
547 unsigned isFloat(
int skip_spaces = 0,
int loose = 0)
const
554 operator const char *()
const
585 UTswap(myLength, other.myLength);
586 UTswap(myHash, other.myHash);
596 {
return myData !=
nullptr; }
600 {
return myData ==
nullptr; }
604 {
return myData ==
nullptr; }
610 const char *
ptr = c_str();
612 if (!SYSisspace(ptr[i]))
622 const char *str = c_str();
623 const void *
ptr = ::memchr(str, c,
length());
624 return ptr ? (
const char *)ptr - str : -1;
634 const char *
ptr = c_str();
635 const char *found_char = strpbrk(ptr, str);
637 return found_char -
ptr;
647 if (start_offset <
length())
649 const char *str = c_str();
650 const void *
ptr = ::memchr(str+start_offset, c,
653 return (
const char *)ptr - str;
665 const char *
ptr = c_str();
666 const char *found_char = strpbrk(ptr+start_offset, str);
668 return found_char -
ptr;
677 const char *str = c_str();
679 const void *
start = SYSmemrchr(str, c, n);
682 n = (
const char *)start - str;
684 if (occurrence_number <= 0)
686 start = (n == 0) ?
nullptr : SYSmemrchr(str, c, n-1);
715 return myDataIfChars;
717 else if (myDataIfHolder)
718 return myDataIfHolder->c_str();
721 #if SYS_IS_GCC_GE(6, 0) && !SYS_IS_GCC_GE(8, 0)
724 const char *
volatile empty =
"";
741 else if (myDataIfHolder)
742 return myDataIfHolder->length();
749 if (!myHash && myData)
775 int64 mem = inclusive ?
sizeof(*this) : 0;
776 if (!myLength && myDataIfHolder)
777 mem += myDataIfHolder->getMemoryUsage(
true);
786 return SYSstring_hash(str, len,
true);
799 UT_StringRef forceValidVariableName(
const char *safechars =
nullptr)
const;
814 setHolder(Holder::buildInline(src, src ? strlen(src) : 0));
819 void adoptFromMalloc(
const char *str,
exint length);
833 adoptFromMalloc(str.myData, strlen(str.myData));
837 str.myIsReference =
true;
842 if (data.
size() <= 0)
849 if (data[data.
size() - 1] !=
'\0')
855 adoptFromMalloc(data.
data(), data.
size() - 1);
864 char *stealAsMalloc();
867 static bool verifyStringLit();
893 if (!myLength && myDataIfHolder)
894 myDataIfHolder->incref();
900 if (!myLength && myDataIfHolder)
901 myDataIfHolder->decref();
905 void setHolder(Holder* holder)
908 myDataIfHolder = holder;
920 myDataIfHolder = Holder::buildInline(myDataIfChars, myLength);
945 static constexpr
uint32 SENTINEL_HASH = 0xdeadbeef;
958 return ref.operator==(lit.
asRef());
963 return ref.operator==(lit.
asRef());
968 return ref.operator!=(lit.
asRef());
973 return ref.operator!=(lit.
asRef());
982 return str.operator==(lit.
asRef());
987 return str.operator==(lit.
asRef());
992 return str.operator!=(lit.
asRef());
997 return str.operator!=(lit.
asRef());
1055 : UT_StringHolder(data,
exint(length)) { }
1058 : UT_StringHolder(data,
exint(length)) { }
1206 template<
typename... Args>
1212 size_t nb_needed =
f.format(
w, fmt, {args...});
1214 char*
buffer = (
char*)malloc(nb_needed+1);
1215 w.setBuffer(
buffer, nb_needed);
1216 f.format(
w, fmt, {args...});
1217 buffer[nb_needed] =
'\0';
1219 adoptFromMalloc(
buffer, nb_needed);
1225 template<
typename... Args>
1232 size_t nb_needed =
f.printf(
w, fmt, {args...});
1234 char*
buffer = (
char*)malloc(nb_needed+1);
1235 w.setBuffer(
buffer, nb_needed);
1236 f.printf(
w, fmt, {args...});
1237 buffer[nb_needed] =
'\0';
1239 adoptFromMalloc(
buffer, nb_needed);
1260 return substitute(find, replacement, !all ? 1 : -1);
1279 bool trimBoundingSpace();
1285 bool trimSpace(
bool leave_single_space_between_words =
false);
1289 const char *
s, std::size_t
const length);
1291 const char *
s, std::size_t
const length);
1305 myDataIfChars = str;
1315 myHash = SYSstring_hash_literal(str);
1364 namespace UT {
inline namespace Literal {
1402 template <
typename T>
1403 struct DefaultClearer;
1414 static const bool clearNeedsDestruction =
false;
1418 #endif // __UT_StringHolder_h__
SYS_FORCE_INLINE UT_StringHolder(UT_StringReferenceType, const UT_String &str)
This will make a shallow reference to the contents of the string.
bool match(const char *pattern, bool case_sensitive=true) const
std::string toStdString() const
void adoptFromString(UT_String &str)
SYS_FORCE_INLINE UT_StringHolder(const UT_StringHolder &str)
Makes a copy of the provided string.
GLboolean GLboolean GLboolean b
SYS_FORCE_INLINE const_iterator begin() const
SYS_FORCE_INLINE const char * nonNullBuffer() const
#define SYS_STATIC_ASSERT(expr)
const char * fcontain(const char *pattern, bool case_sensitive=true) const
SYS_FORCE_INLINE exint findCharIndex(char c, exint start_offset) const
Find the location of the character (or -1 if not found)
size_t operator()(const UT_StringRef &s) const
friend void swap(UT_StringRef &a, UT_StringRef &b)
Friend specialization of std::swap() to use UT_StringRef::swap()
SYS_FORCE_INLINE UT_StringRef(const char *data, exint length)
SYS_FORCE_INLINE constexpr exint length() const
unsigned multiMatch(const char *pattern, bool case_sensitive=true, const char *separators=", ", bool *explicitly_excluded=0, int *match_index=0, ut_PatternRecord *pattern_record=nullptr) const
SYS_FORCE_INLINE UT_StringHolder(UT_StringLiteralType, const char *str, size_t length)
void harden(const char *src)
int substitute(const char *find, const char *replacement, int count=-1)
SYS_FORCE_INLINE UT_StringHolder(const char *data, exint length)
Will make a copy of the provided string.
SYS_FORCE_INLINE UT_StringHolder()
SYS_NO_DISCARD_RESULT bool UTstringEndsWith(const T &str, const char *suffix, bool case_sensitive=true, exint len=-1)
UT_StringLiteralType
A marker enum to use this constructor.
SYS_FORCE_INLINE void clear()
bool contains(const char *pattern, bool case_sensitive=true) const
#define SYS_DEPRECATED_HDK_REPLACE(__V__, __R__)
bool isEmpty() const
Same as !isstring()
static void clear(UT_StringHolder &v)
GLenum const void GLuint GLint reference
SYS_FORCE_INLINE void swap(UT_StringHolder &other)
void swap(T &lhs, T &rhs)
static void clearConstruct(UT_StringHolder *p)
SYS_FORCE_INLINE UT_StringRef & operator=(UT_StringRef &&s)
bool endsWith(const UT_StringView &suffix, bool case_sense=true) const
bool equal(const UT_StringRef &str, bool ignore_case=false) const
SYS_FORCE_INLINE UT_StringHolder(const char *data, uint64 length)
SYS_FORCE_INLINE UT_StringRef(UT_StringRef &&s) noexcept
Move constructor. Steals the working data from the original.
SYS_FORCE_INLINE constexpr bool operator==(const UT_StringLit &other) const
bool operator!=(const char *s) const
SYS_FORCE_INLINE bool hasNonSpace() const
unsigned long long uint64
SYS_FORCE_INLINE exint findCharIndex(const char *str) const
Find the first location of any of the characters in the str passed in.
UT_EXTERN_TEMPLATE(UT_Array< UT_StringHolder >)
unsigned multiMatch(const char *pattern, bool case_sensitive, char separator) const
SYS_FORCE_INLINE size_t tbb_hasher(const UT_StringRef &s)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
constexpr SYS_FORCE_INLINE UT_StringLit()
SYS_FORCE_INLINE const char * data() const
SYS_FORCE_INLINE constexpr uint32 hash() const
SYS_FORCE_INLINE UT_StringRef(const UT_StringLit &lit)
Construct from string literal.
int substitute(const char *find, const char *replacement, int count=-1)
PUGI__FN unsigned int hash_string(const char_t *str)
SYS_FORCE_INLINE const UT_StringHolder & UTmakeUnsafeRefHash(const UT_StringRef &ref)
bool load(UT_IStream &is)
Load string from stream. Use is.eof() to check eof status.
GLubyte GLubyte GLubyte GLubyte w
bool contains(const char *pattern, bool case_sensitive=true) const
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
constexpr SYS_FORCE_INLINE UT_StringLit(const char(&str)[N])
std::ostream & operator<<(std::ostream &ostr, const DataType &a)
SYS_FORCE_INLINE const_iterator end() const
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const char * data() const noexcept
Returns a pointer to the first character of a view.
void saveAscii(std::ostream &os) const
UT_StringRef & operator=(const UT_StringRef &s)
Shares a reference with the source.
SYS_FORCE_INLINE UT_StringHolder(const UT_String &str)
Will make a copy of the provided string.
const char * buffer() const
SYS_FORCE_INLINE UT_StringRef(UT_StringSentinelType)
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_FORCE_INLINE size_t hash_value(const UT_StringRef &str)
UT_StringHolder(UT_String &&str)
Attempts to steal the string's buffer.
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE exint length() const
Returns the length of the string in bytes.
void adoptFromCharArray(UT_Array< char > &data)
SYS_FORCE_INLINE UT_StringHolder(const std::string &str)
Will make a copy of the provided string.
exint emplace_back(S &&...s)
bool operator==(const UT_StringRef &s) const
int compare(const UT_StringRef &str, bool ignore_case=false) const
OIIO_FORCEINLINE const vint4 & operator+=(vint4 &a, const vint4 &b)
int64 getMemoryUsage(bool inclusive) const
SYS_FORCE_INLINE exint findCharIndex(char c) const
Find the location of the character (or -1 if not found)
SYS_FORCE_INLINE const char * buffer() const
SYS_NO_DISCARD_RESULT bool UTstringIsFloat(const StringT &str, bool skip_spaces=false, bool loose=false, bool allow_underscore=false)
friend void swap(UT_StringHolder &a, UT_StringHolder &b)
SYS_FORCE_INLINE UT_StringRef(UT_StringSentinelType, const char *str)
str==nullptr turns into sentinel, otherwise act like UT_StringRef(str)
SYS_FORCE_INLINE UT_StringHolder(const char *data, uint32 length)
static const UT_StringHolder theEmptyString
SYS_FORCE_INLINE UT_StringRef(const UT_StringRef &s) noexcept
Shares a reference with the source.
bool operator>=(const UT_StringRef &k) const
const char * findWord(const char *word) const
GLboolean GLboolean GLboolean GLboolean a
SYS_FORCE_INLINE const UT_StringHolder & UTmakeUnsafeRef(const UT_StringRef &ref)
Convert a UT_StringRef into a UT_StringHolder that is a shallow reference.
GLsizei const GLchar *const * string
SYS_NO_DISCARD_RESULT int UTstringCountChar(const StringT &str, int c)
SYS_FORCE_INLINE UT_StringRef()
SYS_NO_DISCARD_RESULT bool UTstringStartsWith(const T &str, const char *prefix, bool case_sensitive=true, exint len=-1)
SYS_FORCE_INLINE UT_StringHolder & operator=(UT_StringHolder &&s)
void harden()
Take shallow copy and make it deep.
SYS_FORCE_INLINE void makeSentinel()
void saveAscii(std::ostream &os) const
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
SYS_FORCE_INLINE exint findCharIndex(const char *str, exint start_offset) const
Find the first location of any of the characters in the str passed in.
SYS_FORCE_INLINE UT_StringHolder(UT_StringHolder &&a) noexcept
Move constructor. Steals the working data from the original.
#define SYS_NO_DISCARD_RESULT
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
static SYS_FORCE_INLINE unsigned hash_string(const char *str, exint len)
SYS_FORCE_INLINE const char * c_str() const
SYS_FORCE_INLINE bool isSentinel() const
SYS_FORCE_INLINE constexpr const char * data() const
UT_StringHolder(UT_StringRef &&ref)
int spaceship(const UT_StringRef &k) const
friend SYS_FORCE_INLINE constexpr bool operator!=(const UT_StringLit &str, const char *other)
size_t format(const char *fmt, const Args &...args)
Format a string using the same formatting codes as UTformat.
friend SYS_FORCE_INLINE constexpr bool operator==(const char *other, const UT_StringLit &str)
SYS_FORCE_INLINE constexpr const char * c_str() const
bool operator<=(const UT_StringRef &k) const
OIIO_FORCEINLINE vint4 operator>>(const vint4 &a, const unsigned int bits)
const char * findWord(const char *word) const
bool operator<(const UT_StringRef &k) const
bool operator!=(const UT_StringRef &s) const
void fastReferenceWithStrlen(const char *src, exint length)
old name of method:
SYS_NO_DISCARD_RESULT bool UTstringIsInteger(const StringT &str, bool skip_spaces=false)
SYS_FORCE_INLINE UT_StringHolder(const char *data, int32 length)
void saveBinary(std::ostream &os) const
Save string to binary stream.
SYS_FORCE_INLINE constexpr bool operator!=(const UT_StringLit &other) const
int sprintf(const char *fmt,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
bool empty() const
method name that maches std::string
GLenum GLuint GLenum GLsizei const GLchar * buf
SYS_FORCE_INLINE UT_StringHolder(UT_StringReferenceType, const UT_StringRef &ref)
Makes a shallow reference to the contents of the UT_StringRef.
void saveBinary(std::ostream &os) const
Save string to binary stream.
friend void swap(UT_StringHolder &a, UT_StringRef &b)
SYS_FORCE_INLINE UT_StringHolder(UT_StringSentinelType sentinel)
Construct as a sentinel value.
SYS_FORCE_INLINE const UT_StringRef & asRef() const
static int compareNumberedString(const char *s1, const char *s2, bool case_sensitive=true, bool allow_negatives=false)
GLuint GLsizei GLsizei * length
SYS_FORCE_INLINE UT_StringRef(const UT_String &str)
This will make a shallow reference to the contents of the string.
bool operator>(const UT_StringRef &k) const
static bool isClear(const UT_StringHolder &v)
SYS_FORCE_INLINE ~UT_StringRef()
size_t operator()(const UT_StringHolder &s) const
friend SYS_FORCE_INLINE constexpr bool operator!=(const char *other, const UT_StringLit &str)
bool operator==(const UT_String &s) const
bool load(UT_IStream &is)
Load string from stream. Use is.eof() to check eof status.
UT_StringHolder(const UT_StringRef &ref)
bool multiMatch(const char *pattern, bool case_sensitive, char separator) const
SYS_FORCE_INLINE exint lastCharIndex(char c, int occurrence_number=1) const
bool operator()(const UT_StringRef &s1, const UT_StringRef &s2) const
int SYSstrcasecmp(const char *a, const char *b)
friend class UT_StringHolder
unsigned multiMatch(const UT_StringMMPattern &pattern, bool *explicitly_excluded=0, int *match_index=0, ut_PatternRecord *pattern_record=nullptr) const
SYS_FORCE_INLINE UT_StringHolder(UT_StringReferenceType, const char *str)
Will make a shallow reference.
SYS_FORCE_INLINE bool UTisstring(const char *s)
SYS_FORCE_INLINE const UT_StringHolder & asHolder() const
SYS_FORCE_INLINE exint countChar(char c) const
Count the number of times the character c occurs.
GA_API const UT_StringHolder N
const char * const_iterator
Iterators.
SYS_FORCE_INLINE UT_StringRef(const char *str)
Will make a shallow reference.
**If you just want to fire and args
void reference(const char *src)
getOption("OpenEXR.storage") storage
unsigned isInteger(int skip_spaces=0) const
Determine if string can be seen as a single integer number.
SYS_FORCE_INLINE constexpr const char * buffer() const
SYS_FORCE_INLINE void swap(UT_StringRef &other)
unsigned match(const char *pattern, bool case_sensitive=true) const
auto sprintf(const S &fmt, const T &...args) -> std::basic_string< Char >
friend SYS_FORCE_INLINE constexpr bool operator==(const UT_StringLit &str, const char *other)
bool startsWith(const UT_StringView &pfx, bool case_sense=true) const
Imported from UT_String.
static Holder * buildInline(const char *str, exint length)
SYS_FORCE_INLINE UT_StringHolder(const char *str)
Will make a copy of the provided string.
bool all(const vbool4 &v)
const char * c_str() const
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
const char * myDataIfChars
SYS_FORCE_INLINE UT_StringRef(const std::string &str)
This will make a shallow reference to the contents of the string.
unsigned isFloat(int skip_spaces=0, int loose=0) const
Determine if string can be seen as a single floating point number.
bool operator!=(const UT_String &s) const
SYS_FORCE_INLINE bool isstring() const
bool operator==(const char *s) const
SYS_FORCE_INLINE UT_StringHolder(UT_StringReferenceType, const UT_WorkBuffer &str)
This will make a shallow reference to the contents of the string.
SYS_FORCE_INLINE UT_StringHolder(UT_StringReferenceType, const std::string &str)
This will make a shallow reference to the contents of the string.
bool isUnique() const
Returns true this object is the sole owner of the underlying string.
static const UT_StringHolder theSentinel
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
const char * fcontain(const char *pattern, bool case_sensitive=true) const
SYS_FORCE_INLINE void swap(UT_StringRef &other)
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.