summaryrefslogtreecommitdiffstats
path: root/source/core/slang-io.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-06-18 18:22:43 -0400
committerTim Foley <tfoleyNV@users.noreply.github.com>2019-06-18 15:22:43 -0700
commite213e394d5008cb7bf08bbf875acd494259f5847 (patch)
tree75a82a19aaf6be8204c1f8b4ceb446d02a1f06d7 /source/core/slang-io.cpp
parent896e460dc8146bc9a39296ea72f320fe3db28cee (diff)
* Added Path::combineBuilder, so as two sub paths can be combined into a StringBuilder (#988)
* Renamed and improved comments on SharedLibrary
Diffstat (limited to 'source/core/slang-io.cpp')
-rw-r--r--source/core/slang-io.cpp39
1 files changed, 33 insertions, 6 deletions
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp
index 83f21d5dd..01c8b38e0 100644
--- a/source/core/slang-io.cpp
+++ b/source/core/slang-io.cpp
@@ -137,13 +137,40 @@ namespace Slang
String Path::combine(const String& path1, const String& path2)
{
if (path1.getLength() == 0) return path2;
- StringBuilder sb(path1.getLength()+path2.getLength()+2);
- sb.Append(path1);
- if (!path1.endsWith('\\') && !path1.endsWith('/'))
- sb.Append(kPathDelimiter);
- sb.Append(path2);
- return sb.ProduceString();
+
+ StringBuilder sb;
+ combineBuilder(path1.getUnownedSlice(), path2.getUnownedSlice(), sb);
+ return sb.ProduceString();
}
+ /* static */void Path::combineBuilder(const UnownedStringSlice& path1, const UnownedStringSlice& path2, StringBuilder& outBuilder)
+ {
+ outBuilder.Clear();
+ // Make sure we have the space for the full result
+ outBuilder.EnsureCapacity(path1.size() + 2 + path2.size());
+
+ if (path1.size() == 0)
+ {
+ outBuilder.append(path2);
+ return;
+ }
+
+ outBuilder.append(path1);
+
+ // If path1 doesn't end in a delimiter, add one
+ if (!isDelimiter(path1[path1.size() - 1]))
+ {
+ outBuilder.append(kPathDelimiter);
+ }
+
+ // Check that path2 doesn't start with a path delimiter
+ if (path2.size() > 0)
+ {
+ SLANG_ASSERT(!isDelimiter(path2[0]));
+ }
+ // Append the second path
+ outBuilder.append(path2);
+ }
+
String Path::combine(const String& path1, const String& path2, const String& path3)
{
StringBuilder sb(path1.getLength()+path2.getLength()+path3.getLength()+3);