Skip to content

Commit 87529ea

Browse files
committed
Pound sign is now only allowed at the beginning of a line
Fixes fluentmigrator/fluentmigrator#859
1 parent 46526ab commit 87529ea

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

FluentMigrator.BatchParser/RangeSearchers/PoundSignSingleLineComment.cs

+37-2
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,54 @@
1414
// limitations under the License.
1515
#endregion
1616

17+
using System.Text.RegularExpressions;
18+
1719
namespace FluentMigrator.BatchParser.RangeSearchers
1820
{
1921
/// <summary>
2022
/// A single line comment starting with a pound sign (<c># comment</c>)
2123
/// </summary>
22-
public sealed class PoundSignSingleLineComment : SingleLineComment
24+
public sealed class PoundSignSingleLineComment : IRangeSearcher
2325
{
26+
private readonly Regex _startCodeRegex;
27+
2428
/// <summary>
2529
/// Initializes a new instance of the <see cref="PoundSignSingleLineComment"/> class.
2630
/// </summary>
2731
public PoundSignSingleLineComment()
28-
: base("#")
2932
{
33+
var startCode = "#";
34+
_startCodeRegex = new Regex(Regex.Escape(startCode), RegexOptions.CultureInvariant | RegexOptions.Compiled);
35+
StartCodeLength = startCode.Length;
36+
}
37+
38+
/// <inheritdoc />
39+
public int StartCodeLength { get; }
40+
41+
/// <inheritdoc />
42+
public int EndCodeLength => 0;
43+
44+
/// <inheritdoc />
45+
public bool IsComment => true;
46+
47+
/// <inheritdoc />
48+
public int FindStartCode(ILineReader reader)
49+
{
50+
if (reader.Index != 0)
51+
return -1;
52+
var match = _startCodeRegex.Match(reader.Line, reader.Index);
53+
if (!match.Success)
54+
return -1;
55+
var skippedText = reader.ReadString(match.Index - reader.Index);
56+
if (!string.IsNullOrWhiteSpace(skippedText))
57+
return -1;
58+
return match.Index;
59+
}
60+
61+
/// <inheritdoc />
62+
public EndCodeSearchResult FindEndCode(ILineReader reader)
63+
{
64+
return reader.Line.Length;
3065
}
3166
}
3267
}

0 commit comments

Comments
 (0)