001: package com.healthmarketscience.jackcess.scsu;
002:
003: import org.apache.commons.logging.Log;
004: import org.apache.commons.logging.LogFactory;
005:
006: /*
007: * This sample software accompanies Unicode Technical Report #6 and
008: * distributed as is by Unicode, Inc., subject to the following:
009: *
010: * Copyright 1996-1997 Unicode, Inc.. All Rights Reserved.
011: *
012: * Permission to use, copy, modify, and distribute this software
013: * without fee is hereby granted provided that this copyright notice
014: * appears in all copies.
015: *
016: * UNICODE, INC. MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
017: * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING
018: * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
019: * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
020: * UNICODE, INC., SHALL NOT BE LIABLE FOR ANY ERRORS OR OMISSIONS, AND
021: * SHALL NOT BE LIABLE FOR ANY DAMAGES, INCLUDING CONSEQUENTIAL AND
022: * INCIDENTAL DAMAGES, SUFFERED BY YOU AS A RESULT OF USING, MODIFYING
023: * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
024: *
025: * @author Asmus Freytag
026: *
027: * @version 001 Dec 25 1996
028: * @version 002 Jun 25 1997
029: * @version 003 Jul 25 1997
030: * @version 004 Aug 25 1997
031: *
032: * Unicode and the Unicode logo are trademarks of Unicode, Inc.,
033: * and are registered in some jurisdictions.
034: **/
035:
036: /**
037: * A number of helpful output routines for debugging. Output can be
038: * centrally enabled or disabled by calling Debug.set(true/false);
039: * All methods are statics;
040: */
041:
042: public class Debug {
043:
044: private static final Log LOG = LogFactory.getLog(Debug.class);
045:
046: // debugging helper
047: public static void out(char[] chars) {
048: out(chars, 0);
049: }
050:
051: public static void out(char[] chars, int iStart) {
052: if (!LOG.isDebugEnabled())
053: return;
054: StringBuffer msg = new StringBuffer();
055:
056: for (int i = iStart; i < chars.length; i++) {
057: if (chars[i] >= 0 && chars[i] <= 26) {
058: msg.append("^" + (char) (chars[i] + 0x40));
059: } else if (chars[i] <= 255) {
060: msg.append(chars[i]);
061: } else {
062: msg.append("\\u" + Integer.toString(chars[i], 16));
063: }
064: }
065: LOG.debug(msg.toString());
066: }
067:
068: public static void out(byte[] bytes) {
069: out(bytes, 0);
070: }
071:
072: public static void out(byte[] bytes, int iStart) {
073: if (!LOG.isDebugEnabled())
074: return;
075: StringBuffer msg = new StringBuffer();
076:
077: for (int i = iStart; i < bytes.length; i++) {
078: msg.append(bytes[i] + ",");
079: }
080: LOG.debug(msg.toString());
081: }
082:
083: public static void out(String str) {
084: if (!LOG.isDebugEnabled())
085: return;
086:
087: LOG.debug(str);
088: }
089:
090: public static void out(String msg, int iData) {
091: if (!LOG.isDebugEnabled())
092: return;
093:
094: LOG.debug(msg + iData);
095: }
096:
097: public static void out(String msg, char ch) {
098: if (!LOG.isDebugEnabled())
099: return;
100:
101: LOG.debug(msg + "[U+" + Integer.toString(ch, 16) + "]" + ch);
102: }
103:
104: public static void out(String msg, byte bData) {
105: if (!LOG.isDebugEnabled())
106: return;
107:
108: LOG.debug(msg + bData);
109: }
110:
111: public static void out(String msg, String str) {
112: if (!LOG.isDebugEnabled())
113: return;
114:
115: LOG.debug(msg + str);
116: }
117:
118: public static void out(String msg, char[] data) {
119: if (!LOG.isDebugEnabled())
120: return;
121:
122: LOG.debug(msg);
123: out(data);
124: }
125:
126: public static void out(String msg, byte[] data) {
127: if (!LOG.isDebugEnabled())
128: return;
129:
130: LOG.debug(msg);
131: out(data);
132: }
133:
134: public static void out(String msg, char[] data, int iStart) {
135: if (!LOG.isDebugEnabled())
136: return;
137:
138: LOG.debug(msg + "(" + iStart + "): ");
139: out(data, iStart);
140: }
141:
142: public static void out(String msg, byte[] data, int iStart) {
143: if (!LOG.isDebugEnabled())
144: return;
145:
146: LOG.debug(msg + "(" + iStart + "): ");
147: out(data, iStart);
148: }
149: }
|