summaryrefslogtreecommitdiff
path: root/source/core
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-04-25 12:25:52 -0400
committerGitHub <noreply@github.com>2023-04-25 09:25:52 -0700
commit5abee6a0a30c7c965138ec7286b7f1b21b201731 (patch)
tree0469f6f85bac0fcf502a95f2a60c49179349dd17 /source/core
parente5d5e3c215f3300bf447e6ab46cdf8d5c12f58a6 (diff)
StringBuilder to lowerCamel (#2840)
* #include an absolute path didn't work - because paths were taken to always be relative. * WIP lowerCamel Dictionary. * WIP more lowerCamel fixes for Dictionary. * Add/Remove/Clear * GetValue/Contains * Fix tabs in dictionary. Count -> getCount * Fix fields with caps. * Key -> key Value -> value Use m_ for members where appropriate. Use lowerCamel in linked list. * Some small fixes/improvements to Dictionary. * Kick CI. * Small tidy on String. * Append -> append * ToString -> toString ProduceString -> produceString * Small fixes. * StringToXXX -> stringToXXX * Fix typo introduced by Append -> append. * Made intToAscii do reversal at the end. --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/core')
-rw-r--r--source/core/slang-command-line.cpp8
-rw-r--r--source/core/slang-hex-dump-util.cpp4
-rw-r--r--source/core/slang-implicit-directory-collector.cpp2
-rw-r--r--source/core/slang-io.cpp23
-rw-r--r--source/core/slang-platform.cpp26
-rw-r--r--source/core/slang-process-util.cpp2
-rw-r--r--source/core/slang-signal.cpp2
-rw-r--r--source/core/slang-string.cpp33
-rw-r--r--source/core/slang-string.h259
-rw-r--r--source/core/slang-text-io.cpp6
-rw-r--r--source/core/slang-token-reader.cpp54
-rw-r--r--source/core/slang-token-reader.h16
-rw-r--r--source/core/slang-writer.cpp2
13 files changed, 169 insertions, 268 deletions
diff --git a/source/core/slang-command-line.cpp b/source/core/slang-command-line.cpp
index 59e6a6265..475270d69 100644
--- a/source/core/slang-command-line.cpp
+++ b/source/core/slang-command-line.cpp
@@ -43,7 +43,7 @@ void ExecutableLocation::set(const String& nameOrPath)
StringBuilder builder;
builder << nameOrPath;
builder << suffix;
- setPath(builder.ProduceString());
+ setPath(builder.produceString());
}
}
else
@@ -86,7 +86,7 @@ void CommandLine::addPrefixPathArg(const char* prefix, const String& path, const
// Work out the path with the postfix
builder << pathPostfix;
}
- addArg(builder.ProduceString());
+ addArg(builder.produceString());
}
void CommandLine::append(StringBuilder& out) const
@@ -128,14 +128,14 @@ String CommandLine::toString() const
{
StringBuilder buf;
append(buf);
- return buf.ProduceString();
+ return buf.produceString();
}
String CommandLine::toStringArgs() const
{
StringBuilder buf;
appendArgs(buf);
- return buf.ProduceString();
+ return buf.produceString();
}
} // namespace Slang
diff --git a/source/core/slang-hex-dump-util.cpp b/source/core/slang-hex-dump-util.cpp
index 1279dc237..bbee0a199 100644
--- a/source/core/slang-hex-dump-util.cpp
+++ b/source/core/slang-hex-dump-util.cpp
@@ -227,8 +227,8 @@ static SlangResult _findLine(const UnownedStringSlice& find, UnownedStringSlice&
return SLANG_FAIL;
}
// Extract the size
- size = StringToInt(String(slices[1]));
- hash = HashCode32(StringToInt(String(slices[2])));
+ size = stringToInt(String(slices[1]));
+ hash = HashCode32(stringToInt(String(slices[2])));
}
SLANG_RETURN_ON_FAIL(parse(UnownedStringSlice(startLine.end(), endLine.begin()), outBytes));
diff --git a/source/core/slang-implicit-directory-collector.cpp b/source/core/slang-implicit-directory-collector.cpp
index 169deeb30..d116ed8f9 100644
--- a/source/core/slang-implicit-directory-collector.cpp
+++ b/source/core/slang-implicit-directory-collector.cpp
@@ -15,7 +15,7 @@ ImplicitDirectoryCollector::ImplicitDirectoryCollector(const String& canonicalPa
StringBuilder buffer;
buffer << canonicalPath;
buffer.append('/');
- m_prefix = buffer.ProduceString();
+ m_prefix = buffer.produceString();
}
}
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp
index 50e98c60c..52187bd47 100644
--- a/source/core/slang-io.cpp
+++ b/source/core/slang-io.cpp
@@ -189,10 +189,10 @@ namespace Slang
if (dotPos < 0)
dotPos = path.getLength();
- sb.Append(path.getBuffer(), dotPos);
- sb.Append('.');
- sb.Append(newExt);
- return sb.ProduceString();
+ sb.append(path.getBuffer(), dotPos);
+ sb.append('.');
+ sb.append(newExt);
+ return sb.produceString();
}
/* static */ Index Path::findLastSeparatorIndex(UnownedStringSlice const& path)
@@ -325,7 +325,7 @@ namespace Slang
/* static */void Path::combineIntoBuilder(const UnownedStringSlice& path1, const UnownedStringSlice& path2, StringBuilder& outBuilder)
{
outBuilder.clear();
- outBuilder.Append(path1);
+ outBuilder.append(path1);
append(outBuilder, path2);
}
@@ -338,7 +338,7 @@ namespace Slang
StringBuilder sb;
combineIntoBuilder(path1.getUnownedSlice(), path2.getUnownedSlice(), sb);
- return sb.ProduceString();
+ return sb.produceString();
}
String Path::combine(const String& path1, const String& path2, const String& path3)
{
@@ -346,7 +346,7 @@ namespace Slang
sb.append(path1);
append(sb, path2.getUnownedSlice());
append(sb, path3.getUnownedSlice());
- return sb.ProduceString();
+ return sb.produceString();
}
/* static */ bool Path::isDriveSpecification(const UnownedStringSlice& element)
@@ -546,7 +546,7 @@ namespace Slang
// Reconstruct the string
StringBuilder builder;
join(splitPath.getBuffer(), splitPath.getCount(), builder);
- return builder.ToString();
+ return builder.toString();
}
bool Path::createDirectory(const String& path)
@@ -1059,7 +1059,7 @@ namespace Slang
i++;
}
}
- return sb.ProduceString();
+ return sb.produceString();
}
StringSlice URI::getProtocol() const
@@ -1099,9 +1099,8 @@ namespace Slang
else
{
char buffer[32];
- int length = IntToAscii(buffer, (int)ch, 16);
- ReverseInternalAscii(buffer, length);
- sb << "%" << buffer;
+ int length = intToAscii(buffer, (int)ch, 16);
+ sb << "%" << UnownedStringSlice(buffer, length);
}
}
return URI::fromString(sb.getUnownedSlice());
diff --git a/source/core/slang-platform.cpp b/source/core/slang-platform.cpp
index f28a25f7f..e5af0ba7e 100644
--- a/source/core/slang-platform.cpp
+++ b/source/core/slang-platform.cpp
@@ -49,7 +49,7 @@ namespace Slang
{
StringBuilder builder;
calcPlatformPath(path, builder);
- return builder.ToString();
+ return builder.toString();
}
#ifdef _WIN32
@@ -92,7 +92,7 @@ SLANG_COMPILE_TIME_ASSERT(E_OUTOFMEMORY == SLANG_E_OUT_OF_MEMORY);
{
builderOut << " ";
// Convert to string
- builderOut.Append(String::fromWString(buffer));
+ builderOut.append(String::fromWString(buffer));
LocalFree(buffer);
return SLANG_OK;
}
@@ -152,8 +152,8 @@ SLANG_COMPILE_TIME_ASSERT(E_OUTOFMEMORY == SLANG_E_OUT_OF_MEMORY);
/* static */void SharedLibrary::appendPlatformFileName(const UnownedStringSlice& name, StringBuilder& dst)
{
- dst.Append(name);
- dst.Append(".dll");
+ dst.append(name);
+ dst.append(".dll");
}
#else // _WIN32
@@ -221,21 +221,21 @@ SLANG_COMPILE_TIME_ASSERT(E_OUTOFMEMORY == SLANG_E_OUT_OF_MEMORY);
/* static */void SharedLibrary::appendPlatformFileName(const UnownedStringSlice& name, StringBuilder& dst)
{
#if __CYGWIN__
- dst.Append(name);
- dst.Append(".dll");
+ dst.append(name);
+ dst.append(".dll");
#elif SLANG_APPLE_FAMILY
- dst.Append("lib");
- dst.Append(name);
- dst.Append(".dylib");
+ dst.append("lib");
+ dst.append(name);
+ dst.append(".dylib");
#elif SLANG_LINUX_FAMILY
if (!name.startsWith("lib"))
- dst.Append("lib");
- dst.Append(name);
+ dst.append("lib");
+ dst.append(name);
if (name.indexOf(UnownedStringSlice(".so.")) == -1)
- dst.Append(".so");
+ dst.append(".so");
#else
// Just guess we can do with the name on it's own
- dst.Append(name);
+ dst.append(name);
#endif
}
diff --git a/source/core/slang-process-util.cpp b/source/core/slang-process-util.cpp
index 1a160b00b..ef22c0392 100644
--- a/source/core/slang-process-util.cpp
+++ b/source/core/slang-process-util.cpp
@@ -28,7 +28,7 @@ static String _getText(const ConstArrayView<Byte>& bytes)
{
StringBuilder buf;
StringUtil::appendStandardLines(UnownedStringSlice((const char*)bytes.begin(), (const char*)bytes.end()), buf);
- return buf.ProduceString();
+ return buf.produceString();
}
/* static */SlangResult ProcessUtil::readUntilTermination(Process* process, ExecuteResult& outExecuteResult)
diff --git a/source/core/slang-signal.cpp b/source/core/slang-signal.cpp
index 9641fe5f7..cdf2a1179 100644
--- a/source/core/slang-signal.cpp
+++ b/source/core/slang-signal.cpp
@@ -31,7 +31,7 @@ String _getMessage(SignalType type, char const* message)
buf << ": " << message;
}
- return buf.ProduceString();
+ return buf.produceString();
}
// One point of having as a single function is a choke point both for handling (allowing different
diff --git a/source/core/slang-string.cpp b/source/core/slang-string.cpp
index dc3c3ed46..0cb034604 100644
--- a/source/core/slang-string.cpp
+++ b/source/core/slang-string.cpp
@@ -261,25 +261,25 @@ namespace Slang
return result;
}
- int StringToInt(const String & str, int radix)
+ int stringToInt(const String& str, int radix)
{
if (str.startsWith("0x"))
return (int)strtoll(str.getBuffer(), NULL, 16);
else
return (int)strtoll(str.getBuffer(), NULL, radix);
}
- unsigned int StringToUInt(const String & str, int radix)
+ unsigned int stringToUInt(const String& str, int radix)
{
if (str.startsWith("0x"))
return (unsigned int)strtoull(str.getBuffer(), NULL, 16);
else
return (unsigned int)strtoull(str.getBuffer(), NULL, radix);
}
- double StringToDouble(const String & str)
+ double stringToDouble(const String& str)
{
return (double)strtod(str.getBuffer(), NULL);
}
- float StringToFloat(const String & str)
+ float stringToFloat(const String& str)
{
return strtof(str.getBuffer(), NULL);
}
@@ -300,7 +300,7 @@ namespace Slang
}
#endif
- String String::fromWString(const wchar_t * wstr)
+ String String::fromWString(const wchar_t* wstr)
{
List<char> buf;
#ifdef _WIN32
@@ -311,7 +311,7 @@ namespace Slang
return String(buf.begin(), buf.end());
}
- String String::fromWString(const wchar_t * wstr, const wchar_t * wend)
+ String String::fromWString(const wchar_t* wstr, const wchar_t* wend)
{
List<char> buf;
#ifdef _WIN32
@@ -481,6 +481,11 @@ namespace Slang
}
}
+ void String::append(char const* str, size_t len)
+ {
+ append(str, str + len);
+ }
+
void String::append(const char* textBegin, char const* textEnd)
{
auto oldLength = getLength();
@@ -563,8 +568,7 @@ namespace Slang
{
enum { kCount = 33 };
char* data = prepareForAppend(kCount);
- auto count = IntToAscii(data, value, radix);
- ReverseInternalAscii(data, count);
+ const auto count = intToAscii(data, value, radix);
m_buffer->length += count;
}
@@ -572,8 +576,7 @@ namespace Slang
{
enum { kCount = 33 };
char* data = prepareForAppend(kCount);
- auto count = IntToAscii(data, value, radix);
- ReverseInternalAscii(data, count);
+ const auto count = intToAscii(data, value, radix);
m_buffer->length += count;
}
@@ -581,8 +584,7 @@ namespace Slang
{
enum { kCount = 65 };
char* data = prepareForAppend(kCount);
- auto count = IntToAscii(data, value, radix);
- ReverseInternalAscii(data, count);
+ auto count = intToAscii(data, value, radix);
m_buffer->length += count;
}
@@ -590,12 +592,11 @@ namespace Slang
{
enum { kCount = 65 };
char* data = prepareForAppend(kCount);
- auto count = IntToAscii(data, value, radix);
- ReverseInternalAscii(data, count);
+ auto count = intToAscii(data, value, radix);
m_buffer->length += count;
}
- void String::append(float val, const char * format)
+ void String::append(float val, const char* format)
{
enum { kCount = 128 };
char* data = prepareForAppend(kCount);
@@ -603,7 +604,7 @@ namespace Slang
m_buffer->length += strnlen_s(data, kCount);
}
- void String::append(double val, const char * format)
+ void String::append(double val, const char* format)
{
enum { kCount = 128 };
char* data = prepareForAppend(kCount);
diff --git a/source/core/slang-string.h b/source/core/slang-string.h
index 533d30827..4c78cc32e 100644
--- a/source/core/slang-string.h
+++ b/source/core/slang-string.h
@@ -20,7 +20,7 @@ namespace Slang
extern _EndLine EndLine;
// in-place reversion, works only for ascii string
- inline void ReverseInternalAscii(char * buffer, int length)
+ inline void reverseInplaceAscii(char* buffer, int length)
{
int i, j;
char c;
@@ -32,13 +32,17 @@ namespace Slang
}
}
template<typename IntType>
- inline int IntToAscii(char * buffer, IntType val, int radix)
+ inline int intToAscii(char* buffer, IntType val, int radix)
{
int i = 0;
IntType sign;
+
sign = val;
if (sign < 0)
+ {
val = (IntType)(0 - val);
+ }
+
do
{
int digit = (val % radix);
@@ -47,18 +51,23 @@ namespace Slang
else
buffer[i++] = (char)(digit - 10 + 'A');
} while ((val /= radix) > 0);
+
if (sign < 0)
buffer[i++] = '-';
+
+ // Put in normal character order
+ reverseInplaceAscii(buffer, i);
+
buffer[i] = '\0';
return i;
}
- inline bool IsUtf8LeadingByte(char ch)
+ SLANG_FORCE_INLINE bool isUtf8LeadingByte(char ch)
{
return (((unsigned char)ch) & 0xC0) == 0xC0;
}
- inline bool IsUtf8ContinuationByte(char ch)
+ SLANG_FORCE_INLINE bool isUtf8ContinuationByte(char ch)
{
return (((unsigned char)ch) & 0xC0) == 0x80;
}
@@ -451,10 +460,11 @@ namespace Slang
: m_buffer(buffer)
{}
- static String fromWString(const wchar_t * wstr);
- static String fromWString(const wchar_t * wstr, const wchar_t * wend);
+ static String fromWString(const wchar_t* wstr);
+ static String fromWString(const wchar_t* wstr, const wchar_t* wend);
static String fromWChar(const wchar_t ch);
static String fromUnicodePoint(Char32 codePoint);
+
String()
{
}
@@ -466,11 +476,11 @@ namespace Slang
SLANG_FORCE_INLINE StringRepresentation* getStringRepresentation() const { return m_buffer; }
- const char * begin() const
+ const char* begin() const
{
return getData();
}
- const char * end() const
+ const char* end() const
{
return getData() + getLength();
}
@@ -479,10 +489,11 @@ namespace Slang
void append(uint32_t value, int radix = 10);
void append(int64_t value, int radix = 10);
void append(uint64_t value, int radix = 10);
- void append(float val, const char * format = "%g");
- void append(double val, const char * format = "%g");
+ void append(float val, const char* format = "%g");
+ void append(double val, const char* format = "%g");
void append(char const* str);
+ void append(char const* str, size_t len);
void append(const char* textBegin, char const* textEnd);
void append(char chr);
void append(String const& str);
@@ -498,25 +509,11 @@ namespace Slang
String(const char* str)
{
append(str);
-#if 0
- if (str)
- {
- buffer = StringRepresentation::createWithLength(strlen(str));
- memcpy(buffer.Ptr(), str, getLength() + 1);
- }
-#endif
+
}
String(const char* textBegin, char const* textEnd)
{
append(textBegin, textEnd);
-#if 0
- if (textBegin != textEnd)
- {
- buffer = StringRepresentation::createWithLength(textEnd - textBegin);
- memcpy(buffer.Ptr(), textBegin, getLength());
- buffer->getData()[getLength()] = 0;
- }
-#endif
}
// Make all String ctors from a numeric explicit, to avoid unexpected/unnecessary conversions
@@ -536,33 +533,22 @@ namespace Slang
{
append(val, radix);
}
- explicit String(float val, const char * format = "%g")
+ explicit String(float val, const char* format = "%g")
{
append(val, format);
}
- explicit String(double val, const char * format = "%g")
+ explicit String(double val, const char* format = "%g")
{
append(val, format);
}
explicit String(char chr)
{
- append(chr);
-#if 0
- if (chr)
- {
- buffer = StringRepresentation::createWithLength(1);
- buffer->getData()[0] = chr;
- buffer->getData()[1] = 0;
- }
-#endif
+ appendChar(chr);
}
String(String const& str)
{
m_buffer = str.m_buffer;
-#if 0
- this->operator=(str);
-#endif
}
String(String&& other)
{
@@ -584,12 +570,12 @@ namespace Slang
m_buffer.setNull();
}
- String & operator=(const String & str)
+ String& operator=(const String& str)
{
m_buffer = str.m_buffer;
return *this;
}
- String & operator=(String&& other)
+ String& operator=(String&& other)
{
m_buffer = _Move(other.m_buffer);
return *this;
@@ -678,7 +664,7 @@ namespace Slang
OSString toWString(Index* len = 0) const;
- bool equals(const String & str, bool caseSensitive = true)
+ bool equals(const String& str, bool caseSensitive = true)
{
if (caseSensitive)
return (strcmp(begin(), str.begin()) == 0);
@@ -691,36 +677,36 @@ namespace Slang
#endif
}
}
- bool operator==(const char * strbuffer) const
+ bool operator==(const char* strbuffer) const
{
return (strcmp(begin(), strbuffer) == 0);
}
- bool operator==(const String & str) const
+ bool operator==(const String& str) const
{
return (strcmp(begin(), str.begin()) == 0);
}
- bool operator!=(const char * strbuffer) const
+ bool operator!=(const char* strbuffer) const
{
return (strcmp(begin(), strbuffer) != 0);
}
- bool operator!=(const String & str) const
+ bool operator!=(const String& str) const
{
return (strcmp(begin(), str.begin()) != 0);
}
- bool operator>(const String & str) const
+ bool operator>(const String& str) const
{
return (strcmp(begin(), str.begin()) > 0);
}
- bool operator<(const String & str) const
+ bool operator<(const String& str) const
{
return (strcmp(begin(), str.begin()) < 0);
}
- bool operator>=(const String & str) const
+ bool operator>=(const String& str) const
{
return (strcmp(begin(), str.begin()) >= 0);
}
- bool operator<=(const String & str) const
+ bool operator<=(const String& str) const
{
return (strcmp(begin(), str.begin()) <= 0);
}
@@ -750,7 +736,7 @@ namespace Slang
return result;
}
- Index indexOf(const char * str, Index id) const // String str
+ Index indexOf(const char* str, Index id) const // String str
{
if (id >= getLength())
return Index(-1);
@@ -759,17 +745,17 @@ namespace Slang
return res;
}
- Index indexOf(const String & str, Index id) const
+ Index indexOf(const String& str, Index id) const
{
return indexOf(str.begin(), id);
}
- Index indexOf(const char * str) const
+ Index indexOf(const char* str) const
{
return indexOf(str, 0);
}
- Index indexOf(const String & str) const
+ Index indexOf(const String& str) const
{
return indexOf(str.begin(), 0);
}
@@ -804,15 +790,13 @@ namespace Slang
const Index length = getLength();
const char* data = getData();
- // TODO(JS): If we know Index is signed we can do this a bit more simply
-
- for (Index i = length; i > 0; i--)
- if (data[i - 1] == ch)
- return i - 1;
+ for (Index i = length - 1; i >= 0; --i)
+ if (data[i] == ch)
+ return i;
return Index(-1);
}
- bool startsWith(const char * str) const // String str
+ bool startsWith(const char* str) const
{
if (!m_buffer)
return false;
@@ -833,7 +817,7 @@ namespace Slang
return startsWith(str.begin());
}
- bool endsWith(char const * str) const // String str
+ bool endsWith(char const* str) const // String str
{
if (!m_buffer)
return false;
@@ -850,17 +834,17 @@ namespace Slang
return true;
}
- bool endsWith(const String & str) const
+ bool endsWith(const String& str) const
{
return endsWith(str.begin());
}
- bool contains(const char * str) const // String str
+ bool contains(const char* str) const // String str
{
return m_buffer && indexOf(str) != Index(-1);
}
- bool contains(const String & str) const
+ bool contains(const String& str) const
{
return contains(str.begin());
}
@@ -881,168 +865,85 @@ namespace Slang
private:
enum { InitialSize = 1024 };
public:
+ typedef String Super;
+ using Super::append;
+
explicit StringBuilder(UInt bufferSize = InitialSize)
{
ensureUniqueStorageWithCapacity(bufferSize);
}
- void EnsureCapacity(UInt size)
+
+ void ensureCapacity(UInt size)
{
ensureUniqueStorageWithCapacity(size);
}
- StringBuilder & operator << (char ch)
+ StringBuilder& operator << (char ch)
{
- Append(&ch, 1);
+ appendChar(ch);
return *this;
}
- StringBuilder & operator << (Int32 val)
+ StringBuilder& operator << (Int32 val)
{
- Append(val);
+ append(val);
return *this;
}
- StringBuilder & operator << (UInt32 val)
+ StringBuilder& operator << (UInt32 val)
{
- Append(val);
+ append(val);
return *this;
}
- StringBuilder & operator << (Int64 val)
+ StringBuilder& operator << (Int64 val)
{
- Append(val);
+ append(val);
return *this;
}
- StringBuilder & operator << (UInt64 val)
+ StringBuilder& operator << (UInt64 val)
{
- Append(val);
+ append(val);
return *this;
}
- StringBuilder & operator << (float val)
+ StringBuilder& operator << (float val)
{
- Append(val);
+ append(val);
return *this;
}
- StringBuilder & operator << (double val)
+ StringBuilder& operator << (double val)
{
- Append(val);
+ append(val);
return *this;
}
- StringBuilder & operator << (const char * str)
+ StringBuilder& operator << (const char* str)
{
- Append(str, strlen(str));
+ append(str, strlen(str));
return *this;
}
- StringBuilder & operator << (const String & str)
+ StringBuilder& operator << (const String& str)
{
- Append(str);
+ append(str);
return *this;
}
- StringBuilder & operator << (UnownedStringSlice const& str)
+ StringBuilder& operator << (UnownedStringSlice const& str)
{
append(str);
return *this;
}
- StringBuilder & operator << (const _EndLine)
+ StringBuilder& operator << (const _EndLine)
{
- Append('\n');
+ appendChar('\n');
return *this;
}
- void Append(char ch)
- {
- Append(&ch, 1);
- }
- void Append(float val)
- {
- char buf[128];
- sprintf_s(buf, 128, "%g", val);
- int len = (int)strnlen_s(buf, 128);
- Append(buf, len);
- }
- void Append(double val)
- {
- char buf[128];
- sprintf_s(buf, 128, "%g", val);
- int len = (int)strnlen_s(buf, 128);
- Append(buf, len);
- }
- void Append(Int32 value, int radix = 10)
- {
- char vBuffer[33];
- int len = IntToAscii(vBuffer, value, radix);
- ReverseInternalAscii(vBuffer, len);
- Append(vBuffer);
- }
- void Append(UInt32 value, int radix = 10)
- {
- char vBuffer[33];
- int len = IntToAscii(vBuffer, value, radix);
- ReverseInternalAscii(vBuffer, len);
- Append(vBuffer);
- }
- void Append(Int64 value, int radix = 10)
- {
- char vBuffer[65];
- int len = IntToAscii(vBuffer, value, radix);
- ReverseInternalAscii(vBuffer, len);
- Append(vBuffer);
- }
- void Append(UInt64 value, int radix = 10)
- {
- char vBuffer[65];
- int len = IntToAscii(vBuffer, value, radix);
- ReverseInternalAscii(vBuffer, len);
- Append(vBuffer);
- }
- void Append(const String & str)
- {
- Append(str.getBuffer(), str.getLength());
- }
- void Append(const char * str)
- {
- Append(str, strlen(str));
- }
- void Append(const char * str, UInt strLen)
- {
- append(str, str + strLen);
- }
-#if 0
- int Capacity()
- {
- return bufferSize;
- }
-
- char * Buffer()
- {
- return buffer;
- }
-
- int Length()
- {
- return length;
- }
-#endif
-
- String ToString()
+ String toString()
{
return *this;
}
- String ProduceString()
+ String produceString()
{
return *this;
}
#if 0
- String GetSubString(int start, int count)
- {
- String rs;
- rs.buffer = new char[count + 1];
- rs.length = count;
- strncpy_s(rs.buffer.Ptr(), count + 1, buffer + start, count);
- rs.buffer[count] = 0;
- return rs;
- }
-#endif
-
-#if 0
void Remove(int id, int len)
{
#if _DEBUG
@@ -1065,10 +966,10 @@ namespace Slang
}
};
- int StringToInt(const String & str, int radix = 10);
- unsigned int StringToUInt(const String & str, int radix = 10);
- double StringToDouble(const String & str);
- float StringToFloat(const String & str);
+ int stringToInt(const String& str, int radix = 10);
+ unsigned int stringToUInt(const String& str, int radix = 10);
+ double stringToDouble(const String& str);
+ float stringToFloat(const String& str);
}
std::ostream& operator<< (std::ostream& stream, const Slang::String& s);
diff --git a/source/core/slang-text-io.cpp b/source/core/slang-text-io.cpp
index 3f5d739d9..327ef55de 100644
--- a/source/core/slang-text-io.cpp
+++ b/source/core/slang-text-io.cpp
@@ -148,15 +148,15 @@ SlangResult StreamReader::readToEnd(String& outString)
break;
if (ch == '\r')
{
- sb.Append('\n');
+ sb.append('\n');
if (peek() == '\n')
read();
}
else
- sb.Append(ch);
+ sb.append(ch);
}
- outString = sb.ProduceString();
+ outString = sb.produceString();
return SLANG_OK;
}
diff --git a/source/core/slang-token-reader.cpp b/source/core/slang-token-reader.cpp
index be2461796..f6f29def3 100644
--- a/source/core/slang-token-reader.cpp
+++ b/source/core/slang-token-reader.cpp
@@ -336,7 +336,7 @@ namespace Misc {
auto InsertToken = [&](TokenType type)
{
derivative = LexDerivative::None;
- tokenList.add(Token(type, tokenBuilder.ToString(), tokenLine, tokenCol, int(pos), file, tokenFlags));
+ tokenList.add(Token(type, tokenBuilder.toString(), tokenLine, tokenCol, int(pos), file, tokenFlags));
tokenFlags = 0;
tokenBuilder.clear();
};
@@ -347,22 +347,22 @@ namespace Misc {
case '\\':
case '\"':
case '\'':
- tokenBuilder.Append(nextChar);
+ tokenBuilder.append(nextChar);
break;
case 't':
- tokenBuilder.Append('\t');
+ tokenBuilder.append('\t');
break;
case 's':
- tokenBuilder.Append(' ');
+ tokenBuilder.append(' ');
break;
case 'n':
- tokenBuilder.Append('\n');
+ tokenBuilder.append('\n');
break;
case 'r':
- tokenBuilder.Append('\r');
+ tokenBuilder.append('\r');
break;
case 'b':
- tokenBuilder.Append('\b');
+ tokenBuilder.append('\b');
break;
}
};
@@ -433,7 +433,7 @@ namespace Misc {
}
else if (curChar == '.' && IsDigit(nextChar))
{
- tokenBuilder.Append("0.");
+ tokenBuilder.append("0.");
state = State::Fixed;
pos++;
}
@@ -451,12 +451,12 @@ namespace Misc {
case State::Identifier:
if (IsLetter(curChar) || IsDigit(curChar))
{
- tokenBuilder.Append(curChar);
+ tokenBuilder.append(curChar);
pos++;
}
else
{
- auto tokenStr = tokenBuilder.ToString();
+ auto tokenStr = tokenBuilder.toString();
#if 0
if (tokenStr == "#line_reset#")
{
@@ -485,13 +485,13 @@ namespace Misc {
case State::Operator:
if (IsPunctuation(curChar) && !((curChar == '/' && nextChar == '/') || (curChar == '/' && nextChar == '*')))
{
- tokenBuilder.Append(curChar);
+ tokenBuilder.append(curChar);
pos++;
}
else
{
//do token analyze
- ParseOperators(tokenBuilder.ToString(), tokenList, tokenFlags, tokenLine, tokenCol, (int)(pos - tokenBuilder.getLength()), file);
+ ParseOperators(tokenBuilder.toString(), tokenList, tokenFlags, tokenLine, tokenCol, (int)(pos - tokenBuilder.getLength()), file);
tokenBuilder.clear();
state = State::Start;
}
@@ -499,22 +499,22 @@ namespace Misc {
case State::Int:
if (IsDigit(curChar))
{
- tokenBuilder.Append(curChar);
+ tokenBuilder.append(curChar);
pos++;
}
else if (curChar == '.')
{
state = State::Fixed;
- tokenBuilder.Append(curChar);
+ tokenBuilder.append(curChar);
pos++;
}
else if (curChar == 'e' || curChar == 'E')
{
state = State::Double;
- tokenBuilder.Append(curChar);
+ tokenBuilder.append(curChar);
if (nextChar == '-' || nextChar == '+')
{
- tokenBuilder.Append(nextChar);
+ tokenBuilder.append(nextChar);
pos++;
}
pos++;
@@ -522,13 +522,13 @@ namespace Misc {
else if (curChar == 'x')
{
state = State::Hex;
- tokenBuilder.Append(curChar);
+ tokenBuilder.append(curChar);
pos++;
}
else if (curChar == 'u')
{
pos++;
- tokenBuilder.Append(curChar);
+ tokenBuilder.append(curChar);
InsertToken(TokenType::IntLiteral);
state = State::Start;
}
@@ -537,7 +537,7 @@ namespace Misc {
if (derivative == LexDerivative::Line)
{
derivative = LexDerivative::None;
- line = StringToInt(tokenBuilder.ToString()) - 1;
+ line = stringToInt(tokenBuilder.toString()) - 1;
col = 0;
tokenBuilder.clear();
}
@@ -551,7 +551,7 @@ namespace Misc {
case State::Hex:
if (IsDigit(curChar) || (curChar >= 'a' && curChar <= 'f') || (curChar >= 'A' && curChar <= 'F'))
{
- tokenBuilder.Append(curChar);
+ tokenBuilder.append(curChar);
pos++;
}
else
@@ -563,16 +563,16 @@ namespace Misc {
case State::Fixed:
if (IsDigit(curChar))
{
- tokenBuilder.Append(curChar);
+ tokenBuilder.append(curChar);
pos++;
}
else if (curChar == 'e' || curChar == 'E')
{
state = State::Double;
- tokenBuilder.Append(curChar);
+ tokenBuilder.append(curChar);
if (nextChar == '-' || nextChar == '+')
{
- tokenBuilder.Append(nextChar);
+ tokenBuilder.append(nextChar);
pos++;
}
pos++;
@@ -588,7 +588,7 @@ namespace Misc {
case State::Double:
if (IsDigit(curChar))
{
- tokenBuilder.Append(curChar);
+ tokenBuilder.append(curChar);
pos++;
}
else
@@ -608,14 +608,14 @@ namespace Misc {
pos++;
}
else
- tokenBuilder.Append(curChar);
+ tokenBuilder.append(curChar);
}
else
{
if (derivative == LexDerivative::File)
{
derivative = LexDerivative::None;
- file = tokenBuilder.ToString();
+ file = tokenBuilder.toString();
tokenBuilder.clear();
}
else
@@ -635,7 +635,7 @@ namespace Misc {
pos++;
}
else
- tokenBuilder.Append(curChar);
+ tokenBuilder.append(curChar);
}
else
{
diff --git a/source/core/slang-token-reader.h b/source/core/slang-token-reader.h
index 4f0f9791a..264693c81 100644
--- a/source/core/slang-token-reader.h
+++ b/source/core/slang-token-reader.h
@@ -39,7 +39,7 @@ namespace Misc {
sb << FileName;
if (Line != -1)
sb << "(" << Line << ")";
- return sb.ProduceString();
+ return sb.produceString();
}
CodePosition() = default;
CodePosition(int line, int col, int pos, String fileName)
@@ -112,9 +112,9 @@ namespace Misc {
if (token.Type == TokenType::IntLiteral)
{
if (neg)
- return -StringToInt(token.Content);
+ return -stringToInt(token.Content);
else
- return StringToInt(token.Content);
+ return stringToInt(token.Content);
}
throw TextFormatException("Text parsing error: int expected.");
}
@@ -123,7 +123,7 @@ namespace Misc {
auto token = ReadToken();
if (token.Type == TokenType::IntLiteral)
{
- return StringToUInt(token.Content);
+ return stringToUInt(token.Content);
}
throw TextFormatException("Text parsing error: int expected.");
}
@@ -139,9 +139,9 @@ namespace Misc {
if (token.Type == TokenType::DoubleLiteral || token.Type == TokenType::IntLiteral)
{
if (neg)
- return -StringToDouble(token.Content);
+ return -stringToDouble(token.Content);
else
- return StringToDouble(token.Content);
+ return stringToDouble(token.Content);
}
throw TextFormatException("Text parsing error: floating point value expected.");
}
@@ -281,7 +281,7 @@ namespace Misc {
{
if (text[i] == c)
{
- auto str = sb.ToString();
+ auto str = sb.toString();
if (str.getLength() != 0)
result.add(str);
sb.clear();
@@ -289,7 +289,7 @@ namespace Misc {
else
sb << text[i];
}
- auto lastStr = sb.ToString();
+ auto lastStr = sb.toString();
if (lastStr.getLength())
result.add(lastStr);
return result;
diff --git a/source/core/slang-writer.cpp b/source/core/slang-writer.cpp
index 2b00b5853..74a39f871 100644
--- a/source/core/slang-writer.cpp
+++ b/source/core/slang-writer.cpp
@@ -210,7 +210,7 @@ SlangResult StringWriter::write(const char* chars, size_t numChars)
{
if (numChars > 0)
{
- m_builder->Append(chars, numChars);
+ m_builder->append(chars, numChars);
}
return SLANG_OK;
}