summaryrefslogtreecommitdiffstats
path: root/source/core/slang-string-util.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-06-19 16:05:40 -0400
committerGitHub <noreply@github.com>2019-06-19 16:05:40 -0400
commit442f8c6d3d42b892e3f13128bcb6487ff7508f0d (patch)
tree79746a98390c49bba9639ee84999304731210a8b /source/core/slang-string-util.cpp
parent48ae5496516878768d7de241b9b7fbba91fbaa74 (diff)
Make extractLine return a bool. (#991)
Diffstat (limited to 'source/core/slang-string-util.cpp')
-rw-r--r--source/core/slang-string-util.cpp35
1 files changed, 15 insertions, 20 deletions
diff --git a/source/core/slang-string-util.cpp b/source/core/slang-string-util.cpp
index fa96e4435..95caf8319 100644
--- a/source/core/slang-string-util.cpp
+++ b/source/core/slang-string-util.cpp
@@ -199,7 +199,7 @@ ComPtr<ISlangBlob> StringUtil::createStringBlob(const String& string)
return (fromChar == toChar || string.indexOf(fromChar) == Index(-1)) ? string : calcCharReplaced(string.getUnownedSlice(), fromChar, toChar);
}
-/* static */UnownedStringSlice StringUtil::extractLine(UnownedStringSlice& ioText)
+/* static */bool StringUtil::extractLine(UnownedStringSlice& ioText, UnownedStringSlice& outLine)
{
char const*const begin = ioText.begin();
char const*const end = ioText.end();
@@ -207,7 +207,8 @@ ComPtr<ISlangBlob> StringUtil::createStringBlob(const String& string)
// If we have hit the end then return the 'special' terminator
if (begin == nullptr)
{
- return UnownedStringSlice(nullptr, nullptr);
+ outLine = UnownedStringSlice(nullptr, nullptr);
+ return false;
}
char const* cursor = begin;
@@ -234,7 +235,8 @@ ComPtr<ISlangBlob> StringUtil::createStringBlob(const String& string)
}
ioText = UnownedStringSlice(cursor, end);
- return UnownedStringSlice(begin, lineEnd);
+ outLine = UnownedStringSlice(begin, lineEnd);
+ return true;
}
default:
break;
@@ -247,39 +249,32 @@ ComPtr<ISlangBlob> StringUtil::createStringBlob(const String& string)
// Could be empty, or the remaining line (without line end terminators of)
SLANG_ASSERT(begin <= cursor);
- return UnownedStringSlice(begin, cursor);
+ outLine = UnownedStringSlice(begin, cursor);
+ return true;
}
/* static */void StringUtil::calcLines(const UnownedStringSlice& textIn, List<UnownedStringSlice>& outLines)
{
outLines.clear();
-
- UnownedStringSlice text(textIn);
- while (true)
+ UnownedStringSlice text(textIn), line;
+ while (extractLine(text, line))
{
- UnownedStringSlice line = extractLine(text);
- if (line.begin() == nullptr)
- {
- return;
- }
outLines.add(line);
}
}
/* static */bool StringUtil::areLinesEqual(const UnownedStringSlice& inA, const UnownedStringSlice& inB)
{
- UnownedStringSlice a(inA);
- UnownedStringSlice b(inB);
-
+ UnownedStringSlice a(inA), b(inB), lineA, lineB;
+
while (true)
{
- const UnownedStringSlice lineA = extractLine(a);
- const UnownedStringSlice lineB = extractLine(b);
+ const auto hasLineA = extractLine(a, lineA);
+ const auto hasLineB = extractLine(b, lineB);
- // If either has ended, they both must have ended
- if (lineA.begin() == nullptr || lineB.begin() == nullptr)
+ if (!(hasLineA && hasLineB))
{
- return lineA.begin() == lineB.begin();
+ return hasLineA == hasLineB;
}
// The lines must be equal