Révision 2495
tmp/org.txm.utils/src/org/txm/utils/AsciiUtils.java (revision 2495) | ||
---|---|---|
27 | 27 |
// |
28 | 28 |
package org.txm.utils; |
29 | 29 |
|
30 |
import com.ibm.icu.text.Transliterator; |
|
31 |
|
|
30 | 32 |
/** |
31 | 33 |
* The Class AsciiUtils. |
32 | 34 |
* |
... | ... | |
85 | 87 |
public static String convertNonAscii(String s) { |
86 | 88 |
if (s == null) |
87 | 89 |
return null; |
88 |
StringBuilder sb = new StringBuilder(); |
|
89 |
int n = s.length(); |
|
90 |
for (int i = 0; i < n; i++) { |
|
91 |
char c = s.charAt(i); |
|
92 |
int pos = UNICODE.indexOf(c); |
|
93 |
if (pos > -1) { |
|
94 |
sb.append(PLAIN_ASCII.charAt(pos)); |
|
95 |
} else { |
|
96 |
sb.append(c); |
|
97 |
} |
|
98 |
} |
|
99 |
return sb.toString(); |
|
90 |
|
|
91 |
String id = "Any-Latin; NFD; [^\\p{Alnum}] Remove"; |
|
92 |
String latin = Transliterator.getInstance(id).transform(s); |
|
93 |
|
|
94 |
// StringBuilder sb = new StringBuilder(); |
|
95 |
// int n = s.length(); |
|
96 |
// for (int i = 0; i < n; i++) { |
|
97 |
// char c = s.charAt(i); |
|
98 |
// int pos = UNICODE.indexOf(c); |
|
99 |
// if (pos > -1) { |
|
100 |
// sb.append(PLAIN_ASCII.charAt(pos)); |
|
101 |
// } else { |
|
102 |
// sb.append(c); |
|
103 |
// } |
|
104 |
// } |
|
105 |
return latin; |
|
100 | 106 |
} |
101 | 107 |
|
102 | 108 |
/** |
... | ... | |
186 | 192 |
* the arguments |
187 | 193 |
*/ |
188 | 194 |
public static void main(String args[]) { |
189 |
String s = "The result : È,É,Ê,Ë,Û,Ù,Ï,Î,À,Â,Ô,è,é,ê,ë,û,ù,ï,î,à,â,ô,ç "; //$NON-NLS-1$
|
|
195 |
String s = "01The result : È,É,Ê,Ë,Û,Ù,Ï,Î,À,Â,Ô,è,é,ê,ë,û,ù,ï,î,à,â,ô,ç 0 1 2 3 4 5 6 7 8 9 10"; //$NON-NLS-1$
|
|
190 | 196 |
System.out.println(AsciiUtils.convertNonAscii(s)); |
191 | 197 |
System.out.println(AsciiUtils.buildId(s)); |
192 | 198 |
// output : |
Formats disponibles : Unified diff