From ce47d3c5db7f9dbd4e859d367f576fbf92d62beb Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 22 Aug 2008 17:47:51 +0000 Subject: [PATCH] Throw descriptive exception when escape character '@' is at the end of a highlighting expression. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3439 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../DefaultHighlightingStrategy.cs | 110 +++++++++--------- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs index 027b706311..cbf57e6900 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/DefaultHighlightingStrategy.cs @@ -786,6 +786,8 @@ namespace ICSharpCode.TextEditor.Document switch (expr[i]) { case '@': // "special" meaning ++i; + if (i == expr.Length) + throw new HighlightingDefinitionInvalidException("Unexpected end of @ sequence, use @@ to look for a single @."); switch (expr[i]) { case '!': // don't match the following expression StringBuilder whatmatch = new StringBuilder(); @@ -819,69 +821,69 @@ namespace ICSharpCode.TextEditor.Document switch (expr[i]) { case '@': // "special" meaning ++i; - if (i < expr.Length) { - switch (expr[i]) { - case 'C': // match whitespace or punctuation - if (index + j == lineSegment.Offset || index + j >= lineSegment.Offset + lineSegment.Length) { - // nothing (EOL or SOL) - } else { - char ch = document.GetCharAt(lineSegment.Offset + index + j); - if (!Char.IsWhiteSpace(ch) && !Char.IsPunctuation(ch)) { - return false; - } + if (i == expr.Length) + throw new HighlightingDefinitionInvalidException("Unexpected end of @ sequence, use @@ to look for a single @."); + switch (expr[i]) { + case 'C': // match whitespace or punctuation + if (index + j == lineSegment.Offset || index + j >= lineSegment.Offset + lineSegment.Length) { + // nothing (EOL or SOL) + } else { + char ch = document.GetCharAt(lineSegment.Offset + index + j); + if (!Char.IsWhiteSpace(ch) && !Char.IsPunctuation(ch)) { + return false; } - break; - case '!': // don't match the following expression - { - StringBuilder whatmatch = new StringBuilder(); - ++i; - while (i < expr.Length && expr[i] != '@') { - whatmatch.Append(expr[i++]); - } - if (lineSegment.Offset + index + j + whatmatch.Length < document.TextLength) { - int k = 0; - for (; k < whatmatch.Length; ++k) { - char docChar = ignoreCase ? Char.ToUpperInvariant(document.GetCharAt(lineSegment.Offset + index + j + k)) : document.GetCharAt(lineSegment.Offset + index + j + k); - char spanChar = ignoreCase ? Char.ToUpperInvariant(whatmatch[k]) : whatmatch[k]; - if (docChar != spanChar) { - break; - } - } - if (k >= whatmatch.Length) { - return false; + } + break; + case '!': // don't match the following expression + { + StringBuilder whatmatch = new StringBuilder(); + ++i; + while (i < expr.Length && expr[i] != '@') { + whatmatch.Append(expr[i++]); + } + if (lineSegment.Offset + index + j + whatmatch.Length < document.TextLength) { + int k = 0; + for (; k < whatmatch.Length; ++k) { + char docChar = ignoreCase ? Char.ToUpperInvariant(document.GetCharAt(lineSegment.Offset + index + j + k)) : document.GetCharAt(lineSegment.Offset + index + j + k); + char spanChar = ignoreCase ? Char.ToUpperInvariant(whatmatch[k]) : whatmatch[k]; + if (docChar != spanChar) { + break; } } + if (k >= whatmatch.Length) { + return false; + } + } // --j; - break; + break; + } + case '-': // don't match the expression before + { + StringBuilder whatmatch = new StringBuilder(); + ++i; + while (i < expr.Length && expr[i] != '@') { + whatmatch.Append(expr[i++]); } - case '-': // don't match the expression before - { - StringBuilder whatmatch = new StringBuilder(); - ++i; - while (i < expr.Length && expr[i] != '@') { - whatmatch.Append(expr[i++]); + if (index - whatmatch.Length >= 0) { + int k = 0; + for (; k < whatmatch.Length; ++k) { + char docChar = ignoreCase ? Char.ToUpperInvariant(document.GetCharAt(lineSegment.Offset + index - whatmatch.Length + k)) : document.GetCharAt(lineSegment.Offset + index - whatmatch.Length + k); + char spanChar = ignoreCase ? Char.ToUpperInvariant(whatmatch[k]) : whatmatch[k]; + if (docChar != spanChar) + break; } - if (index - whatmatch.Length >= 0) { - int k = 0; - for (; k < whatmatch.Length; ++k) { - char docChar = ignoreCase ? Char.ToUpperInvariant(document.GetCharAt(lineSegment.Offset + index - whatmatch.Length + k)) : document.GetCharAt(lineSegment.Offset + index - whatmatch.Length + k); - char spanChar = ignoreCase ? Char.ToUpperInvariant(whatmatch[k]) : whatmatch[k]; - if (docChar != spanChar) - break; - } - if (k >= whatmatch.Length) { - return false; - } + if (k >= whatmatch.Length) { + return false; } -// --j; - break; - } - case '@': // matches @ - if (index + j >= lineSegment.Length || '@' != document.GetCharAt(lineSegment.Offset + index + j)) { - return false; } +// --j; break; - } + } + case '@': // matches @ + if (index + j >= lineSegment.Length || '@' != document.GetCharAt(lineSegment.Offset + index + j)) { + return false; + } + break; } break; default: