2 *******************************************************************************
3 * Copyright (C) 2001-2010, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
7 package com.ibm.icu.impl;
9 import com.ibm.icu.util.VersionInfo;
11 public final class ICUDebug {
12 private static String params;
15 params = System.getProperty("ICUDebug");
17 catch (SecurityException e) {
20 private static boolean debug = params != null;
21 private static boolean help = debug && (params.equals("") || params.indexOf("help") != -1);
25 System.out.println("\nICUDebug=" + params);
29 public static final String javaVersionString = System.getProperty("java.version", "0");
30 public static final boolean isJDK14OrHigher;
31 public static final VersionInfo javaVersion;
33 public static VersionInfo getInstanceLenient(String s) {
34 // Extracting ASCII numbers up to 4 delimited by
35 // any non digit characters
36 int[] ver = new int[4];
37 boolean numeric = false;
39 while (i < s.length()) {
40 char c = s.charAt(i++);
41 if (c < '0' || c > '9') {
52 ver[vidx] = ver[vidx] * 10 + (c - '0');
53 if (ver[vidx] > 255) {
54 // VersionInfo does not support numbers
55 // greater than 255. In such case, we
56 // ignore the number and the rest
67 return VersionInfo.getInstance(ver[0], ver[1], ver[2], ver[3]);
71 javaVersion = getInstanceLenient(javaVersionString);
73 VersionInfo java14Version = VersionInfo.getInstance("1.4.0");
75 isJDK14OrHigher = javaVersion.compareTo(java14Version) >= 0;
78 public static boolean enabled() {
82 public static boolean enabled(String arg) {
84 boolean result = params.indexOf(arg) != -1;
85 if (help) System.out.println("\nICUDebug.enabled(" + arg + ") = " + result);
91 public static String value(String arg) {
92 String result = "false";
94 int index = params.indexOf(arg);
96 index += arg.length();
97 if (params.length() > index && params.charAt(index) == '=') {
99 int limit = params.indexOf(",", index);
100 result = params.substring(index, limit == -1 ? params.length() : limit);
106 if (help) System.out.println("\nICUDebug.value(" + arg + ") = " + result);
111 // static public void main(String[] args) {
113 // String[] tests = {
119 // "x1.4.51xx89ea.7f",
121 // "10-100-1000-10000",
125 // for (int i = 0; i < tests.length; ++i) {
126 // System.out.println(tests[i] + " => " + getInstanceLenient(tests[i]));