31 #ifndef __UT_WorkBuffer_h__
32 #define __UT_WorkBuffer_h__
63 #define UT_INITIAL_BUFFER_SIZE 2000
136 if (myBuffer != myStackBuffer)
168 const char *
buffer()
const {
return myBuffer; }
196 void release(
bool recompute_length =
false);
197 void releaseSetLength(
exint new_length);
201 int64 getMemoryUsage(
bool inclusive)
const;
214 myString = myBuffer.lock();
227 char *
string()
const {
return myString; }
236 myBuffer.release(recompute_length);
245 myString = myBuffer.lock();
264 return myBuffer[idx];
279 return myBuffer[myLength - 1];
283 int isNullTerminated()
const;
302 append(str.c_str(), str.length());
313 return (::strcmp(str, myBuffer) == 0);
318 if (!(
const char *)str)
320 return (::strcmp(str, myBuffer) == 0);
327 return (::memcmp(myBuffer, str.
c_str(), myLength) == 0);
336 return (::memcmp(myBuffer, buf.myBuffer, myLength) == 0);
341 return !(*
this == str);
346 return !(*
this == str);
351 return !(*
this == str);
356 return !(*
this ==
buf);
363 void growBufferIfNeeded()
369 while (myLength+1 > myAllocatedSize)
413 growBufferIfNeeded();
416 myLength = ::strlen(myBuffer);
424 return ::strlen(myBuffer);
442 void protectedStrcat(
const char *str,
bool force_quote=
false);
452 void fullyProtectedStrcat(
const char *str,
bool force_quote=
false);
453 void fullyProtectedBinaryStrcat(
454 const char *str,
exint size,
bool force_quote=
false);
464 append(src, ::strnlen(src, len));
470 void strcatFirstWord(
const char *
src);
476 return ::strcmp(myBuffer, src);
483 return ::strncmp(myBuffer, src, n);
490 return ::strdup(myBuffer);
497 if (myLockCount) {
UT_ASSERT(0);
return; }
505 return (myLength == 0);
520 if (offset < 0)
return;
521 if (offset >= myLength)
523 if (myLockCount) {
UT_ASSERT(0);
return; }
525 growBufferIfNeeded();
526 myBuffer[myLength] =
'\0';
556 bool getline(std::istream &is);
557 bool getline(FILE *fp);
566 const char *comment_chars =
"#",
567 const char *separators =
" \t\n\r");
569 const char *comment_chars =
"#",
570 const char *separators =
" \t\n\r");
572 const char *comment_chars =
"#",
573 const char *separators =
" \t\n\r");
583 int sprintf(
const char *fmt, ...)
585 int appendSprintf(
const char *fmt, ...)
592 template<typename... Args>
596 return appendFormat(fmt, {args...});
601 template<
typename... Args>
604 return appendFormat(fmt, {args...});
606 size_t appendFormat(
const char *fmt, std::initializer_list<UT::Format::ArgValue>
args);
612 if (myLockCount) {
UT_ASSERT(0);
return; }
615 growBufferIfNeeded();
616 myBuffer[myLength - 1] = character;
617 myBuffer[myLength] =
'\0';
621 void appendPrintMemory(
int64 mem);
625 if (myLockCount) {
UT_ASSERT(0);
return; }
628 growBufferIfNeeded();
629 for (
int i = n; i > 0; i--)
630 myBuffer[myLength - i] = character;
631 myBuffer[myLength] =
'\0';
642 if (myLockCount) {
UT_ASSERT(0);
return; }
645 growBufferIfNeeded();
646 ::memcpy(myBuffer + myLength - len, buf, len);
647 myBuffer[myLength] =
'\0';
652 if (myLockCount) {
UT_ASSERT(0);
return; }
656 growBufferIfNeeded();
657 ::memcpy(myBuffer + myLength - size, data, size);
658 myBuffer[myLength] =
'\0';
665 append(str, ::strlen(str));
672 append((
const char *)str);
750 if (myLockCount) {
UT_ASSERT(0);
return; }
753 growBufferIfNeeded();
754 ::memmove(myBuffer+1, myBuffer, myLength);
755 myBuffer[0] = character;
759 if (myLockCount) {
UT_ASSERT(0);
return; }
763 growBufferIfNeeded();
764 ::memmove(myBuffer+size, myBuffer, myLength+1 - size);
765 ::memcpy(myBuffer, data, size);
771 prepend(str, ::strlen(str));
778 prepend((
const char *)str);
800 if (myLockCount) {
UT_ASSERT(0);
return; }
803 myLength -= by_length;
805 myBuffer[myLength] =
'\0';
813 if (new_length >= myLength)
815 UT_ASSERT(0 &&
"Truncating beyond buffer extent");
818 backup(myLength-new_length);
825 if (myLockCount) {
UT_ASSERT(0);
return; }
827 while( myLength > 0 && myBuffer[myLength-1] != c )
829 myBuffer[myLength] =
'\0';
834 if (myLockCount) {
UT_ASSERT(0);
return; }
837 myLength -= by_length;
839 for (
int i=0; i<myLength; i++)
840 myBuffer[i] = myBuffer[by_length+i];
841 myBuffer[myLength] =
'\0';
846 const char *
findChar(
char c,
int occurance_number = 1)
const
848 return findCharFrom(c, 0, occurance_number);
851 const char *
lastChar(
char c,
int occurance_number = 1)
const
853 if (myLockCount) {
UT_ASSERT(0);
return NULL; }
857 for (
exint i = myLength; i --> 0;)
862 if(occurance_number <= 0)
864 return (myBuffer + i);
873 int occurance_number = 1)
const
875 if (myLockCount) {
UT_ASSERT(0);
return NULL; }
879 if (position < 0 || position >= myLength) {
return NULL; }
881 for(
exint i = position; i < myLength; ++i)
886 if(occurance_number <= 0)
888 return (myBuffer + i);
908 bool getNextToken(
const char *(&
string),
912 void copyIntoString(
UT_String &str)
const;
916 void copyIntoString(
char *str,
exint max_length)
const;
930 std::
string toStdString()
const
937 bool stripComments(
char comment_char =
'#');
942 int strip(
const char *chars);
945 void removeTrailingSpaceLines();
948 bool removeTrailingSpace();
951 bool removeLeadingSpace();
954 bool removeTrailingDigits();
963 void makeIndentString(
exint indent,
exint tabstop=8);
971 ::memmove(myBuffer, myBuffer + n, myLength);
976 myBuffer[myLength] =
'\0';
982 int substitute(
const char *
find,
const char *replacement,
int count = -1);
988 return substitute(find, replacement, !all ? 1 : -1);
1001 const char *to_pattern,
1002 const char *from_name,
1003 const char *from_pattern);
1011 void setFromUTF16(
const utf16 *str);
1016 void setAsUTF16(
const utf8 *str);
1033 bool this_stack = (myBuffer == myStackBuffer);
1034 bool other_stack = (other.myBuffer == other.myStackBuffer);
1036 if (this_stack && other_stack)
1040 size_t max_size = (myLength > other.myLength) ? myLength
1043 UTswap(myStackBuffer, other.myStackBuffer, max_size + 1);
1045 else if (this_stack && !other_stack)
1047 ::memcpy(other.myStackBuffer, myStackBuffer, myLength + 1);
1048 myBuffer = other.myBuffer;
1049 other.myBuffer = other.myStackBuffer;
1051 else if (!this_stack && other_stack)
1053 ::memcpy(myStackBuffer, other.myStackBuffer, other.myLength + 1);
1054 other.myBuffer = myBuffer;
1055 myBuffer = myStackBuffer;
1058 UTswap(myBuffer, other.myBuffer);
1059 UTswap(myAllocatedSize, other.myAllocatedSize);
1060 UTswap(myLength, other.myLength);
1061 UTswap(myLockCount, other.myLockCount);
1066 const char *
begin()
const {
return myBuffer; }
1068 const char *
end()
const {
return myBuffer + myLength; }
1073 struct do_narrow {};
1095 char *myBuffer = myStackBuffer;
1098 int myLockCount = 0;
1108 return buf.operator==(lit.
asRef());
1113 return buf.operator==(lit.
asRef());
1118 return buf.operator!=(lit.
asRef());
1123 return buf.operator!=(lit.
asRef());
1127 static inline size_t
1135 ::memcpy(buffer, v.
buffer(), len);
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
SYS_FORCE_INLINE void append(const UT_StringRef &str)
GLenum GLuint GLenum GLsizei const GLchar * buf
std::string upper(string_view a)
Return an all-upper case version of a (locale-independent).
GT_API const UT_StringHolder filename
SYS_FORCE_INLINE exint length() const
#define SYS_DEPRECATED(__V__)
SYS_FORCE_INLINE constexpr exint length() const
SYS_FORCE_INLINE void strcpy(const UT_StringRef &src)
void write(exint offset, const UT_StringHolder &src)
SYS_FORCE_INLINE exint getAllocatedSize() const
SYS_FORCE_INLINE char * operator*() const
SYS_FORCE_INLINE bool operator==(const UT_StringRef &str) const
SYS_FORCE_INLINE bool operator==(const UT_String &str) const
SYS_FORCE_INLINE UT_WorkBuffer(const char *data, exint size)
SYS_FORCE_INLINE void append(const UT_StringView &view)
SYS_FORCE_INLINE void strncat(const char *src, exint len)
GLsizei const GLchar *const * string
SYS_FORCE_INLINE UT_WorkBuffer(const UT_StringRef &str)
SYS_FORCE_INLINE UT_WorkBuffer(const char *str)
void append(exint n, char character)
SYS_FORCE_INLINE const char * buffer() const
GLuint GLsizei GLsizei * length
SYS_FORCE_INLINE void strcpy(const char *src)
SYS_FORCE_INLINE void release(bool recompute_length=false)
You can manually release the buffer.
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
const char * findCharFrom(char c, exint position, int occurance_number=1) const
SYS_FORCE_INLINE bool operator!=(const UT_StringRef &str) const
void append(const char *data, exint size)
const char * lastChar(char c, int occurance_number=1) const
unsigned long long uint64
OIIO_FORCEINLINE vbool4 insert(const vbool4 &a, bool val)
Helper: substitute val for a[i].
SYS_FORCE_INLINE char last() const
utf16 * lockUTF16(exint offset=0, exint len=0)
Lock buffer for len utf-16 characters.
SYS_FORCE_INLINE void relock()
If you've manually released the lock, you can relock the buffer.
SYS_FORCE_INLINE void append(const UT_String &str)
SIM_API const UT_StringHolder all
SYS_FORCE_INLINE const char * data() const
SYS_FORCE_INLINE void append(const UT_StringLit &str)
void swap(UT_WorkBuffer &other)
void eraseHead(exint n)
Remove the first n characters.
SYS_FORCE_INLINE void append(const UT_WorkBuffer &wb)
SYS_FORCE_INLINE bool operator==(const UT_WorkBuffer &buf) const
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
std::ostream & operator<<(std::ostream &ostr, const DataType &a)
SYS_FORCE_INLINE UT_WorkBuffer & operator+=(const UT_WorkBuffer &wb)
SYS_NO_DISCARD_RESULT SYS_FORCE_INLINE const char * data() const noexcept
Returns a pointer to the first character of a view.
SYS_FORCE_INLINE void append(const char *str)
A utility class to do read-only operations on a subset of an existing string.
static const utf8 * convert(const utf8 *str, utf32 &cp)
size_t appendFormat(const char *fmt, const Args &...args)
#define UT_INITIAL_BUFFER_SIZE
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_FORCE_INLINE void strcpy(const UT_WorkBuffer &src)
SYS_FORCE_INLINE void strcpy(const UT_StringView &src)
SYS_FORCE_INLINE const char * buffer() const
SYS_FORCE_INLINE UT_WorkBuffer & operator+=(const UT_Digits &digits)
SYS_FORCE_INLINE const char * end() const
SYS_FORCE_INLINE UT_WorkBuffer & operator=(const UT_WorkBuffer &other)
void printMemory(int64 mem)
#define SYS_PRINTF_CHECK_ATTRIBUTE(string_index, first_to_check)
SYS_FORCE_INLINE const char * begin() const
Iterator compatibility.
GLint GLint GLsizei GLint GLenum format
SYS_FORCE_INLINE void prepend(const UT_StringRef &str)
SYS_FORCE_INLINE UT_WorkBuffer(const UT_StringView &view)
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
void prepend(char character)
SYS_FORCE_INLINE bool isEmpty() const
SYS_FORCE_INLINE char * strdup() const
static SYS_FORCE_INLINE UT_WorkBuffer widen(const utf8 *str)
SYS_FORCE_INLINE const char * findChar(char c, int occurance_number=1) const
SYS_FORCE_INLINE UT_WorkBuffer & operator+=(const UT_String &str)
SYS_FORCE_INLINE exint strlen() const
SYS_FORCE_INLINE bool operator!=(const UT_WorkBuffer &buf) const
SYS_FORCE_INLINE UT_WorkBuffer & operator=(const std::string &str)
SYS_FORCE_INLINE const char * c_str() const
SYS_FORCE_INLINE void strcpy(const UT_String &src)
#define UT_UTF8_MAX_ENCODING_LEN
size_t SYSstrlcpy(char *dest, const char *src, size_t size)
SYS_FORCE_INLINE char * string() const
SYS_FORCE_INLINE void prepend(const UT_String &str)
SYS_FORCE_INLINE char operator()(exint idx) const
SYS_FORCE_INLINE UT_WorkBuffer(const UT_WorkBuffer &other)
SYS_FORCE_INLINE void strcat(const char *src)
SYS_FORCE_INLINE void truncate(exint new_length)
SYS_FORCE_INLINE const utf16 * castToUTF16() const
Once set as UTF16-LE, get it back as such a pointer.
auto reserve(std::back_insert_iterator< Container > it, size_t n) -> checked_ptr< typename Container::value_type >
SYS_FORCE_INLINE const UT_StringRef & asRef() const
void append(utf32 cp)
Append a single Unicode code point, converted to UTF8.
SYS_FORCE_INLINE int strcmp(const char *src) const
static SYS_FORCE_INLINE UT_WorkBuffer narrow(const utf16 *str)
SYS_FORCE_INLINE UT_WorkBuffer & operator=(const char *str)
SYS_FORCE_INLINE bool isstring() const
SYS_FORCE_INLINE void backup(exint by_length)
Rewind by the given length.
void write(exint offset, const char *src)
SYS_FORCE_INLINE UT_WorkBuffer(const UT_String &str)
SYS_FORCE_INLINE AutoLock(UT_WorkBuffer &buf)
SYS_FORCE_INLINE bool operator==(const char *str) const
SYS_FORCE_INLINE UT_WorkBuffer(const UT_StringLit &str)
std::string lower(string_view a)
Return an all-upper case version of a (locale-independent).
void advance(exint by_length)
SYS_FORCE_INLINE bool operator!=(const char *str) const
SYS_FORCE_INLINE UT_WorkBuffer & operator+=(const char *str)
SIM_API const UT_StringHolder position
SYS_FORCE_INLINE bool UTisstring(const char *s)
SYS_FORCE_INLINE void append(char character)
void prepend(const char *data, exint size)
virtual bool readFile(GA_Detail &g, const char *filename, const GA_LoadOptions *opts, UT_StringArray *errors) const
Class which defines an I/O interface to save/load geometry.
**If you just want to fire and args
auto vsprintf(const S &fmt, basic_format_args< basic_printf_context_t< type_identity_t< Char >>> args) -> std::basic_string< Char >
SYS_FORCE_INLINE ~UT_WorkBuffer()
SYS_FORCE_INLINE void clear()
SYS_FORCE_INLINE constexpr const char * buffer() const
SYS_FORCE_INLINE ~AutoLock()
auto sprintf(const S &fmt, const T &...args) -> std::basic_string< Char >
string_view OIIO_UTIL_API strip(string_view str, string_view chars=string_view())
SYS_FORCE_INLINE char first() const
void write(T &out, bool v)
SYS_FORCE_INLINE bool operator!=(const UT_String &str) const
SYS_FORCE_INLINE UT_WorkBuffer & operator+=(const UT_StringRef &str)
SYS_FORCE_INLINE UT_WorkBuffer & operator+=(const std::string &str)
Converts a double or float or half to the shortest accurate decimal possible.
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
SYS_FORCE_INLINE void write(exint offset, char c)
SYS_FORCE_INLINE bool isstring() const
SYS_FORCE_INLINE void prepend(const char *str)
SYS_FORCE_INLINE void strncpy(const char *src, exint maxlen)
SYS_FORCE_INLINE int strncmp(const char *src, exint n) const
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
SYS_FORCE_INLINE UT_WorkBuffer()