Index: lutinutil/src/java/org/codelutin/util/StringUtil.java diff -u lutinutil/src/java/org/codelutin/util/StringUtil.java:1.17 lutinutil/src/java/org/codelutin/util/StringUtil.java:1.18 --- lutinutil/src/java/org/codelutin/util/StringUtil.java:1.17 Fri Jun 8 13:28:33 2007 +++ lutinutil/src/java/org/codelutin/util/StringUtil.java Fri Jun 8 13:36:30 2007 @@ -1,32 +1,32 @@ /* *##%% -* Copyright (C) 2002, 2003 Code Lutin -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*##%%**/ + * Copyright (C) 2002, 2003 Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%%**/ /* * -* StringUtil.java -* -* Created: Sun Apr 14 2002 -* -* @author POUSSIN Benjamin -* Copyright Code Lutin -* @version $Revision: 1.17 $ -* -* Mise a jour: $Date: 2007/06/08 13:28:33 $ -* par : $Author: bpoussin $ -*/ + * StringUtil.java + * + * Created: Sun Apr 14 2002 + * + * @author POUSSIN Benjamin + * Copyright Code Lutin + * @version $Revision: 1.18 $ + * + * Mise a jour: $Date: 2007/06/08 13:36:30 $ + * par : $Author: thimel $ + */ package org.codelutin.util; import java.awt.Color; @@ -42,38 +42,47 @@ * Classe contenant un ensemle de m?thode static utiles pour la manipulation des * cha?ne de caract?re mais qui ne sont pas d?fini dans la classe String de * Java. - * - *@author poussin - *@created 21 octobre 2003 + * + * @author poussin + * @created 21 octobre 2003 */ public class StringUtil { // StringUtil /** Constructor for the StringUtil object */ protected StringUtil() { } - + static public String unaccent(String s) { String result = ""; - for (char c: s.toCharArray()) { + for (char c : s.toCharArray()) { if ("éèêë".indexOf(c) != -1) { result += "e"; } else if ("àäâ".indexOf(c) != -1) { result += "a"; - } else if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')) { + } else if ("ç".indexOf(c) != -1) { + result += "c"; + } else if ("îï".indexOf(c) != -1) { + result += "i"; + } else if ("ôö".indexOf(c) != -1) { + result += "a"; + } else if ("ùûü".indexOf(c) != -1) { + result += "u"; + } else if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') + || ('0' <= c && c <= '9')) { result += c; } else { // on ne l'ajoute pas a result donc on supprime le caractere -// result += encodeUTF(c); + // result += encodeUTF(c); } } return result; } - + static public String substring(String s, int begin) { String result = substring(s, begin, s.length()); return result; } - + static public String substring(String s, int begin, int end) { if (begin < 0) { begin = s.length() + begin; @@ -85,16 +94,18 @@ end = begin; } - String result = s.substring(begin, end); + String result = s.substring(begin, end); return result; } /** * Met en majuscule le premier caract?re de la cha?ne pass? en param?tre - * - * @param word La cha?ne ? capitaliser - * @return La cha?ne capitalis?e - * @deprecated you must use org.apache.commons.lang.StringUtils.capitalise(String) + * + * @param word + * La cha?ne ? capitaliser + * @return La cha?ne capitalis?e + * @deprecated you must use + * org.apache.commons.lang.StringUtils.capitalise(String) */ public static String capitalize(String word) { return word.substring(0, 1).toUpperCase() + word.substring(1); @@ -102,10 +113,12 @@ /** * Met en minuscule le premier caract?re de la cha?ne pass? en param?tre - * - *@param word La cha?ne ? decapitaliser - *@return La cha?ne decapitalis?e - * @deprecated you must use org.apache.commons.lang.StringUtils.uncapitalise(String) + * + * @param word + * La cha?ne ? decapitaliser + * @return La cha?ne decapitalis?e + * @deprecated you must use + * org.apache.commons.lang.StringUtils.uncapitalise(String) */ public static String uncapitalize(String word) { return word.substring(0, 1).toLowerCase() + word.substring(1); @@ -113,11 +126,13 @@ /** * Concat?ne un tableau de cha?ne de caract?res en une seul cha?ne. - * - *@param s le tableau de cha?nes - *@param sep le s?parateur ? utiliser pour s?parer chaque cha?ne. - *@return la cha?ne r?sultante de la concat?nation. Si le tableau est - * null ou vide, la cha?ne r?sultante est une chaine vide. + * + * @param s + * le tableau de cha?nes + * @param sep + * le s?parateur ? utiliser pour s?parer chaque cha?ne. + * @return la cha?ne r?sultante de la concat?nation. Si le tableau est null + * ou vide, la cha?ne r?sultante est une chaine vide. * @deprecated you must use org.apache.commons.lang.StringUtils.join */ public static String unsplit(String[] s, String sep) { @@ -133,27 +148,29 @@ } /** - * Split string use 'separator' as separator. If String contains "'()[]{} this - * method count the number of open char end close char to split correctly - * argument + * Split string use 'separator' as separator. If String contains "'()[]{} + * this method count the number of open char end close char to split + * correctly argument * - * @param args string to split - * @param separator separator use to split string + * @param args + * string to split + * @param separator + * separator use to split string * @return array of string */ - static public String [] split(String args, String separator) { + static public String[] split(String args, String separator) { if (args == null) { return new String[0]; } - + List result = new ArrayList(); - + int start = 0; int end = 0; StringBuffer op = new StringBuffer(); // stack of {([ currently open char last = '\0'; // contains " or ' if string is openned - for (int i=0; i 0 if listAsString != null or null */ - static public String [] split(String stringList) { - String [] result = split(stringList, ","); + static public String[] split(String stringList) { + String[] result = split(stringList, ","); return result; } - public static boolean toBoolean(String s){ + public static boolean toBoolean(String s) { return "true".equalsIgnoreCase(s); } - public static byte toByte(String s){ + public static byte toByte(String s) { return Byte.parseByte(s); } - public static double toDouble(String s){ + public static double toDouble(String s) { return Double.parseDouble(s); } - public static float toFloat(String s){ + public static float toFloat(String s) { return Float.parseFloat(s); } - public static long toLong(String s){ + public static long toLong(String s) { return Long.parseLong(s); } - public static short toShort(String s){ + public static short toShort(String s) { return Short.parseShort(s); } - public static int toInt(String s){ + public static int toInt(String s) { return Integer.parseInt(s); } - public static char toChar(String s){ - //fixme a revoir - return s.charAt(0) ; + public static char toChar(String s) { + // fixme a revoir + return s.charAt(0); } - public static boolean [] toArrayBoolean(String ... s){ - boolean [] result = new boolean[s.length]; - for (int i=0; i factors[i] ){ + while (i < factors.length && i < unites.length && tmp > factors[i]) { tmp = tmp / factors[i++]; } tmp *= sign; - String result = MessageFormat.format("{0,number,0.###}{1}", tmp, unites[i]); + String result = MessageFormat.format("{0,number,0.###}{1}", tmp, + unites[i]); return result; }