]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/main/classes/core/src/com/ibm/icu/impl/ICUDebug.java
Clean up imports.
[Dictionary.git] / jars / icu4j-52_1 / main / classes / core / src / com / ibm / icu / impl / ICUDebug.java
1 /**
2  *******************************************************************************
3  * Copyright (C) 2001-2010, International Business Machines Corporation and    *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6  */
7 package com.ibm.icu.impl;
8
9 import com.ibm.icu.util.VersionInfo;
10
11 public final class ICUDebug {
12     private static String params;
13     static {
14         try {
15             params = System.getProperty("ICUDebug");
16         }
17         catch (SecurityException e) {
18         }
19     }
20     private static boolean debug = params != null;
21     private static boolean help = debug && (params.equals("") || params.indexOf("help") != -1);
22
23     static {
24         if (debug) {
25             System.out.println("\nICUDebug=" + params);
26         }
27     }
28
29     public static final String javaVersionString = System.getProperty("java.version", "0");
30     public static final boolean isJDK14OrHigher;
31     public static final VersionInfo javaVersion;
32
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;
38         int i = 0, vidx = 0;
39         while (i < s.length()) {
40             char c = s.charAt(i++);
41             if (c < '0' || c > '9') {
42                 if (numeric) {
43                     if (vidx == 3) {
44                         // up to 4 numbers
45                         break;
46                     }
47                     numeric = false;
48                     vidx++;
49                 }
50             } else {
51                 if (numeric) {
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
57                         ver[vidx] = 0;
58                         break;
59                     }
60                 } else {
61                     numeric = true;
62                     ver[vidx] = c - '0';
63                 }
64             }
65         }
66
67         return VersionInfo.getInstance(ver[0], ver[1], ver[2], ver[3]);
68     }
69
70     static {
71         javaVersion = getInstanceLenient(javaVersionString);
72
73         VersionInfo java14Version = VersionInfo.getInstance("1.4.0");
74
75         isJDK14OrHigher = javaVersion.compareTo(java14Version) >= 0;
76     }
77
78     public static boolean enabled() {
79         return debug;
80     }
81
82     public static boolean enabled(String arg) {
83         if (debug) {
84             boolean result = params.indexOf(arg) != -1;
85             if (help) System.out.println("\nICUDebug.enabled(" + arg + ") = " + result);
86             return result;
87         }
88         return false;
89     }
90
91     public static String value(String arg) {
92         String result = "false";
93         if (debug) {
94             int index = params.indexOf(arg);
95             if (index != -1) {
96                 index += arg.length();
97                 if (params.length() > index && params.charAt(index) == '=') {
98                     index += 1;
99                     int limit = params.indexOf(",", index);
100                     result = params.substring(index, limit == -1 ? params.length() : limit);
101                 } else {
102                     result = "true";
103                 }
104             }
105
106             if (help) System.out.println("\nICUDebug.value(" + arg + ") = " + result);
107         }
108         return result;
109     }
110
111 //    static public void main(String[] args) {
112 //        // test
113 //        String[] tests = {
114 //            "1.3.0",
115 //            "1.3.0_02",
116 //            "1.3.1ea",
117 //            "1.4.1b43",
118 //            "___41___5",
119 //            "x1.4.51xx89ea.7f",
120 //            "1.6_2009",
121 //            "10-100-1000-10000",
122 //            "beta",
123 //            "0",
124 //        };
125 //        for (int i = 0; i < tests.length; ++i) {
126 //            System.out.println(tests[i] + " => " + getInstanceLenient(tests[i]));
127 //        }
128 //    }
129 }