public override void Visit(SqlUnaryScalarExpression sqlUnaryScalarExpression) { this.writer.Write("("); this.writer.Write(SqlObjectTextSerializer.SqlUnaryScalarOperatorKindToString(sqlUnaryScalarExpression.OperatorKind)); this.writer.Write(" "); sqlUnaryScalarExpression.Expression.Accept(this); this.writer.Write(")"); }
unsafe private static void WriteEscapedString(StringBuilder stringBuilder, ReadOnlySpan <char> unescapedString) { while (!unescapedString.IsEmpty) { int?indexOfFirstCharacterThatNeedsEscaping = SqlObjectTextSerializer.IndexOfCharacterThatNeedsEscaping(unescapedString); if (!indexOfFirstCharacterThatNeedsEscaping.HasValue) { // No escaping needed; indexOfFirstCharacterThatNeedsEscaping = unescapedString.Length; } // Write as much of the string as possible ReadOnlySpan <char> noEscapeNeededPrefix = unescapedString.Slice( start: 0, length: indexOfFirstCharacterThatNeedsEscaping.Value); fixed(char *noEscapeNeedPrefixPointer = noEscapeNeededPrefix) { stringBuilder.Append(noEscapeNeedPrefixPointer, noEscapeNeededPrefix.Length); } unescapedString = unescapedString.Slice(start: indexOfFirstCharacterThatNeedsEscaping.Value); // Escape the next character if it exists if (!unescapedString.IsEmpty) { char character = unescapedString[0]; unescapedString = unescapedString.Slice(start: 1); switch (character) { case '\\': stringBuilder.Append('\\'); stringBuilder.Append('\\'); break; case '"': stringBuilder.Append('\\'); stringBuilder.Append('"'); break; case '/': stringBuilder.Append('\\'); stringBuilder.Append('/'); break; case '\b': stringBuilder.Append('\\'); stringBuilder.Append('b'); break; case '\f': stringBuilder.Append('\\'); stringBuilder.Append('f'); break; case '\n': stringBuilder.Append('\\'); stringBuilder.Append('n'); break; case '\r': stringBuilder.Append('\\'); stringBuilder.Append('r'); break; case '\t': stringBuilder.Append('\\'); stringBuilder.Append('t'); break; default: char wideCharToEscape = (char)character; // We got a control character (U+0000 through U+001F). stringBuilder.Append('\\'); stringBuilder.Append('u'); stringBuilder.Append(SqlObjectTextSerializer.GetHexDigit((wideCharToEscape >> 12) & 0xF)); stringBuilder.Append(SqlObjectTextSerializer.GetHexDigit((wideCharToEscape >> 8) & 0xF)); stringBuilder.Append(SqlObjectTextSerializer.GetHexDigit((wideCharToEscape >> 4) & 0xF)); stringBuilder.Append(SqlObjectTextSerializer.GetHexDigit((wideCharToEscape >> 0) & 0xF)); break; } } } }
public override void Visit(SqlStringLiteral sqlStringLiteral) { this.writer.Write("\""); SqlObjectTextSerializer.WriteEscapedString(this.writer.GetStringBuilder(), sqlStringLiteral.Value.AsSpan()); this.writer.Write("\""); }
public override void Visit(SqlNumberLiteral sqlNumberLiteral) { SqlObjectTextSerializer.WriteNumber64(this.writer.GetStringBuilder(), sqlNumberLiteral.Value); }