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);
460 void fullyProtectedUtf8ToPythonStrcat(
const char *str);
470 append(src, ::strnlen(src, len));
476 void strcatFirstWord(
const char *
src);
482 return ::strcmp(myBuffer, src);
489 return ::strncmp(myBuffer, src, n);
496 return ::strdup(myBuffer);
503 if (myLockCount) {
UT_ASSERT(0);
return; }
511 return (myLength == 0);
526 if (offset < 0)
return;
527 if (offset >= myLength)
529 if (myLockCount) {
UT_ASSERT(0);
return; }
531 growBufferIfNeeded();
532 myBuffer[myLength] =
'\0';
553 write(offset, src.
c_str());
562 bool getline(std::istream &is);
563 bool getline(FILE *
fp);
572 const char *comment_chars =
"#",
573 const char *separators =
" \t\n\r");
575 const char *comment_chars =
"#",
576 const char *separators =
" \t\n\r");
578 const char *comment_chars =
"#",
579 const char *separators =
" \t\n\r");
589 int sprintf(
const char *fmt, ...)
591 int appendSprintf(const
char *fmt, ...)
593 int vsprintf(const
char *fmt, va_list ap);
598 template<typename... Args>
602 return appendFormat(fmt, {args...});
608 template<
typename... Args>
611 return appendFormat(fmt, {args...});
613 size_t appendFormat(
const char *fmt, std::initializer_list<UT::Format::ArgValue>
args);
617 size_t appendFormatByArray(
const char *fmt,
619 bool report_errors =
true);
625 if (myLockCount) {
UT_ASSERT(0);
return; }
628 growBufferIfNeeded();
629 myBuffer[myLength - 1] = character;
630 myBuffer[myLength] =
'\0';
634 void appendPrintMemory(
int64 mem);
638 if (myLockCount) {
UT_ASSERT(0);
return; }
641 growBufferIfNeeded();
642 std::fill(myBuffer+myLength-n, myBuffer+myLength, character);
643 myBuffer[myLength] =
'\0';
654 if (myLockCount) {
UT_ASSERT(0);
return; }
657 growBufferIfNeeded();
658 ::memcpy(myBuffer + myLength - len, buf, len);
659 myBuffer[myLength] =
'\0';
664 if (myLockCount) {
UT_ASSERT(0);
return; }
668 growBufferIfNeeded();
669 ::memcpy(myBuffer + myLength - size, data, size);
670 myBuffer[myLength] =
'\0';
677 append(str, ::strlen(str));
684 append((
const char *)str);
762 if (myLockCount) {
UT_ASSERT(0);
return; }
765 growBufferIfNeeded();
766 ::memmove(myBuffer+1, myBuffer, myLength);
767 myBuffer[0] = character;
771 if (myLockCount) {
UT_ASSERT(0);
return; }
775 growBufferIfNeeded();
776 ::memmove(myBuffer+size, myBuffer, myLength+1 - size);
777 ::memcpy(myBuffer, data, size);
783 prepend(str, ::strlen(str));
790 prepend((
const char *)str);
812 if (myLockCount) {
UT_ASSERT(0);
return; }
815 myLength -= by_length;
817 myBuffer[myLength] =
'\0';
825 if (new_length >= myLength)
830 &&
"Truncating beyond buffer extent");
833 backup(myLength-new_length);
840 if (myLockCount) {
UT_ASSERT(0);
return; }
842 while( myLength > 0 && myBuffer[myLength-1] != c )
844 myBuffer[myLength] =
'\0';
849 if (myLockCount) {
UT_ASSERT(0);
return; }
852 myLength -= by_length;
854 for (
int i=0; i<myLength; i++)
855 myBuffer[i] = myBuffer[by_length+i];
856 myBuffer[myLength] =
'\0';
861 const char *
findChar(
char c,
int occurance_number = 1)
const
863 return findCharFrom(c, 0, occurance_number);
866 const char *
lastChar(
char c,
int occurance_number = 1)
const
868 if (myLockCount) {
UT_ASSERT(0);
return NULL; }
872 for (
exint i = myLength; i --> 0;)
877 if(occurance_number <= 0)
879 return (myBuffer + i);
888 int occurance_number = 1)
const
890 if (myLockCount) {
UT_ASSERT(0);
return NULL; }
894 if (position < 0 || position >= myLength) {
return NULL; }
896 for(
exint i = position; i < myLength; ++i)
901 if(occurance_number <= 0)
903 return (myBuffer + i);
923 bool getNextToken(
const char *(&
string),
927 void copyIntoString(
UT_String &str)
const;
931 void copyIntoString(
char *str,
exint max_length)
const;
945 std::
string toStdString()
const
952 bool stripComments(
char comment_char =
'#');
957 int strip(
const char *chars);
960 void removeTrailingSpaceLines();
963 bool removeTrailingSpace();
966 bool removeLeadingSpace();
969 bool removeTrailingDigits();
978 void makeIndentString(
exint indent,
exint tabstop=8);
986 ::memmove(myBuffer, myBuffer + n, myLength);
991 myBuffer[myLength] =
'\0';
997 int substitute(
const char *
find,
const char *replacement,
int count = -1);
1001 int substitute(const
char *
find, const
char *replacement,
bool all)
1003 return substitute(find, replacement, !all ? 1 : -1);
1016 const char *to_pattern,
1017 const char *from_name,
1018 const char *from_pattern);
1026 void setFromUTF16(
const utf16 *str);
1031 void setAsUTF16(
const utf8 *str);
1048 bool this_stack = (myBuffer == myStackBuffer);
1049 bool other_stack = (other.myBuffer == other.myStackBuffer);
1051 if (this_stack && other_stack)
1055 size_t max_size = (myLength > other.myLength) ? myLength
1058 UTswap(myStackBuffer, other.myStackBuffer, max_size + 1);
1060 else if (this_stack && !other_stack)
1062 ::memcpy(other.myStackBuffer, myStackBuffer, myLength + 1);
1063 myBuffer = other.myBuffer;
1064 other.myBuffer = other.myStackBuffer;
1066 else if (!this_stack && other_stack)
1068 ::memcpy(myStackBuffer, other.myStackBuffer, other.myLength + 1);
1069 other.myBuffer = myBuffer;
1070 myBuffer = myStackBuffer;
1073 UTswap(myBuffer, other.myBuffer);
1074 UTswap(myAllocatedSize, other.myAllocatedSize);
1075 UTswap(myLength, other.myLength);
1076 UTswap(myLockCount, other.myLockCount);
1081 const char *
begin()
const {
return myBuffer; }
1083 const char *
end()
const {
return myBuffer + myLength; }
1088 struct do_narrow {};
1105 template <
typename ListT,
bool ReportErrorsT = true>
1106 size_t appendFormatImpl(
const char *fmt, ListT
args);
1113 char *myBuffer = myStackBuffer;
1116 int myLockCount = 0;
1126 return buf.operator==(lit.
asRef());
1131 return buf.operator==(lit.
asRef());
1136 return buf.operator!=(lit.
asRef());
1141 return buf.operator!=(lit.
asRef());
1145 static inline size_t
1153 ::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()