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; }
197 void release(
bool recompute_length =
false);
198 void releaseSetLength(
exint new_length);
202 int64 getMemoryUsage(
bool inclusive)
const;
215 myString = myBuffer.lock();
228 char *
string()
const {
return myString; }
237 myBuffer.release(recompute_length);
246 myString = myBuffer.lock();
265 return myBuffer[idx];
280 return myBuffer[myLength - 1];
284 int isNullTerminated()
const;
303 append(str.c_str(), str.length());
314 return (::strcmp(str, myBuffer) == 0);
319 if (!(
const char *)str)
321 return (::strcmp(str, myBuffer) == 0);
328 return (::memcmp(myBuffer, str.
c_str(), myLength) == 0);
337 return (::memcmp(myBuffer, buf.myBuffer, myLength) == 0);
342 return !(*
this == str);
347 return !(*
this == str);
352 return !(*
this == str);
357 return !(*
this ==
buf);
364 void growBufferIfNeeded()
370 while (myLength+1 > myAllocatedSize)
414 growBufferIfNeeded();
417 myLength = ::strlen(myBuffer);
425 return ::strlen(myBuffer);
443 void protectedStrcat(
const char *str,
bool force_quote=
false);
453 void fullyProtectedStrcat(
const char *str,
bool force_quote=
false);
454 void fullyProtectedBinaryStrcat(
455 const char *str,
exint size,
bool force_quote=
false);
465 append(src, ::strnlen(src, len));
471 void strcatFirstWord(
const char *
src);
477 return ::strcmp(myBuffer, src);
484 return ::strncmp(myBuffer, src, n);
491 return ::strdup(myBuffer);
498 if (myLockCount) {
UT_ASSERT(0);
return; }
506 return (myLength == 0);
521 if (offset < 0)
return;
522 if (offset >= myLength)
524 if (myLockCount) {
UT_ASSERT(0);
return; }
526 growBufferIfNeeded();
527 myBuffer[myLength] =
'\0';
548 write(offset, src.
c_str());
557 bool getline(std::istream &is);
558 bool getline(FILE *fp);
567 const char *comment_chars =
"#",
568 const char *separators =
" \t\n\r");
570 const char *comment_chars =
"#",
571 const char *separators =
" \t\n\r");
573 const char *comment_chars =
"#",
574 const char *separators =
" \t\n\r");
584 int sprintf(
const char *fmt, ...)
586 int appendSprintf(const
char *fmt, ...)
588 int vsprintf(const
char *fmt, va_list ap);
593 template<typename... Args>
597 return appendFormat(fmt, {args...});
603 template<
typename... Args>
606 return appendFormat(fmt, {args...});
608 size_t appendFormat(
const char *fmt, std::initializer_list<UT::Format::ArgValue>
args);
612 size_t appendFormatByArray(
const char *fmt,
614 bool report_errors =
true);
620 if (myLockCount) {
UT_ASSERT(0);
return; }
623 growBufferIfNeeded();
624 myBuffer[myLength - 1] = character;
625 myBuffer[myLength] =
'\0';
629 void appendPrintMemory(
int64 mem);
633 if (myLockCount) {
UT_ASSERT(0);
return; }
636 growBufferIfNeeded();
637 std::fill(myBuffer+myLength-n, myBuffer+myLength, character);
638 myBuffer[myLength] =
'\0';
649 if (myLockCount) {
UT_ASSERT(0);
return; }
652 growBufferIfNeeded();
653 ::memcpy(myBuffer + myLength - len, buf, len);
654 myBuffer[myLength] =
'\0';
659 if (myLockCount) {
UT_ASSERT(0);
return; }
663 growBufferIfNeeded();
664 ::memcpy(myBuffer + myLength - size, data, size);
665 myBuffer[myLength] =
'\0';
672 append(str, ::strlen(str));
679 append((
const char *)str);
757 if (myLockCount) {
UT_ASSERT(0);
return; }
760 growBufferIfNeeded();
761 ::memmove(myBuffer+1, myBuffer, myLength);
762 myBuffer[0] = character;
766 if (myLockCount) {
UT_ASSERT(0);
return; }
770 growBufferIfNeeded();
771 ::memmove(myBuffer+size, myBuffer, myLength+1 - size);
772 ::memcpy(myBuffer, data, size);
778 prepend(str, ::strlen(str));
785 prepend((
const char *)str);
807 if (myLockCount) {
UT_ASSERT(0);
return; }
810 myLength -= by_length;
812 myBuffer[myLength] =
'\0';
820 if (new_length >= myLength)
822 UT_ASSERT(0 &&
"Truncating beyond buffer extent");
825 backup(myLength-new_length);
832 if (myLockCount) {
UT_ASSERT(0);
return; }
834 while( myLength > 0 && myBuffer[myLength-1] != c )
836 myBuffer[myLength] =
'\0';
841 if (myLockCount) {
UT_ASSERT(0);
return; }
844 myLength -= by_length;
846 for (
int i=0; i<myLength; i++)
847 myBuffer[i] = myBuffer[by_length+i];
848 myBuffer[myLength] =
'\0';
853 const char *
findChar(
char c,
int occurance_number = 1)
const
855 return findCharFrom(c, 0, occurance_number);
858 const char *
lastChar(
char c,
int occurance_number = 1)
const
860 if (myLockCount) {
UT_ASSERT(0);
return NULL; }
864 for (
exint i = myLength; i --> 0;)
869 if(occurance_number <= 0)
871 return (myBuffer + i);
880 int occurance_number = 1)
const
882 if (myLockCount) {
UT_ASSERT(0);
return NULL; }
886 if (position < 0 || position >= myLength) {
return NULL; }
888 for(
exint i = position; i < myLength; ++i)
893 if(occurance_number <= 0)
895 return (myBuffer + i);
915 bool getNextToken(
const char *(&
string),
919 void copyIntoString(
UT_String &str)
const;
923 void copyIntoString(
char *str,
exint max_length)
const;
937 std::
string toStdString()
const
944 bool stripComments(
char comment_char =
'#');
949 int strip(
const char *chars);
952 void removeTrailingSpaceLines();
955 bool removeTrailingSpace();
958 bool removeLeadingSpace();
961 bool removeTrailingDigits();
970 void makeIndentString(
exint indent,
exint tabstop=8);
978 ::memmove(myBuffer, myBuffer + n, myLength);
983 myBuffer[myLength] =
'\0';
989 int substitute(
const char *
find,
const char *replacement,
int count = -1);
993 int substitute(const
char *
find, const
char *replacement,
bool all)
995 return substitute(find, replacement, !all ? 1 : -1);
1008 const char *to_pattern,
1009 const char *from_name,
1010 const char *from_pattern);
1018 void setFromUTF16(
const utf16 *str);
1023 void setAsUTF16(
const utf8 *str);
1040 bool this_stack = (myBuffer == myStackBuffer);
1041 bool other_stack = (other.myBuffer == other.myStackBuffer);
1043 if (this_stack && other_stack)
1047 size_t max_size = (myLength > other.myLength) ? myLength
1050 UTswap(myStackBuffer, other.myStackBuffer, max_size + 1);
1052 else if (this_stack && !other_stack)
1054 ::memcpy(other.myStackBuffer, myStackBuffer, myLength + 1);
1055 myBuffer = other.myBuffer;
1056 other.myBuffer = other.myStackBuffer;
1058 else if (!this_stack && other_stack)
1060 ::memcpy(myStackBuffer, other.myStackBuffer, other.myLength + 1);
1061 other.myBuffer = myBuffer;
1062 myBuffer = myStackBuffer;
1065 UTswap(myBuffer, other.myBuffer);
1066 UTswap(myAllocatedSize, other.myAllocatedSize);
1067 UTswap(myLength, other.myLength);
1068 UTswap(myLockCount, other.myLockCount);
1073 const char *
begin()
const {
return myBuffer; }
1075 const char *
end()
const {
return myBuffer + myLength; }
1080 struct do_narrow {};
1097 template <
typename ListT,
bool ReportErrorsT = true>
1098 size_t appendFormatImpl(
const char *fmt, ListT
args);
1105 char *myBuffer = myStackBuffer;
1108 int myLockCount = 0;
1118 return buf.operator==(lit.
asRef());
1123 return buf.operator==(lit.
asRef());
1128 return buf.operator!=(lit.
asRef());
1133 return buf.operator!=(lit.
asRef());
1137 static inline size_t
1145 ::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
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()