PageRenderTime 96ms CodeModel.GetById 86ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/bsh/StringUtil.java

#
Java | 120 lines | 59 code | 11 blank | 50 comment | 10 complexity | 5213a0bd5f70cab7fcaa133f33f63031 MD5 | raw file
  1/*****************************************************************************
  2 *                                                                           *
  3 *  This file is part of the BeanShell Java Scripting distribution.          *
  4 *  Documentation and updates may be found at http://www.beanshell.org/      *
  5 *                                                                           *
  6 *  Sun Public License Notice:                                               *
  7 *                                                                           *
  8 *  The contents of this file are subject to the Sun Public License Version  *
  9 *  1.0 (the "License"); you may not use this file except in compliance with *
 10 *  the License. A copy of the License is available at http://www.sun.com    * 
 11 *                                                                           *
 12 *  The Original Code is BeanShell. The Initial Developer of the Original    *
 13 *  Code is Pat Niemeyer. Portions created by Pat Niemeyer are Copyright     *
 14 *  (C) 2000.  All Rights Reserved.                                          *
 15 *                                                                           *
 16 *  GNU Public License Notice:                                               *
 17 *                                                                           *
 18 *  Alternatively, the contents of this file may be used under the terms of  *
 19 *  the GNU Lesser General Public License (the "LGPL"), in which case the    *
 20 *  provisions of LGPL are applicable instead of those above. If you wish to *
 21 *  allow use of your version of this file only under the  terms of the LGPL *
 22 *  and not to allow others to use your version of this file under the SPL,  *
 23 *  indicate your decision by deleting the provisions above and replace      *
 24 *  them with the notice and other provisions required by the LGPL.  If you  *
 25 *  do not delete the provisions above, a recipient may use your version of  *
 26 *  this file under either the SPL or the LGPL.                              *
 27 *                                                                           *
 28 *  Patrick Niemeyer (pat@pat.net)                                           *
 29 *  Author of Learning Java, O'Reilly & Associates                           *
 30 *  http://www.pat.net/~pat/                                                 *
 31 *                                                                           *
 32 *****************************************************************************/
 33
 34package bsh;
 35
 36import java.util.*;
 37
 38public class StringUtil {
 39
 40	public static String [] split( String s, String delim) {
 41		Vector v = new Vector();
 42		StringTokenizer st = new StringTokenizer(s, delim);
 43		while ( st.hasMoreTokens() )
 44			v.addElement( st.nextToken() );
 45		String [] sa = new String [ v.size() ];
 46		v.copyInto( sa );
 47		return sa;
 48	}
 49
 50	public static String [] bubbleSort( String [] in ) {
 51		Vector v = new Vector();
 52		for(int i=0; i<in.length; i++)
 53			v.addElement(in[i]);
 54
 55		int n = v.size();
 56		boolean swap = true;
 57		while ( swap ) {
 58			swap = false;
 59			for(int i=0; i<(n-1); i++)
 60				if ( ((String)v.elementAt(i)).compareTo(
 61						((String)v.elementAt(i+1)) ) > 0 ) {
 62					String tmp = (String)v.elementAt(i+1);
 63					v.removeElementAt( i+1 );
 64					v.insertElementAt( tmp, i );
 65					swap = true;
 66				}
 67		}
 68
 69		String [] out = new String [ n ];
 70		v.copyInto(out);
 71		return out;
 72	}
 73
 74
 75	public static String maxCommonPrefix( String one, String two ) {
 76		int i=0;
 77		while( one.regionMatches( 0, two, 0, i ) )
 78			i++;
 79		return one.substring(0, i-1);
 80	}
 81
 82	// Clean this up later...
 83    public static String methodString(String name, Class[] types)
 84    {
 85        StringBuffer sb = new StringBuffer(name + "(");
 86        if(types.length > 0)
 87			sb.append(" ");
 88        for(int i=0; i<(types.length - 1); i++)
 89        {
 90            Class c = types[i];
 91            sb.append(((c == null) ? "null" : c.getName()) + ", ");
 92        }
 93        if(types.length > 0)
 94        {
 95            Class c = types[types.length - 1];
 96            sb.append(((c == null) ? "null" : c.getName()));
 97			sb.append(" ");
 98        }
 99        sb.append(")");
100        return sb.toString();
101    }
102
103	/**
104		Split a filename into dirName, baseName
105		@return String [] { dirName, baseName }
106    public String [] splitFileName( String fileName ) 
107	{ 
108		String dirName, baseName;
109		int i = fileName.lastIndexOf( File.separator );
110		if ( i != -1 ) {
111			dirName = fileName.substring(0, i);
112			baseName = fileName.substring(i+1);
113		} else
114			baseName = fileName;
115
116		return new String[] { dirName, baseName };
117	}
118
119	*/
120}