mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-15 01:42:37 +00:00
ICU-0 whitespace cleanup
X-SVN-Rev: 17552
This commit is contained in:
parent
b5ef6e48ae
commit
f2d4d6fa9e
1 changed files with 70 additions and 69 deletions
|
@ -11,19 +11,19 @@ import com.ibm.icu.util.VersionInfo;
|
|||
public final class ICUDebug {
|
||||
private static String params;
|
||||
static {
|
||||
try {
|
||||
params = System.getProperty("ICUDebug");
|
||||
}
|
||||
catch (SecurityException e) {
|
||||
}
|
||||
try {
|
||||
params = System.getProperty("ICUDebug");
|
||||
}
|
||||
catch (SecurityException e) {
|
||||
}
|
||||
}
|
||||
private static boolean debug = params != null;
|
||||
private static boolean help = debug && (params.equals("") || params.indexOf("help") != -1);
|
||||
|
||||
static {
|
||||
if (debug) {
|
||||
System.out.println("\nICUDebug=" + params);
|
||||
}
|
||||
if (debug) {
|
||||
System.out.println("\nICUDebug=" + params);
|
||||
}
|
||||
}
|
||||
|
||||
public static final String javaVersionString = System.getProperty("java.version");
|
||||
|
@ -31,42 +31,42 @@ public final class ICUDebug {
|
|||
public static final VersionInfo javaVersion;
|
||||
|
||||
public static VersionInfo getInstanceLenient(String s) {
|
||||
// clean string
|
||||
// preserve only digits, separated by single '.'
|
||||
// ignore over 4 digit sequences
|
||||
// does not test < 255, very odd...
|
||||
// clean string
|
||||
// preserve only digits, separated by single '.'
|
||||
// ignore over 4 digit sequences
|
||||
// does not test < 255, very odd...
|
||||
|
||||
char[] chars = s.toCharArray();
|
||||
int r = 0, w = 0, count = 0;
|
||||
boolean numeric = false; // ignore leading non-numerics
|
||||
while (r < chars.length) {
|
||||
char c = chars[r++];
|
||||
if (c < '0' || c > '9') {
|
||||
if (numeric) {
|
||||
if (count == 3) {
|
||||
// only four digit strings allowed
|
||||
break;
|
||||
char[] chars = s.toCharArray();
|
||||
int r = 0, w = 0, count = 0;
|
||||
boolean numeric = false; // ignore leading non-numerics
|
||||
while (r < chars.length) {
|
||||
char c = chars[r++];
|
||||
if (c < '0' || c > '9') {
|
||||
if (numeric) {
|
||||
if (count == 3) {
|
||||
// only four digit strings allowed
|
||||
break;
|
||||
}
|
||||
numeric = false;
|
||||
chars[w++] = '.';
|
||||
++count;
|
||||
}
|
||||
} else {
|
||||
numeric = true;
|
||||
chars[w++] = c;
|
||||
}
|
||||
numeric = false;
|
||||
chars[w++] = '.';
|
||||
++count;
|
||||
}
|
||||
} else {
|
||||
numeric = true;
|
||||
chars[w++] = c;
|
||||
while (w > 0 && chars[w-1] == '.') {
|
||||
--w;
|
||||
}
|
||||
}
|
||||
while (w > 0 && chars[w-1] == '.') {
|
||||
--w;
|
||||
}
|
||||
|
||||
String vs = new String(chars, 0, w);
|
||||
String vs = new String(chars, 0, w);
|
||||
|
||||
return VersionInfo.getInstance(vs);
|
||||
return VersionInfo.getInstance(vs);
|
||||
}
|
||||
|
||||
static {
|
||||
javaVersion = getInstanceLenient(javaVersionString);
|
||||
javaVersion = getInstanceLenient(javaVersionString);
|
||||
|
||||
VersionInfo java14Version = VersionInfo.getInstance("1.4.0");
|
||||
|
||||
|
@ -74,49 +74,50 @@ public final class ICUDebug {
|
|||
}
|
||||
|
||||
public static boolean enabled() {
|
||||
return debug;
|
||||
return debug;
|
||||
}
|
||||
|
||||
public static boolean enabled(String arg) {
|
||||
if (debug) {
|
||||
boolean result = params.indexOf(arg) != -1;
|
||||
if (help) System.out.println("\nICUDebug.enabled(" + arg + ") = " + result);
|
||||
return result;
|
||||
}
|
||||
return false;
|
||||
if (debug) {
|
||||
boolean result = params.indexOf(arg) != -1;
|
||||
if (help) System.out.println("\nICUDebug.enabled(" + arg + ") = " + result);
|
||||
return result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String value(String arg) {
|
||||
String result = "false";
|
||||
if (debug) {
|
||||
int index = params.indexOf(arg);
|
||||
if (index != -1) {
|
||||
index += arg.length();
|
||||
if (params.length() > index && params.charAt(index) == '=') {
|
||||
index += 1;
|
||||
int limit = params.indexOf(",", index);
|
||||
result = params.substring(index, limit == -1 ? params.length() : limit);
|
||||
}
|
||||
result = "true";
|
||||
}
|
||||
String result = "false";
|
||||
if (debug) {
|
||||
int index = params.indexOf(arg);
|
||||
if (index != -1) {
|
||||
index += arg.length();
|
||||
if (params.length() > index && params.charAt(index) == '=') {
|
||||
index += 1;
|
||||
int limit = params.indexOf(",", index);
|
||||
result = params.substring(index, limit == -1 ? params.length() : limit);
|
||||
} else {
|
||||
result = "true";
|
||||
}
|
||||
}
|
||||
|
||||
if (help) System.out.println("\nICUDebug.value(" + arg + ") = " + result);
|
||||
}
|
||||
return result;
|
||||
if (help) System.out.println("\nICUDebug.value(" + arg + ") = " + result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static public void main(String[] args) {
|
||||
// test
|
||||
String[] tests = {
|
||||
"1.3.0",
|
||||
"1.3.0_02",
|
||||
"1.3.1ea",
|
||||
"1.4.1b43",
|
||||
"___41___5",
|
||||
"x1.4.51xx89ea.7f"
|
||||
};
|
||||
for (int i = 0; i < tests.length; ++i) {
|
||||
System.out.println(tests[i] + " => " + getInstanceLenient(tests[i]));
|
||||
}
|
||||
// test
|
||||
String[] tests = {
|
||||
"1.3.0",
|
||||
"1.3.0_02",
|
||||
"1.3.1ea",
|
||||
"1.4.1b43",
|
||||
"___41___5",
|
||||
"x1.4.51xx89ea.7f"
|
||||
};
|
||||
for (int i = 0; i < tests.length; ++i) {
|
||||
System.out.println(tests[i] + " => " + getInstanceLenient(tests[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue