XPathEncoder
Namespace: SnowBank.Text.Xml · class
XPATH Codec
Methods
AppendLiteral
static StringBuilder AppendLiteral(StringBuilder sb, string literal, char quote = '"')
Append a string literal for inclusion in a XPATH query
static StringBuilder AppendLiteral(StringBuilder sb, ReadOnlySpan<char> literal, char quote = '"')
Append a string literal for inclusion in a XPATH query
EncodeLiteral
static string EncodeLiteral(bool value)
Encode a boolean into an XPATH literal
Returns: Either "true" or "false"
static string EncodeLiteral(int value)
Encode a number into an XPATH literal
static string EncodeLiteral(long value)
Encode a number into an XPATH literal
static string EncodeLiteral(float value)
Encode a number into an XPATH literal
static string EncodeLiteral(double value)
Encode a number into an XPATH literal
static string EncodeLiteral(string literal, char quote = '"')
Encode a string literal for inclusion in a XPATH query
Encodes ', " and \ by adding a \ in front of each occurrence (ie: ' => '). Optionally adds the character at the start and end of the token. If is null, returns either
"null"
(if is specified), or an empty string (if equal to '\0')
- EncodeLiteral("Hello World") =>
Hello World- EncodeLiteral("Hello World", quote: '"') =>"Hello World"- EncodeLiteral("Hello World", quote: ''') =>'Hello World'- EncodeLiteral("A'B"C&D\E", quote: ''') =>'A\'B\"C&D\\E'
static string EncodeLiteral(ReadOnlySpan<char> literal, char quote = '"')
Encode a string literal for inclusion in a XPATH query
Encodes ', " and \ by adding a \ in front of each occurrence (ie: ' => '). Optionally adds the character at the start and end of the token. If is null, returns either
"null"
(if is specified), or an empty string (if equal to '\0')
- EncodeLiteral("Hello World") =>
Hello World- EncodeLiteral("Hello World", quote: '"') =>"Hello World"- EncodeLiteral("Hello World", quote: ''') =>'Hello World'- EncodeLiteral("A'B"C&D\E", quote: ''') =>'A\'B\"C&D\\E'
static string EncodeLiteral(Guid guid, char quote = '"')
Encode a Guid into an XPATH literal
The empty Guid is encoded as the empty string!
GetEncodedLength
static int GetEncodedLength(string literal)
Return the number of characters required to fully encode the specified string into an XPATH string literal (including escaping characters, and the surrounding quotes)
Returns: Can be used to pre-allocate the buffer capacity required to fully encode a string, before calling one of the encode helpers
Please note that the null string is encoded as "null" and so required 4 characters.
GetMaxEncodedLength
static int GetMaxEncodedLength(int count)
Return the number of characters required to fully a string literal in the worst possible
Returns: In the worst case, the string requires 2 + LENGTH * 2 characters to encode.