diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2018-10-26 08:16:54 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-10-26 08:16:54 -0400 |
| commit | cb9d679a3a93c65c44904bf77811b9d74e431e23 (patch) | |
| tree | bdc78bc01351f6eeed4714d01cd3aef6cf067109 /source/core/slang-string-util.cpp | |
| parent | ad47fe71defcc96a7bed87a4c3a40543978f0fb8 (diff) | |
Feature/file system cache (#692)
* First pass at caching file system.
* default-file-system -> slang-file-system
fix problem with location("build.linux") confusing windows build for now.
* Added CompressedResult
Fix problem in Result construction with it being unsigned
* Add support for Path simplification.
* Testing for Path::Simplify.
* Refactored CacheFileSystem - automatically handles ISlangFileSystem or ISlangFileSystemExt appropriately.
Removed WrapFileSystem - because wasn't possible to emulate some of the behavior if just loadFile is implemented.
Split out StringBlob - so that no need to convert between ISlangBlob and String repeatidly.
* Remove unwanted code in ~CompileRequest
Diffstat (limited to 'source/core/slang-string-util.cpp')
| -rw-r--r-- | source/core/slang-string-util.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/source/core/slang-string-util.cpp b/source/core/slang-string-util.cpp index 29f8dc0ca..6d0d896a1 100644 --- a/source/core/slang-string-util.cpp +++ b/source/core/slang-string-util.cpp @@ -2,6 +2,19 @@ namespace Slang { +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! StringBlob !!!!!!!!!!!!!!!!!!!!!!!!!!! + +// Allocate static const storage for the various interface IDs that the Slang API needs to expose +static const Guid IID_ISlangUnknown = SLANG_UUID_ISlangUnknown; +static const Guid IID_ISlangBlob = SLANG_UUID_ISlangBlob; + +/* static */ISlangUnknown* StringBlob::getInterface(const Guid& guid) +{ + return (guid == IID_ISlangUnknown || guid == IID_ISlangBlob) ? static_cast<ISlangBlob*>(this) : nullptr; +} + +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! StringUtil !!!!!!!!!!!!!!!!!!!!!!!!!!! + /* static */void StringUtil::split(const UnownedStringSlice& in, char splitChar, List<UnownedStringSlice>& slicesOut) { slicesOut.Clear(); @@ -74,4 +87,28 @@ namespace Slang { return builder; } +/* static */String StringUtil::getString(ISlangBlob* blob) +{ + if (blob) + { + size_t size = blob->getBufferSize(); + if (size > 0) + { + const char* contents = (const char*)blob->getBufferPointer(); + // Check it has terminating 0, if not we must construct as if it does + if (contents[size - 1] == 0) + { + size--; + } + return String(contents, contents + size); + } + } + return String(); +} + +ComPtr<ISlangBlob> StringUtil::createStringBlob(const String& string) +{ + return ComPtr<ISlangBlob>(new StringBlob(string)); +} + } // namespace Slang |
