1   /*
2    * PROJECT   : DAR Runtime and Tools
3    * COPYRIGHT : Copyright (C) 1999-2004 tim.stephenson@enableit.org
4    * LICENSE   : GNU LESSER GENERAL PUBLIC LICENSE
5    *             Version 2.1, February 1999
6    *
7    * This program is free software; you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20   */
21  package org.enableit.db.util;
22  
23  import org.apache.log4j.Logger;
24  
25  
26  /***
27   * @author $Author: tim $
28   */
29  public class StringHelper extends Object {
30      /*
31       * Properties
32       */
33  
34      /***
35       * The Log4J <code>Logger</code> doing the logging.
36       */
37      private static Logger logger = Logger.getLogger(StringHelper.class);
38  
39      /***
40       * CVS info ABOUT this class and its current version
41       */
42      public static final String ABOUT = "$Revision: 1.5 $";
43  
44      /*
45       * Constructors
46       */
47  
48      /***
49       * Constructor to prevent instantiation.
50       */
51      private StringHelper() {
52      }
53  
54      /*
55       * Methods
56       */
57  
58      /***
59       * Trims leading and trailing whitespace as defined by the Unicode
60       * (unlike <code>java.lang.String.trim()</code>).
61       */
62      public static String trim(String s) {
63          logger.info("METHOD_ENTRY: trim, string: " + s);
64  
65          StringBuffer sb = new StringBuffer();
66          boolean started = false;
67  
68          for (int y = 0; y < s.length(); y++) {
69              char c = s.charAt(y);
70  
71              if (!Character.isSpaceChar(c)) {
72                  started = true;
73              }
74  
75              if (started) {
76                  logger.debug("c: " + c + "y: " + y);
77                  sb.append(s.substring(y));
78  
79                  break;
80              }
81          }
82  
83          s = sb.toString();
84          logger.debug("After leading trim: " + s);
85          sb = new StringBuffer();
86          started = false;
87  
88          for (int y = s.length() - 1; y > 0; y--) {
89              char c = s.charAt(y);
90  
91              if (!Character.isSpaceChar(c)) {
92                  started = true;
93              }
94  
95              if (started) {
96                  sb.append(s.substring(0, y + 1));
97  
98                  break;
99              }
100         }
101 
102         logger.info("METHOD_EXIT: trim, returning: " + sb);
103 
104         return sb.toString();
105     }
106 }
This page was automatically generated by Maven