Skip to content

Commit

Permalink
Merge pull request #854 from tkellogg/dollar-newline
Browse files Browse the repository at this point in the history
Made `$` match end of line
  • Loading branch information
jaredpar committed Apr 4, 2012
2 parents 09647c2 + 8842f3a commit 72651fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion VimCore/VimRegex.fs
Expand Up @@ -231,6 +231,13 @@ module VimRegexFactory =
RegexOptions.None
else
RegexOptions.Compiled

let regexOptions =
if data.IncludesNewLine then
regexOptions
else
regexOptions ||| RegexOptions.Multiline

if data.MatchCase then
regexOptions
else
Expand Down Expand Up @@ -260,7 +267,10 @@ module VimRegexFactory =
| '}' -> if data.IsRangeOpen then data.EndRange() else data.AppendChar '}'
| '|' -> data.AppendChar '|'
| '^' -> if data.IsStartOfPattern || data.IsStartOfGrouping then data.AppendChar '^' else data.AppendEscapedChar '^'
| '$' -> if data.IsEndOfPattern then data.AppendChar '$' else data.AppendEscapedChar '$'
| '$' ->
if data.IsEndOfPattern then
data.AppendString @"\r?$"
else data.AppendEscapedChar '$'
| '<' -> data.AppendString @"\b"
| '>' -> data.AppendString @"\b"
| '[' -> data.BeginGrouping()
Expand Down
8 changes: 8 additions & 0 deletions VimCoreTest/VimRegexTest.cs
Expand Up @@ -1108,5 +1108,13 @@ public void NewLine_Replace()
VerifyReplace(@"\n", "hello\r\nworld", " ", "hello world");
VerifyReplace(@"\n", "hello\rworld", " ", "hello world");
}

[Test]
public void Newline_DollarSignMatchesEndOfLine()
{
VerifyMatches(@"foo$", "foo\r\nbar");
VerifyMatches(@"foo$", "foo\nbar");
VerifyMatches(@"foo$", "foo");
}
}
}

0 comments on commit 72651fe

Please sign in to comment.