File tree 2 files changed +22
-37
lines changed
FluentMigrator.BatchParser/RangeSearchers
2 files changed +22
-37
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
-
19
17
namespace FluentMigrator . BatchParser . RangeSearchers
20
18
{
21
19
/// <summary>
22
20
/// A single line comment starting with a pound sign (<c># comment</c>)
23
21
/// </summary>
24
- public sealed class PoundSignSingleLineComment : IRangeSearcher
22
+ public sealed class PoundSignSingleLineComment : SingleLineComment
25
23
{
26
- private readonly Regex _startCodeRegex ;
27
-
28
24
/// <summary>
29
25
/// Initializes a new instance of the <see cref="PoundSignSingleLineComment"/> class.
30
26
/// </summary>
31
27
public PoundSignSingleLineComment ( )
28
+ : base ( "#" , true )
32
29
{
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 ;
65
30
}
66
31
}
67
32
}
Original file line number Diff line number Diff line change @@ -24,14 +24,26 @@ namespace FluentMigrator.BatchParser.RangeSearchers
24
24
/// </summary>
25
25
public class SingleLineComment : IRangeSearcher
26
26
{
27
+ private readonly bool _onlyAtBeginningOfLine ;
27
28
private readonly Regex _startCodeRegex ;
28
29
29
30
/// <summary>
30
31
/// Initializes a new instance of the <see cref="SingleLineComment"/> class.
31
32
/// </summary>
32
33
/// <param name="startCode">The start code for the single line comment</param>
33
34
public SingleLineComment ( string startCode )
35
+ : this ( startCode , false )
34
36
{
37
+ }
38
+
39
+ /// <summary>
40
+ /// Initializes a new instance of the <see cref="SingleLineComment"/> class.
41
+ /// </summary>
42
+ /// <param name="startCode">The start code for the single line comment</param>
43
+ /// <param name="onlyAtBeginningOfLine">Find the start code only at the beginning of the line</param>
44
+ public SingleLineComment ( string startCode , bool onlyAtBeginningOfLine )
45
+ {
46
+ _onlyAtBeginningOfLine = onlyAtBeginningOfLine ;
35
47
_startCodeRegex = new Regex ( Regex . Escape ( startCode ) , RegexOptions . CultureInvariant | RegexOptions . Compiled ) ;
36
48
StartCodeLength = startCode . Length ;
37
49
}
@@ -51,6 +63,14 @@ public int FindStartCode(ILineReader reader)
51
63
var match = _startCodeRegex . Match ( reader . Line , reader . Index ) ;
52
64
if ( ! match . Success )
53
65
return - 1 ;
66
+
67
+ if ( _onlyAtBeginningOfLine )
68
+ {
69
+ var skippedText = reader . Line . Substring ( 0 , match . Index ) ;
70
+ if ( ! string . IsNullOrWhiteSpace ( skippedText ) )
71
+ return - 1 ;
72
+ }
73
+
54
74
return match . Index ;
55
75
}
56
76
You can’t perform that action at this time.
0 commit comments