oops I ve put the wrong file here is the right one. Anyways, I am more interresting in:
/*replace occurence functions such as "hello {1}, bonjour (2)" */ - replace( String text, String with1 ) - replace( String text, String with1, String with2 ) - ... /* convert a latin-X string to ASCII string. e.g. à -> a ... */ - public static String toAlphaNumeric ( String str ) Thomas UNG a écrit : > > Hi Scott, > > > > I am interrested because I ve wrote my own one. I ve put it in the > > attachment. Feel free to pick anything if you thing that it is > > interresting. However, some of them are not optimized. > > > > Kind Regards, > > Thomas
package com.bobo.utils.lang; import org.apache.commons.lang.StringUtils; public class String2ReplaceUtils extends StringUtils { private static final String arg1 = "{1}"; private static final String arg2 = "{2}"; private static final String arg3 = "{3}"; private static final String arg4 = "{4}"; private static final String arg5 = "{5}"; private static final String arg6 = "{6}"; private static final String arg7 = "{7}"; private static final String arg8 = "{8}"; private static final String arg9 = "{9}"; private static final int MAX_OCCURENCE = 1; /** * TODO - optimization */ public static String replace( String text, String with1 ) { return StringUtils.replace(text, arg1, with1, MAX_OCCURENCE); } public static String replace( String text, String with1, String with2 ) { String result = StringUtils.replace( text, arg1, with1, MAX_OCCURENCE ); return StringUtils.replace( result, arg2, with2, MAX_OCCURENCE ); } public static String replace( String text, String with1, String with2, String with3 ) { String result = StringUtils.replace( text, arg1, with1, MAX_OCCURENCE ); result = StringUtils.replace( result, arg2, with2, MAX_OCCURENCE ); return StringUtils.replace( result, arg3, with3, MAX_OCCURENCE ); } public static String replace( String text, String with1, String with2, String with3, String with4 ) { String result = StringUtils.replace( text, arg1, with1 ); result = StringUtils.replace( result, arg2, with2, MAX_OCCURENCE ); result = StringUtils.replace( result, arg3, with3, MAX_OCCURENCE ); return StringUtils.replace( result, arg4, with4, MAX_OCCURENCE ); } public static String replace( String text, String with1, String with2, String with3, String with4, String with5 ) { String result = StringUtils.replace( text, arg1, with1 ); result = StringUtils.replace( result, arg2, with2, MAX_OCCURENCE ); result = StringUtils.replace( result, arg3, with3, MAX_OCCURENCE ); result = StringUtils.replace( result, arg4, with4, MAX_OCCURENCE ); return StringUtils.replace( result, arg5, with5, MAX_OCCURENCE ); } public static String replace( String text, String with1, String with2, String with3, String with4, String with5, String with6 ) { String result = StringUtils.replace( text, arg1, with1 ); result = StringUtils.replace( result, arg2, with2, MAX_OCCURENCE ); result = StringUtils.replace( result, arg3, with3, MAX_OCCURENCE ); result = StringUtils.replace( result, arg4, with4, MAX_OCCURENCE ); result = StringUtils.replace( result, arg5, with5, MAX_OCCURENCE ); return StringUtils.replace( result, arg6, with6, MAX_OCCURENCE ); } public static String replace( String text, String with1, String with2, String with3, String with4, String with5, String with6, String with7) { String result = StringUtils.replace( text, arg1, with1 ); result = StringUtils.replace( result, arg2, with2, MAX_OCCURENCE ); result = StringUtils.replace( result, arg3, with3, MAX_OCCURENCE ); result = StringUtils.replace( result, arg4, with4, MAX_OCCURENCE ); result = StringUtils.replace( result, arg5, with5, MAX_OCCURENCE ); result = StringUtils.replace( result, arg6, with6, MAX_OCCURENCE ); return StringUtils.replace( result, arg7, with7, MAX_OCCURENCE ); } public static String replace( String text, String with1, String with2, String with3, String with4, String with5, String with6, String with7, String with8) { String result = StringUtils.replace( text, arg1, with1 ); result = StringUtils.replace( result, arg2, with2, MAX_OCCURENCE ); result = StringUtils.replace( result, arg3, with3, MAX_OCCURENCE ); result = StringUtils.replace( result, arg4, with4, MAX_OCCURENCE ); result = StringUtils.replace( result, arg5, with5, MAX_OCCURENCE ); result = StringUtils.replace( result, arg6, with6, MAX_OCCURENCE ); result = StringUtils.replace( result, arg7, with7, MAX_OCCURENCE ); return StringUtils.replace( result, arg8, with8, MAX_OCCURENCE ); } public static String replace( String text, String with1, String with2, String with3, String with4, String with5, String with6, String with7, String with8, String with9) { String result = StringUtils.replace( text, arg1, with1 ); result = StringUtils.replace( result, arg2, with2, MAX_OCCURENCE ); result = StringUtils.replace( result, arg3, with3, MAX_OCCURENCE ); result = StringUtils.replace( result, arg4, with4, MAX_OCCURENCE ); result = StringUtils.replace( result, arg5, with5, MAX_OCCURENCE ); result = StringUtils.replace( result, arg6, with6, MAX_OCCURENCE ); result = StringUtils.replace( result, arg7, with7, MAX_OCCURENCE ); result = StringUtils.replace( result, arg8, with8, MAX_OCCURENCE ); return StringUtils.replace( result, arg9, with9, MAX_OCCURENCE ); } public static String replaceAll( String text, String with1 ) { return StringUtils.replace(text, arg1, with1); } public static String replaceAll( String text, String with1, String with2 ) { String result = StringUtils.replace( text, arg1, with1 ); return StringUtils.replace( result, arg2, with2 ); } public static String replaceAll( String text, String with1, String with2, String with3 ) { String result = StringUtils.replace( text, arg1, with1 ); result = StringUtils.replace( result, arg2, with2 ); return StringUtils.replace( result, arg3, with3 ); } public static String replaceAll( String text, String with1, String with2, String with3, String with4 ) { String result = StringUtils.replace( text, arg1, with1 ); result = StringUtils.replace( result, arg2, with2 ); result = StringUtils.replace( result, arg3, with3 ); return StringUtils.replace( result, arg4, with4 ); } public static String replaceAll( String text, String with1, String with2, String with3, String with4, String with5 ) { String result = StringUtils.replace( text, arg1, with1 ); result = StringUtils.replace( result, arg2, with2 ); result = StringUtils.replace( result, arg3, with3 ); result = StringUtils.replace( result, arg4, with4 ); return StringUtils.replace( result, arg5, with5 ); } public static String replaceAll( String text, String with1, String with2, String with3, String with4, String with5, String with6 ) { String result = StringUtils.replace( text, arg1, with1 ); result = StringUtils.replace( result, arg2, with2 ); result = StringUtils.replace( result, arg3, with3 ); result = StringUtils.replace( result, arg4, with4 ); result = StringUtils.replace( result, arg5, with5 ); return StringUtils.replace( result, arg6, with6 ); } public static String replaceAll( String text, String with1, String with2, String with3, String with4, String with5, String with6, String with7) { String result = StringUtils.replace( text, arg1, with1 ); result = StringUtils.replace( result, arg2, with2 ); result = StringUtils.replace( result, arg3, with3 ); result = StringUtils.replace( result, arg4, with4 ); result = StringUtils.replace( result, arg5, with5 ); result = StringUtils.replace( result, arg6, with6 ); return StringUtils.replace( result, arg7, with7 ); } public static String replaceAll( String text, String with1, String with2, String with3, String with4, String with5, String with6, String with7, String with8) { String result = StringUtils.replace( text, arg1, with1 ); result = StringUtils.replace( result, arg2, with2 ); result = StringUtils.replace( result, arg3, with3 ); result = StringUtils.replace( result, arg4, with4 ); result = StringUtils.replace( result, arg5, with5 ); result = StringUtils.replace( result, arg6, with6 ); result = StringUtils.replace( result, arg7, with7 ); return StringUtils.replace( result, arg8, with8 ); } public static String replaceAll( String text, String with1, String with2, String with3, String with4, String with5, String with6, String with7, String with8, String with9) { String result = StringUtils.replace( text, arg1, with1 ); result = StringUtils.replace( result, arg2, with2 ); result = StringUtils.replace( result, arg3, with3 ); result = StringUtils.replace( result, arg4, with4 ); result = StringUtils.replace( result, arg5, with5 ); result = StringUtils.replace( result, arg6, with6 ); result = StringUtils.replace( result, arg7, with7 ); result = StringUtils.replace( result, arg8, with8 ); return StringUtils.replace( result, arg9, with9 ); } /** * Convert unicode str to allowed ascii caracter set * ONLY SET FOR LATIN CONVERSION!!! * * a-z, A-Z, 0-9, - * 61-7A,u41-5A,u30-u39,u2D * * REMOVE FORBIDDEN CARACTERS * @param str * @return */ public static String toAlphaNumeric ( String str ) { char [] chars = str.toCharArray(); StringBuffer result = new StringBuffer(); for( int i=0; i<chars.length; i++) { result.append( toAlphaNumeric ( chars[i] ) ); } return result.toString(); } /** * Considered to be 'alpha numeric': * a-z, A-Z, 0-9, - * * http://fr.wikipedia.org/wiki/Latin-1 * TODO - perf, bit optimization * @param c * @return */ public static char toAlphaNumeric ( char c ) { //a-z if( c >= '\u0061' && c <= '\u007A' ) return c; //A-Z if( c >= '\u0041' && c <= '\u005A' ) return c; //0-9 if( c >= '\u0030' && c <= '\u0039' ) return c; //- if( c == '\u002D' ) return c; //all kind of 'A' + ae if( (c >= '\u00C0' && c <= '\u00C6') || (c >= '\u00E0' && c <= '\u00E6') ) return '\u0061'; //all kind of 'E' if( (c >= '\u00C8' && c <= '\u00CB') || (c >= '\u00E8' && c <= '\u00EB')) return '\u0065'; //all kind of 'i' if( (c >= '\u00CC' && c <= '\u00CF') || (c >= '\u00EC' && c <= '\u00EF')) return '\u0069'; //all kind of c if( c == '\u00C7' || c == '\u00E7' ) return '\u0063'; //all kind of 'o' if( (c >= '\u00D2' && c <= '\u00D6') || (c >= '\u00F2' && c <= '\u00F6') || c == '\u00D0' || c == '\u00F0') return '\u006F'; //all kind of 'u' if( (c >= '\u00D9' && c <= '\u00DC') || (c >= '\u00F9' && c <= '\u00FC')) return '\u006F'; //all kind of 'y' if( c == '\u00DD' || c == '\u00FD' || c == '\u00FF' ) return '\u0079'; //all kind of n if( c == '\u00D1' || c == '\u00F1') return '\u006E'; //'b z' allemand if( c == '\u00DF' ) return '\u0062'; //autres empty return ' '; } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]