From a22b7520745334ecef3cbd920a0331f01c905935 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 8 Mar 2018 12:35:00 -0800 Subject: Cleanups on slang-generate (#437) * Cleanups on slang-generate There is nothing too significant in these changes, but I'm trying to get things in place so that we can: - Clean up the stdlib code to do less explicit `StringBuilder` operations and instead to use more of the "template engine" approach - Start using slang-generate for code other than the slang stdlib, so that we can generate more of our boilerplate. The main new functionality here is that in a template/meta file, you can now enclose an expression in `$(...)` to indicate that is should be spliced into the result. E.g. instead of: class ${{ sb << someClassName; }} { ... } We can now write: class $(someClassName) { ... } The other bit of new functionality is support for a whole-line statement escape, so that instead of: ${{ for( auto a : someCollection ) { }} void $(a)() { ... } ${{ } }} We can instead write: $: for(auto a : someCollection) { void $(a)() { ... } $: } I haven't yet tried to use that functionality in the stdlib meta-code, but doing so would be an obvious next step. * Fixup: change some $P to $p The capitalization on some of the GLSL intrinsic mappings got messed up during a find-and-replace operation when removing the double `$` that used to be required to escape things. --- source/core/slang-string.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'source/core/slang-string.cpp') diff --git a/source/core/slang-string.cpp b/source/core/slang-string.cpp index 460a077b5..2420cb7d7 100644 --- a/source/core/slang-string.cpp +++ b/source/core/slang-string.cpp @@ -43,6 +43,26 @@ namespace Slang return endData ? endData : kEmptyOSString; } + // UnownedStringSlice + + bool UnownedStringSlice::endsWith(UnownedStringSlice const& other) const + { + UInt thisSize = size(); + UInt otherSize = other.size(); + + if (otherSize > thisSize) + return false; + + return UnownedStringSlice( + end() - otherSize, end()) == other; + } + + bool UnownedStringSlice::endsWith(char const* str) const + { + return endsWith(UnownedTerminatedStringSlice(str)); + } + + // StringSlice StringSlice::StringSlice() -- cgit v1.2.3