Q
qwertmonkey
I need to set up some code's running context via properties files and I want
to make sure that users don't get too playful messing with them, because that
could alter results greatly and in unexpected ways (they must probably won't
be able to make sense of and then they would bother the hell out of you)
~
So, I must do some sanity check the running parameters if entered via the
command prompt or if the defaults are used from the properties files
~
I am telling you all of that because you many know of libraries to do such
thing
~
I think one possible way to do that is via a regexp, which should match all
the options included in the test array aISAr
~
One of the problems I am having is that if you enter as options say [true|t],
the matcher would match just the "t" of "true" and I want for "true" to be
actually matched another one is that, say, " true ", should be matched, as well
as "false [ nix |mac| windows ] line.separator" ...
~
Any ideas you would share?
~
thanks,
lbrtchx
~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TEST CODE ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
import java.util.regex.Matcher;
import java.util.regex.Pattern;
// __
public class RegexMatches02Test{
// __
public static void main( String args[] ){
String aRegEx;
String aIS;
Pattern Ptrn;
Matcher Mtchr;
int iCnt, iMtxStart, iMtxEnd;
// __
aRegEx = "^\\s*[true|false|t|f]{1}\\s*\\[";
aRegEx = "^\\s*[true|false|t|f]{1}";
aRegEx = "^\\s*[true|false|t|f]{1}\\s*";
aRegEx = "^\\s*[true|false t|f]{1}\\s*";
// __
String[] aISAr = new String[]{
" true[a|b |c ] q"
, " true [a|b |c ] q"
, "true [a|b |c ] q"
, "true[a|b|c] b"
, "true[a|b|c]q"
, "False[ y | n | q ] q"
, "false[nix|windows|mac]line.separator"
, "false [ nix |mac| windows ] line.separator"
, "T[y|n]q"
, "T[y]"
, "false"
, "faLse"
, "true"
, "TrUe"
, "F"
, "T"
};
int iISArL = aISAr.length, i = 0;
// __
boolean IsLoop;
Ptrn = Pattern.compile(aRegEx, Pattern.CASE_INSENSITIVE);
System.err.println("// __ matching pattern: |" + aRegEx + "|");
Mtchr = Ptrn.matcher(aISAr); // get a matcher object
IsLoop = (i < iISArL);
while(IsLoop){
System.err.println("// __ |" + i + "|" + aISAr + "|");
iCnt = 0;
// __
while(Mtchr.find()){
iMtxStart = Mtchr.start();
iMtxEnd = Mtchr.end();
System.err.println("|" + iCnt + "|" + iMtxStart + "|" + iMtxEnd + "|" +
aISAr.substring(iMtxStart, iMtxEnd) + "|");
++iCnt;
}// (Mtchr.find())
System.err.println("~");
// __
++i;
IsLoop = (i < iISArL);
if(IsLoop){ Mtchr.reset(aISAr); }
}// while(IsLoop)
}
}
to make sure that users don't get too playful messing with them, because that
could alter results greatly and in unexpected ways (they must probably won't
be able to make sense of and then they would bother the hell out of you)
~
So, I must do some sanity check the running parameters if entered via the
command prompt or if the defaults are used from the properties files
~
I am telling you all of that because you many know of libraries to do such
thing
~
I think one possible way to do that is via a regexp, which should match all
the options included in the test array aISAr
~
One of the problems I am having is that if you enter as options say [true|t],
the matcher would match just the "t" of "true" and I want for "true" to be
actually matched another one is that, say, " true ", should be matched, as well
as "false [ nix |mac| windows ] line.separator" ...
~
Any ideas you would share?
~
thanks,
lbrtchx
~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ TEST CODE ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
import java.util.regex.Matcher;
import java.util.regex.Pattern;
// __
public class RegexMatches02Test{
// __
public static void main( String args[] ){
String aRegEx;
String aIS;
Pattern Ptrn;
Matcher Mtchr;
int iCnt, iMtxStart, iMtxEnd;
// __
aRegEx = "^\\s*[true|false|t|f]{1}\\s*\\[";
aRegEx = "^\\s*[true|false|t|f]{1}";
aRegEx = "^\\s*[true|false|t|f]{1}\\s*";
aRegEx = "^\\s*[true|false t|f]{1}\\s*";
// __
String[] aISAr = new String[]{
" true[a|b |c ] q"
, " true [a|b |c ] q"
, "true [a|b |c ] q"
, "true[a|b|c] b"
, "true[a|b|c]q"
, "False[ y | n | q ] q"
, "false[nix|windows|mac]line.separator"
, "false [ nix |mac| windows ] line.separator"
, "T[y|n]q"
, "T[y]"
, "false"
, "faLse"
, "true"
, "TrUe"
, "F"
, "T"
};
int iISArL = aISAr.length, i = 0;
// __
boolean IsLoop;
Ptrn = Pattern.compile(aRegEx, Pattern.CASE_INSENSITIVE);
System.err.println("// __ matching pattern: |" + aRegEx + "|");
Mtchr = Ptrn.matcher(aISAr); // get a matcher object
IsLoop = (i < iISArL);
while(IsLoop){
System.err.println("// __ |" + i + "|" + aISAr + "|");
iCnt = 0;
// __
while(Mtchr.find()){
iMtxStart = Mtchr.start();
iMtxEnd = Mtchr.end();
System.err.println("|" + iCnt + "|" + iMtxStart + "|" + iMtxEnd + "|" +
aISAr.substring(iMtxStart, iMtxEnd) + "|");
++iCnt;
}// (Mtchr.find())
System.err.println("~");
// __
++i;
IsLoop = (i < iISArL);
if(IsLoop){ Mtchr.reset(aISAr); }
}// while(IsLoop)
}
}