summaryrefslogtreecommitdiffstats
path: root/source/core/slang-string-escape-util.h
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 14:49:26 +0800
committerGitHub <noreply@github.com>2024-10-29 14:49:26 +0800
commitf65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch)
treeea1d61342cd29368e19135000ec2948813096205 /source/core/slang-string-escape-util.h
parenta729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff)
format
* format * Minor test fixes * enable checking cpp format in ci
Diffstat (limited to 'source/core/slang-string-escape-util.h')
-rw-r--r--source/core/slang-string-escape-util.h110
1 files changed, 67 insertions, 43 deletions
diff --git a/source/core/slang-string-escape-util.h b/source/core/slang-string-escape-util.h
index c3a43b623..6e02d772d 100644
--- a/source/core/slang-string-escape-util.h
+++ b/source/core/slang-string-escape-util.h
@@ -1,39 +1,41 @@
#ifndef SLANG_CORE_STRING_ESCAPE_UTIL_H
#define SLANG_CORE_STRING_ESCAPE_UTIL_H
-#include "slang-string.h"
#include "slang-list.h"
+#include "slang-string.h"
-namespace Slang {
+namespace Slang
+{
class StringEscapeHandler
{
public:
-
- /// True if quoting is needed
+ /// True if quoting is needed
virtual bool isQuotingNeeded(const UnownedStringSlice& slice) = 0;
- /// True if any escaping is needed. If not slice can be used (assuming appropriate quoting) as is
+ /// True if any escaping is needed. If not slice can be used (assuming appropriate quoting) as
+ /// is
virtual bool isEscapingNeeded(const UnownedStringSlice& slice) = 0;
- /// True if we need to unescape
+ /// True if we need to unescape
virtual bool isUnescapingNeeeded(const UnownedStringSlice& slice) = 0;
- /// Takes slice and adds any appropriate escaping (for example C++/C type escaping for special characters like '\', '"' and if not ascii will write out as hex sequence)
- /// Does not append quotes
+ /// Takes slice and adds any appropriate escaping (for example C++/C type escaping for special
+ /// characters like '\', '"' and if not ascii will write out as hex sequence) Does not append
+ /// quotes
virtual SlangResult appendEscaped(const UnownedStringSlice& slice, StringBuilder& out) = 0;
- /// Given a slice append it unescaped
- /// Does not consume surrounding quotes
+ /// Given a slice append it unescaped
+ /// Does not consume surrounding quotes
virtual SlangResult appendUnescaped(const UnownedStringSlice& slice, StringBuilder& out) = 0;
- /// Lex quoted text.
- /// The first character of cursor should be the quoteCharacter.
- /// cursor points to the string to be lexed - must typically be 0 terminated.
- /// outCursor on successful lex will be at the next character after was processed.
+ /// Lex quoted text.
+ /// The first character of cursor should be the quoteCharacter.
+ /// cursor points to the string to be lexed - must typically be 0 terminated.
+ /// outCursor on successful lex will be at the next character after was processed.
virtual SlangResult lexQuoted(const char* cursor, const char** outCursor) = 0;
SLANG_FORCE_INLINE char getQuoteChar() const { return m_quoteChar; }
- StringEscapeHandler(char quoteChar):
- m_quoteChar(quoteChar)
+ StringEscapeHandler(char quoteChar)
+ : m_quoteChar(quoteChar)
{
}
@@ -43,8 +45,8 @@ protected:
/* A set of function that can be used for escaping/unescaping quoting/unquoting strings.
-The distinction between 'escaping' and 'quoting' here, is just that escaping is the 'payload' of quotes.
-In *principal* the Style can determine different styles of escaping that can be used.
+The distinction between 'escaping' and 'quoting' here, is just that escaping is the 'payload' of
+quotes. In *principal* the Style can determine different styles of escaping that can be used.
*/
struct StringEscapeUtil
{
@@ -52,43 +54,65 @@ struct StringEscapeUtil
enum class Style
{
- Cpp, ///< Cpp style quoting and escape handling
- Space, ///< Applies quotes if there are spaces. Does not escape.
- JSON, ///< Json encoding
- Slang, ///< Slang style string encoding (For now same as Cpp but that may change in the future)
+ Cpp, ///< Cpp style quoting and escape handling
+ Space, ///< Applies quotes if there are spaces. Does not escape.
+ JSON, ///< Json encoding
+ Slang, ///< Slang style string encoding (For now same as Cpp but that may change in the
+ ///< future)
CountOf,
};
- /// Given a style returns a handler
+ /// Given a style returns a handler
static Handler* getHandler(Style style);
- /// Get without quotes. Will assert if not correctly quoted
+ /// Get without quotes. Will assert if not correctly quoted
static UnownedStringSlice unquote(char quoteChar, const UnownedStringSlice& slice);
- static UnownedStringSlice unquote(Handler* handler, const UnownedStringSlice& slice) { return unquote(handler->getQuoteChar(), slice); }
+ static UnownedStringSlice unquote(Handler* handler, const UnownedStringSlice& slice)
+ {
+ return unquote(handler->getQuoteChar(), slice);
+ }
/// True is slice is quoted
static bool isQuoted(char quoteChar, UnownedStringSlice& slice);
- static bool isQuoted(Handler* handler, UnownedStringSlice& slice) { return isQuoted(handler->getQuoteChar(), slice); }
-
- /// If quoting is needed appends to out quoted
- static SlangResult appendMaybeQuoted(Handler* handler, const UnownedStringSlice& slice, StringBuilder& out);
-
- /// If the slice appears to be quoted for the style, unquote it, else just append to out
- static SlangResult appendMaybeUnquoted(Handler* handler, const UnownedStringSlice& slice, StringBuilder& out);
-
- /// Appends to out slice without quotes
- static SlangResult appendUnquoted(Handler* handler, const UnownedStringSlice& slice, StringBuilder& out);
-
- /// Append with quotes (even if not needed)
- static SlangResult appendQuoted(Handler* handler, const UnownedStringSlice& slice, StringBuilder& out);
-
+ static bool isQuoted(Handler* handler, UnownedStringSlice& slice)
+ {
+ return isQuoted(handler->getQuoteChar(), slice);
+ }
- /// True if requires 'shell-like' unescape. With shell-like, quoting does *not* have to start at the start of the slice.
- /// and there may be multiple quoted section
+ /// If quoting is needed appends to out quoted
+ static SlangResult appendMaybeQuoted(
+ Handler* handler,
+ const UnownedStringSlice& slice,
+ StringBuilder& out);
+
+ /// If the slice appears to be quoted for the style, unquote it, else just append to out
+ static SlangResult appendMaybeUnquoted(
+ Handler* handler,
+ const UnownedStringSlice& slice,
+ StringBuilder& out);
+
+ /// Appends to out slice without quotes
+ static SlangResult appendUnquoted(
+ Handler* handler,
+ const UnownedStringSlice& slice,
+ StringBuilder& out);
+
+ /// Append with quotes (even if not needed)
+ static SlangResult appendQuoted(
+ Handler* handler,
+ const UnownedStringSlice& slice,
+ StringBuilder& out);
+
+
+ /// True if requires 'shell-like' unescape. With shell-like, quoting does *not* have to start at
+ /// the start of the slice. and there may be multiple quoted section
static SlangResult isUnescapeShellLikeNeeded(Handler* handler, const UnownedStringSlice& slice);
- /// Shells can have multiple quoted sections. This function makes a string with out quoting
- static SlangResult unescapeShellLike(Handler* handler, const UnownedStringSlice& slice, StringBuilder& out);
+ /// Shells can have multiple quoted sections. This function makes a string with out quoting
+ static SlangResult unescapeShellLike(
+ Handler* handler,
+ const UnownedStringSlice& slice,
+ StringBuilder& out);
};