Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

TStringUtils.java

00001 /*
00002 *  Name:      TStringUtils.java
00003 *  Author:    Francisco Vides Fernandez
00004 *  Summary:   Miscellaneous functions for formatting strings
00005 *  Date:      $Date: 2003/10/02 22:25:06 $
00006 *  Revision:  $Revision: 1.2 $
00007 *
00008 *  Copyright (C) 2001-2003  Francisco Vides Fernandez <pax@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00027 package org.mpcl.text;
00028 
00029 import java.util.ArrayList;
00030 import java.util.List;
00031 import java.util.StringTokenizer;
00032 
00033 
00035 public class TStringUtils
00036 {
00037 
00038   //
00039   //  S E L E C T O R S
00040   //
00041 
00048   public static List _tokenizeKeys (String yKEYS)
00049   {
00050 
00051     StringTokenizer   tTokenizer;
00052     List              tTokenList = new ArrayList();
00053 
00054     try
00055     {
00056       tTokenizer = new StringTokenizer (yKEYS);
00057       while ( tTokenizer.hasMoreTokens() )
00058       {
00059         tTokenList.add (tTokenizer.nextToken());
00060       }
00061     }
00062     catch (NullPointerException tEXCEPTION)
00063     {
00064       // we do nothing if the string is null
00065     }
00066     return tTokenList;
00067 
00068   }  // _tokenizeKeys()
00069 
00079   public static String _wrapString (String ySOURCE, int iMAX_LENGTH)
00080   {
00081     return _wrapString (ySOURCE, iMAX_LENGTH, ' ', "...");
00082   }
00083 
00093   public static String _wrapString (String ySOURCE, int iMAX_LENGTH, char cLAST_CHAR)
00094   {
00095     return _wrapString (ySOURCE, iMAX_LENGTH, cLAST_CHAR, "...");
00096   }
00097 
00108   public static String _wrapString ( String ySOURCE     ,
00109                                      int    iMAX_LENGTH ,
00110                                      char   cLAST_CHAR  ,
00111                                      String ySUFFIX     )
00112   {
00113 
00114     int      iLastIndex;
00115     String   yWrapped;
00116     
00117     if ( ( ySOURCE == null ) || ( ySOURCE.length() <= iMAX_LENGTH ) )
00118     {
00119       yWrapped = ySOURCE;
00120     }
00121     else
00122     {
00123       yWrapped   = ySOURCE.substring (0, iMAX_LENGTH);
00124       iLastIndex = yWrapped.lastIndexOf (cLAST_CHAR);
00125       if ( iLastIndex >= 0 )
00126       {
00127         yWrapped = yWrapped.substring (0, iLastIndex);
00128       }
00129       yWrapped += ySUFFIX;
00130     }
00131     return yWrapped;
00132 
00133   }  // _wrapString()
00134 
00135 }  // class TStringUtils

Generated on Mon Oct 13 02:35:24 2003 for MPCL by doxygen1.2.18