• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /**
4  *******************************************************************************
5  * Copyright (C) 2001-2010, International Business Machines Corporation and    *
6  * others. All Rights Reserved.                                                *
7  *******************************************************************************
8  */
9 package com.ibm.icu.impl;
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 
enabled()29     public static boolean enabled() {
30         return debug;
31     }
32 
enabled(String arg)33     public static boolean enabled(String arg) {
34         if (debug) {
35             boolean result = params.indexOf(arg) != -1;
36             if (help) System.out.println("\nICUDebug.enabled(" + arg + ") = " + result);
37             return result;
38         }
39         return false;
40     }
41 
value(String arg)42     public static String value(String arg) {
43         String result = "false";
44         if (debug) {
45             int index = params.indexOf(arg);
46             if (index != -1) {
47                 index += arg.length();
48                 if (params.length() > index && params.charAt(index) == '=') {
49                     index += 1;
50                     int limit = params.indexOf(",", index);
51                     result = params.substring(index, limit == -1 ? params.length() : limit);
52                 } else {
53                     result = "true";
54                 }
55             }
56 
57             if (help) System.out.println("\nICUDebug.value(" + arg + ") = " + result);
58         }
59         return result;
60     }
61 }
62