31 #ifndef __UT_WorkBuffer_h__
32 #define __UT_WorkBuffer_h__
64 #define UT_INITIAL_BUFFER_SIZE 2000
137 if (myBuffer != myStackBuffer)
169 const char *
buffer()
const {
return myBuffer; }
201 void release(
bool recompute_length =
false);
202 void releaseSetLength(
exint new_length);
206 int64 getMemoryUsage(
bool inclusive)
const;
219 myString = myBuffer.lock();
232 char *
string()
const {
return myString; }
241 myBuffer.release(recompute_length);
250 myString = myBuffer.lock();
269 return myBuffer[idx];
284 return myBuffer[myLength - 1];
288 int isNullTerminated()
const;
307 append(str.c_str(), str.length());
318 return (::strcmp(str, myBuffer) == 0);
323 if (!(
const char *)str)
325 return (::strcmp(str, myBuffer) == 0);
332 return (::memcmp(myBuffer, str.
c_str(), myLength) == 0);
341 return (::memcmp(myBuffer, buf.myBuffer, myLength) == 0);
346 return !(*
this == str);
351 return !(*
this == str);
356 return !(*
this == str);
361 return !(*
this ==
buf);
368 void growBufferIfNeeded()
374 while (myLength+1 > myAllocatedSize)
418 growBufferIfNeeded();
421 myLength = ::strlen(myBuffer);
429 return ::strlen(myBuffer);
447 void protectedStrcat(
const char *str,
bool force_quote=
false);
457 void fullyProtectedStrcat(
const char *str,
bool force_quote=
false);
458 void fullyProtectedBinaryStrcat(
459 const char *str,
exint size,
bool force_quote=
false);
469 append(src, ::strnlen(src, len));
475 void strcatFirstWord(
const char *
src);
481 return ::strcmp(myBuffer, src);
488 return ::strncmp(myBuffer, src, n);
495 return ::strdup(myBuffer);
502 if (myLockCount) {
UT_ASSERT(0);
return; }
510 return (myLength == 0);
525 if (offset < 0)
return;
526 if (offset >= myLength)
528 if (myLockCount) {
UT_ASSERT(0);
return; }
530 growBufferIfNeeded();
531 myBuffer[myLength] =
'\0';
552 write(offset, src.
c_str());
561 bool getline(std::istream &is);
562 bool getline(FILE *
fp);
571 const char *comment_chars =
"#",
572 const char *separators =
" \t\n\r");
574 const char *comment_chars =
"#",
575 const char *separators =
" \t\n\r");
577 const char *comment_chars =
"#",
578 const char *separators =
" \t\n\r");
588 int sprintf(
const char *fmt, ...)
590 int appendSprintf(const
char *fmt, ...)
592 int vsprintf(const
char *fmt, va_list ap);
597 template<typename... Args>
601 return appendFormat(fmt, {args...});
607 template<
typename... Args>
610 return appendFormat(fmt, {args...});
612 size_t appendFormat(
const char *fmt, std::initializer_list<UT::Format::ArgValue>
args);
616 size_t appendFormatByArray(
const char *fmt,
618 bool report_errors =
true);
624 if (myLockCount) {
UT_ASSERT(0);
return; }
627 growBufferIfNeeded();
628 myBuffer[myLength - 1] = character;
629 myBuffer[myLength] =
'\0';
633 void appendPrintMemory(
int64 mem);
637 if (myLockCount) {
UT_ASSERT(0);
return; }
640 growBufferIfNeeded();
641 std::fill(myBuffer+myLength-n, myBuffer+myLength, character);
642 myBuffer[myLength] =
'\0';
653 if (myLockCount) {
UT_ASSERT(0);
return; }
656 growBufferIfNeeded();
657 ::memcpy(myBuffer + myLength - len, buf, len);
658 myBuffer[myLength] =
'\0';
663 if (myLockCount) {
UT_ASSERT(0);
return; }
667 growBufferIfNeeded();
668 ::memcpy(myBuffer + myLength - size, data, size);
669 myBuffer[myLength] =
'\0';
676 append(str, ::strlen(str));
683 append((
const char *)str);
761 if (myLockCount) {
UT_ASSERT(0);
return; }
764 growBufferIfNeeded();
765 ::memmove(myBuffer+1, myBuffer, myLength);
766 myBuffer[0] = character;
770 if (myLockCount) {
UT_ASSERT(0);
return; }
774 growBufferIfNeeded();
775 ::memmove(myBuffer+size, myBuffer, myLength+1 - size);
776 ::memcpy(myBuffer, data, size);
782 prepend(str, ::strlen(str));
789 prepend((
const char *)str);
811 if (myLockCount) {
UT_ASSERT(0);
return; }
814 myLength -= by_length;
816 myBuffer[myLength] =
'\0';
824 if (new_length >= myLength)
829 &&
"Truncating beyond buffer extent");
832 backup(myLength-new_length);
839 if (myLockCount) {
UT_ASSERT(0);
return; }
841 while( myLength > 0 && myBuffer[myLength-1] != c )
843 myBuffer[myLength] =
'\0';
848 if (myLockCount) {
UT_ASSERT(0);
return; }
851 myLength -= by_length;
853 for (
int i=0; i<myLength; i++)
854 myBuffer[i] = myBuffer[by_length+i];
855 myBuffer[myLength] =
'\0';
860 const char *
findChar(
char c,
int occurance_number = 1)
const
862 return findCharFrom(c, 0, occurance_number);
865 const char *
lastChar(
char c,
int occurance_number = 1)
const
867 if (myLockCount) {
UT_ASSERT(0);
return NULL; }
871 for (
exint i = myLength; i --> 0;)
876 if(occurance_number <= 0)
878 return (myBuffer + i);
887 int occurance_number = 1)
const
889 if (myLockCount) {
UT_ASSERT(0);
return NULL; }
893 if (position < 0 || position >= myLength) {
return NULL; }
895 for(
exint i = position; i < myLength; ++i)
900 if(occurance_number <= 0)
902 return (myBuffer + i);
922 bool getNextToken(
const char *(&
string),
926 void copyIntoString(
UT_String &str)
const;
930 void copyIntoString(
char *str,
exint max_length)
const;
944 std::
string toStdString()
const
951 bool stripComments(
char comment_char =
'#');
956 int strip(
const char *chars);
959 void removeTrailingSpaceLines();
962 bool removeTrailingSpace();
965 bool removeLeadingSpace();
968 bool removeTrailingDigits();
977 void makeIndentString(
exint indent,
exint tabstop=8);
985 ::memmove(myBuffer, myBuffer + n, myLength);
990 myBuffer[myLength] =
'\0';
996 int substitute(
const char *
find,
const char *replacement,
int count = -1);
1000 int substitute(const
char *
find, const
char *replacement,
bool all)
1002 return substitute(find, replacement, !all ? 1 : -1);
1015 const char *to_pattern,
1016 const char *from_name,
1017 const char *from_pattern);
1025 void setFromUTF16(
const utf16 *str);
1030 void setAsUTF16(
const utf8 *str);
1047 bool this_stack = (myBuffer == myStackBuffer);
1048 bool other_stack = (other.myBuffer == other.myStackBuffer);
1050 if (this_stack && other_stack)
1054 size_t max_size = (myLength > other.myLength) ? myLength
1057 UTswap(myStackBuffer, other.myStackBuffer, max_size + 1);
1059 else if (this_stack && !other_stack)
1061 ::memcpy(other.myStackBuffer, myStackBuffer, myLength + 1);
1062 myBuffer = other.myBuffer;
1063 other.myBuffer = other.myStackBuffer;
1065 else if (!this_stack && other_stack)
1067 ::memcpy(myStackBuffer, other.myStackBuffer, other.myLength + 1);
1068 other.myBuffer = myBuffer;
1069 myBuffer = myStackBuffer;
1072 UTswap(myBuffer, other.myBuffer);
1073 UTswap(myAllocatedSize, other.myAllocatedSize);
1074 UTswap(myLength, other.myLength);
1075 UTswap(myLockCount, other.myLockCount);
1080 const char *
begin()
const {
return myBuffer; }
1082 const char *
end()
const {
return myBuffer + myLength; }
1087 struct do_narrow {};
1104 template <
typename ListT,
bool ReportErrorsT = true>
1105 size_t appendFormatImpl(
const char *fmt, ListT
args);
1112 char *myBuffer = myStackBuffer;
1115 int myLockCount = 0;
1125 return buf.operator==(lit.
asRef());
1130 return buf.operator==(lit.
asRef());
1135 return buf.operator!=(lit.
asRef());
1140 return buf.operator!=(lit.
asRef());
1144 static inline size_t
1152 ::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)
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
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
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 const char * c_str() const
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
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
SYS_FORCE_INLINE UT_WorkBuffer()