| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package uk.me.parabola.imgfmt.app.labelenc; |
| 18 |
|
| 19 |
import java.util.Locale; |
| 20 |
import java.nio.charset.StandardCharsets; |
| 21 |
import java.text.Normalizer; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class Utf8Encoder extends BaseEncoder implements CharacterEncoder { |
| 29 |
|
| 30 |
public EncodedText encodeText(String text) { |
| 31 |
if (text == null || text.isEmpty()) |
| 32 |
return NO_TEXT; |
| 33 |
|
| 34 |
String uctext; |
| 35 |
if (isUpperCase()) |
| 36 |
uctext = text.toUpperCase(Locale.ENGLISH); |
| 37 |
else |
| 38 |
uctext = text; |
| 39 |
uctext = Normalizer.normalize(uctext, Normalizer.Form.NFC); |
| 40 |
|
| 41 |
EncodedText et; |
| 42 |
byte[] buf = uctext.getBytes(StandardCharsets.UTF_8); |
| 43 |
byte[] res = new byte[buf.length + 1]; |
| 44 |
System.arraycopy(buf, 0, res, 0, buf.length); |
| 45 |
res[buf.length] = 0; |
| 46 |
et = new EncodedText(res, res.length, uctext.toCharArray()); |
| 47 |
return et; |
| 48 |
} |
| 49 |
} |