diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-03-08 12:35:00 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-03-08 12:35:00 -0800 |
| commit | a22b7520745334ecef3cbd920a0331f01c905935 (patch) | |
| tree | f5ecf29f957f6b40f3fb5a4f987b2a1d00dd3bed /source/core/slang-string.cpp | |
| parent | ed718ba1048ef856efbf0d02902e4d60f173b207 (diff) | |
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.
Diffstat (limited to 'source/core/slang-string.cpp')
| -rw-r--r-- | source/core/slang-string.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
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() |
