@@ -29,16 +29,23 @@ public static void main(String[] args) throws ParseException, IOException {
29
29
// create Options object
30
30
Options options = new Options ();
31
31
32
- options .addOption ( "rf" , true , "regexFile" );
33
- options .addOption ( "r" , true , "regex" );
32
+ options .addOption (
33
+ "rf" ,
34
+ true ,
35
+ "file containint the regexes to test against (multiple regexes are separated by one empty line)"
36
+ );
37
+ options .addOption ( "r" , true , "regex to test against" );
34
38
35
- options .addOption ( "mf" , true , "moaFile " );
36
- options .addOption ( "mo" , true , "moaOutputFolder (overwrites if existent)" );
39
+ options .addOption ( "mf" , true , "file/folder to read the MOA from " );
40
+ options .addOption ( "mo" , true , "folder to export the MOAs to (overwrites if existent)" );
37
41
38
- options .addOption ( "sf" , true , "stringFile " );
39
- options .addOption ( "s" , true , "string" );
42
+ options .addOption ( "sf" , true , "file to read the input string(s) from " );
43
+ options .addOption ( "s" , true , "string to test the MOA/Regex against " );
40
44
41
- options .addOption ( "m" , false , "multiline" );
45
+ options .addOption ( "m" , false , "multiline matching mode (search in string for regex)" );
46
+
47
+ options .addOption ( "ls" , false , "treat every line of the input string file as one string" );
48
+ options .addOption ( "t" , false , "trim lines if -ls is set" );
42
49
43
50
options .addOption ( "help" , false , "prints this dialog" );
44
51
@@ -76,7 +83,7 @@ public static void main(String[] args) throws ParseException, IOException {
76
83
if ( emptyLineCountAfterRegex >= 1 ) {
77
84
if ( regexStr .length () > 0 ) {
78
85
patterns .add ( MoaPattern .compile ( regexStr .toString () ) );
79
- patternNames .add (regexStr .toString ());
86
+ patternNames .add ( regexStr .toString () );
80
87
}
81
88
regexStr .setLength ( 0 );
82
89
emptyLineCountAfterRegex = 0 ;
@@ -93,7 +100,7 @@ public static void main(String[] args) throws ParseException, IOException {
93
100
if ( regexStr .length () > 0 ) {
94
101
try {
95
102
patterns .add ( MoaPattern .compile ( regexStr .toString () ) );
96
- patternNames .add (regexStr .toString ());
103
+ patternNames .add ( regexStr .toString () );
97
104
}
98
105
catch (Exception e ) {
99
106
System .out .println ( e .getMessage () );
@@ -114,14 +121,14 @@ public static void main(String[] args) throws ParseException, IOException {
114
121
for ( File moar : moarFiles ) {
115
122
String jsonString = readWholeFile ( moar );
116
123
patterns .add ( MoarJSONSerializer .fromJSON ( jsonString ) );
117
- patternNames .add (moar .getAbsolutePath ());
124
+ patternNames .add ( moar .getAbsolutePath () );
118
125
}
119
126
}
120
127
else {
121
128
System .out .println ( fileName + " is a single file. using it directly (no check for *.moar suffix)" );
122
129
String jsonString = readWholeFile ( file );
123
130
patterns .add ( MoarJSONSerializer .fromJSON ( jsonString ) );
124
- patternNames .add (fileName );
131
+ patternNames .add ( fileName );
125
132
}
126
133
}
127
134
@@ -131,23 +138,36 @@ public static void main(String[] args) throws ParseException, IOException {
131
138
}
132
139
133
140
if ( cmd .hasOption ( "sf" ) ) {
141
+ boolean treatLineAsString = cmd .hasOption ( "ls" );
142
+ boolean trim = cmd .hasOption ( "t" );
134
143
String fileName = cmd .getOptionValue ( "sf" );
135
144
StringBuilder stringBuilder = new StringBuilder ();
136
145
boolean firstLine = true ;
137
146
for ( String str : readFileContents ( new File ( fileName ) ) ) {
138
- if ( !firstLine ) {
139
- stringBuilder .append ( "\n " );
147
+ if ( treatLineAsString ) {
148
+ if ( trim ) {
149
+ str = str .trim ();
150
+ if ( str .length () == 0 ) {
151
+ continue ;
152
+ }
153
+ }
154
+ stringsToCheck .add ( str );
140
155
}
141
- if ( firstLine ) {
142
- firstLine = false ;
156
+ else {
157
+ if ( !firstLine ) {
158
+ stringBuilder .append ( "\n " );
159
+ }
160
+ if ( firstLine ) {
161
+ firstLine = false ;
162
+ }
163
+ stringBuilder .append ( str );
143
164
}
144
- stringBuilder .append ( str );
145
165
}
146
- stringsToCheck .add ( stringBuilder .toString () );
166
+ if ( !treatLineAsString ) {
167
+ stringsToCheck .add ( stringBuilder .toString () );
168
+ }
147
169
}
148
170
149
- boolean multiLine = cmd .hasOption ( "m" );
150
-
151
171
if ( patterns .size () == 0 ) {
152
172
System .out .println ( "no patterns to check" );
153
173
return ;
@@ -184,16 +204,18 @@ public static void main(String[] args) throws ParseException, IOException {
184
204
return ;
185
205
}
186
206
207
+ boolean multiline = cmd .hasOption ( "m" );
208
+
187
209
for ( String string : stringsToCheck ) {
188
210
int curPattern = 0 ;
189
211
for ( MoaPattern pattern : patterns ) {
190
212
MoaMatcher matcher = pattern .matcher ( string );
191
- if ( !multiLine ) {
213
+ if ( !multiline ) {
192
214
if ( matcher .matches () ) {
193
- System .out .println ( "\" " + patternNames .get (curPattern ) + "\" matches \" " + string + "\" " );
215
+ System .out .println ( "\" " + patternNames .get ( curPattern ) + "\" matches \" " + string + "\" " );
194
216
}
195
217
else {
196
- System .out .println ( "\" " + patternNames .get (curPattern ) + "\" does not match \" " + string + "\" " );
218
+ System .out .println ( "\" " + patternNames .get ( curPattern ) + "\" does not match \" " + string + "\" " );
197
219
}
198
220
}
199
221
else {
0 commit comments