From d9118d260034319d58376c2ecf67b339568d85fb Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 9 Jun 2023 12:38:24 -0400 Subject: Small improvements around StringBlob (#2924) * #include an absolute path didn't work - because paths were taken to always be relative. * Small fixes and improvements around reflection tool. * Make PrettyWriter printing a class. * Sundary improvements around StringBlob. --- source/core/slang-string.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source/core/slang-string.h') diff --git a/source/core/slang-string.h b/source/core/slang-string.h index b4583d0b2..65fd3a315 100644 --- a/source/core/slang-string.h +++ b/source/core/slang-string.h @@ -81,6 +81,10 @@ namespace Slang public: typedef UnownedStringSlice ThisType; + // Type to indicate that a ctor is with a length to disabmiguate 0/nullptr + // causing ambiguity. + struct WithLength {}; + UnownedStringSlice() : m_begin(nullptr) , m_end(nullptr) @@ -98,6 +102,10 @@ namespace Slang : m_begin(b) , m_end(b + len) {} + UnownedStringSlice(WithLength, char const* b, size_t len) + : m_begin(b) + , m_end(b + len) + {} SLANG_FORCE_INLINE char const* begin() const { return m_begin; } @@ -190,6 +198,7 @@ namespace Slang SLANG_FORCE_INLINE static UnownedStringSlice fromLiteral(const char (&in)[SIZE]) { return UnownedStringSlice(in, SIZE - 1); } protected: + char const* m_begin; char const* m_end; }; @@ -216,6 +225,9 @@ namespace Slang template SLANG_FORCE_INLINE static ThisType fromLiteral(const char(&in)[SIZE]) { return ThisType(in, SIZE - 1); } + /// Default constructor + UnownedTerminatedStringSlice():Super(Super::WithLength(), "", 0) {} + /// Note, b cannot be null because if it were then the string would not be null terminated UnownedTerminatedStringSlice(char const* b) : Super(b, b + strlen(b)) -- cgit v1.2.3