summaryrefslogtreecommitdiff
path: root/source/core/slang-io.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-01-11 15:24:11 -0500
committerGitHub <noreply@github.com>2021-01-11 15:24:11 -0500
commit723796a0a0fed8e5b8c3222b1c90443189113098 (patch)
tree41fa039f2f2fcec4c24746203ad119a8054f021a /source/core/slang-io.cpp
parent5554777188225266e2295db3588f6cb17cae0c4d (diff)
LZ4 compression support (#1654)
* #include an absolute path didn't work - because paths were taken to always be relative. * Testing out use of lz4. * Added ICompressionSystem, and LZ4 implementation. * Add support for deflate compression. Simplify compression interface - to make more easily work across apis. * WIP on CompressedFileSystem. * ImplicitDirectoryCollector * SubStringIndexMap - > StringSliceIndexMap. * WIP save stdlib in different containers. * Support for different archive types for stdlib. * Fix project. * CompressedFileSystem -> ArchiveFileSystem. Added CompressionSystemType::None * Added ArchiveFileSystem * Fix problem RiffFileSystem load withoug compression system. * Test archive types. Improve diagnostic message. * Fix typo in testing file system archives. * Split out archive detection. * Fix gcc warning issue. * Fix warning. * RiffArchiveFileSystem -> RiffFileSystem Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'source/core/slang-io.cpp')
-rw-r--r--source/core/slang-io.cpp54
1 files changed, 30 insertions, 24 deletions
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp
index 2e2ec3d8b..d4f603109 100644
--- a/source/core/slang-io.cpp
+++ b/source/core/slang-io.cpp
@@ -3,6 +3,8 @@
#include "../../slang-com-helper.h"
+#include "slang-string-util.h"
+
#ifndef __STDC__
# define __STDC__ 1
#endif
@@ -400,52 +402,56 @@ namespace Slang
return false;
}
- /* static */String Path::simplify(const UnownedStringSlice& path)
+ /* static */void Path::simplify(List<UnownedStringSlice>& ioSplit)
{
- List<UnownedStringSlice> splitPath;
- split(path, splitPath);
-
// Strictly speaking we could do something about case on platforms like window, but here we won't worry about that
- for (Index i = 0; i < splitPath.getCount(); i++)
+ for (Index i = 0; i < ioSplit.getCount(); i++)
{
- const UnownedStringSlice& cur = splitPath[i];
- if (cur == "." && splitPath.getCount() > 1)
+ const UnownedStringSlice& cur = ioSplit[i];
+ if (cur == "." && ioSplit.getCount() > 1)
{
// Just remove it
- splitPath.removeAt(i);
+ ioSplit.removeAt(i);
i--;
}
else if (cur == ".." && i > 0)
{
// Can we remove this and the one before ?
- UnownedStringSlice& before = splitPath[i - 1];
+ UnownedStringSlice& before = ioSplit[i - 1];
if (before == ".." || (i == 1 && isDriveSpecification(before)))
{
- // Can't do it
+ // Can't do it, but we allow relative, so just leave for now
continue;
}
- splitPath.removeRange(i - 1, 2);
+ ioSplit.removeRange(i - 1, 2);
i -= 2;
}
}
+ }
- // If its empty it must be .
- if (splitPath.getCount() == 0)
+ /* static */void Path::join(const UnownedStringSlice* slices, Index count, StringBuilder& out)
+ {
+ out.Clear();
+
+ if (count == 0)
{
- splitPath.add(UnownedStringSlice::fromLiteral("."));
+ out << ".";
+ return;
}
-
+
+ StringUtil::join(slices, count, kPathDelimiter, out);
+ }
+
+
+ /* static */String Path::simplify(const UnownedStringSlice& path)
+ {
+ List<UnownedStringSlice> splitPath;
+ split(path, splitPath);
+ simplify(splitPath);
+
// Reconstruct the string
StringBuilder builder;
- for (Index i = 0; i < splitPath.getCount(); i++)
- {
- if (i > 0)
- {
- builder.Append(kPathDelimiter);
- }
- builder.Append(splitPath[i]);
- }
-
+ join(splitPath.getBuffer(), splitPath.getCount(), builder);
return builder.ToString();
}