File tree 1 file changed +37
-2
lines changed
FluentMigrator.BatchParser/RangeSearchers
1 file changed +37
-2
lines changed Original file line number Diff line number Diff line change 14
14
// limitations under the License.
15
15
#endregion
16
16
17
+ using System . Text . RegularExpressions ;
18
+
17
19
namespace FluentMigrator . BatchParser . RangeSearchers
18
20
{
19
21
/// <summary>
20
22
/// A single line comment starting with a pound sign (<c># comment</c>)
21
23
/// </summary>
22
- public sealed class PoundSignSingleLineComment : SingleLineComment
24
+ public sealed class PoundSignSingleLineComment : IRangeSearcher
23
25
{
26
+ private readonly Regex _startCodeRegex ;
27
+
24
28
/// <summary>
25
29
/// Initializes a new instance of the <see cref="PoundSignSingleLineComment"/> class.
26
30
/// </summary>
27
31
public PoundSignSingleLineComment ( )
28
- : base ( "#" )
29
32
{
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 ;
30
65
}
31
66
}
32
67
}
You can’t perform that action at this time.
0 commit comments