public TSQLStringLiteral( int beginPostion, string text) : base( beginPostion, text) { // need to find unescaped value insides quote characters // there are three different possible quote characters that we might support for string literals // if this is a unicode string it will begin with N int quotePosition = 0; int length = text.Length - 2; if (text[0] == 'N') { quotePosition++; length--; IsUnicode = true; } else { IsUnicode = false; } // now we can find which quote character we're using QuoteCharacter = text[quotePosition]; // now unescape doubled up quote characters Value = text.Substring(quotePosition + 1, length) .Replace(new string(QuoteCharacter, 2), QuoteCharacter.ToString()); }
/// <summary> /// Retrieves a token from a character array. /// </summary> /// <param name="chars">the character array containing the token</param> /// <param name="start">the index of the first character of the token</param> /// <param name="end">the index of the last character of the token</param> /// <returns>the token without the surrounding quotes, or the token itself if there are no surrounding quotes</returns> private string RetrieveToken(char[] chars, int start, int end) { var startQuote = start; var endQuote = end; // Remove quotes if necessary if (SearchQuote(chars, ref startQuote, ref endQuote)) { var token = new string(chars, startQuote + 1, endQuote - startQuote - 1); token = token.Replace(QuoteCharacter.ToString() + QuoteCharacter, QuoteCharacter.ToString()); return(token); } return(new string(chars, start, end - start + 1)); }
internal TSQLStringLiteral( int beginPosition, string text) : base( beginPosition, text) { // need to find unescaped value insides quote characters // there are three different possible quote characters that we might support for string literals // if this is a unicode string it will begin with N int quotePosition = 0; int length = text.Length - 2; if (text[0] == 'N') { quotePosition++; length--; IsUnicode = true; } else { IsUnicode = false; } // now we can find which quote character we're using QuoteCharacter = text[quotePosition]; // trim off the leading and trailing quotes Value = text.Substring(quotePosition + 1, length); // now unescape doubled up quote characters Value = Value.Replace(new string(QuoteCharacter, 2), QuoteCharacter.ToString()); // remove line continuation backslash // https://docs.microsoft.com/en-us/sql/t-sql/language-elements/sql-server-utilities-statements-backslash?view=sql-server-2017 Value = Value.Replace("\\\r\n", ""); Value = Value.Replace("\\\n", ""); }