diff options
Diffstat (limited to 'src/Libraries')
-rw-r--r-- | src/Libraries/General/StringRef.cpp | 11 | ||||
-rw-r--r-- | src/Libraries/General/StringRef.h | 3 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/Libraries/General/StringRef.cpp b/src/Libraries/General/StringRef.cpp index a05e6070..7b0840c1 100644 --- a/src/Libraries/General/StringRef.cpp +++ b/src/Libraries/General/StringRef.cpp @@ -8,6 +8,7 @@ #include "StringRef.h" #include <cstring> #include <cstdio> +#include "WMath.h" // Need to define strnlen here because it isn't ISO standard size_t strnlen(const char *s, size_t n) @@ -110,6 +111,16 @@ size_t StringRef::StripTrailingSpaces() const return slen; } +size_t StringRef::Prepend(const char *src) const +{ + const size_t slen = ::strlen(src); + const size_t dlen = strlen(); + const size_t newLen = min<size_t>(dlen + slen, len - 1); + memmove(p + slen, p, newLen - slen + 1); + memcpy(p, src, slen); + return newLen; +} + // End diff --git a/src/Libraries/General/StringRef.h b/src/Libraries/General/StringRef.h index 9660389a..09ddaa24 100644 --- a/src/Libraries/General/StringRef.h +++ b/src/Libraries/General/StringRef.h @@ -33,7 +33,7 @@ public: void Clear() const { p[0] = 0; } - int printf(const char *fmt, ...) const __attribute__ ((format (printf, 2, 3))); + int printf(const char *fmt, ...) const __attribute__ ((format (printf, 2, 3))); int vprintf(const char *fmt, va_list vargs) const; int catf(const char *fmt, ...) const __attribute__ ((format (printf, 2, 3))); int vcatf(const char *fmt, va_list vargs) const; @@ -41,6 +41,7 @@ public: size_t cat(const char *src) const; size_t cat(char c) const; size_t StripTrailingSpaces() const; + size_t Prepend(const char *src) const; bool IsEmpty() const { return p[0] == 0; } }; |