Java String Upper Case toUppercaseNoAccents(String txt)

Here you can find the source of toUppercaseNoAccents(String txt)

Description

to Uppercase No Accents

License

Open Source License

Declaration

public static String toUppercaseNoAccents(String txt) 

Method Source Code

//package com.java2s;
//    it under the terms of the GNU General Public License as published by

public class Main {
    private static final String UPPERCASE_ASCII = "AEIOU" // grave
            + "AEIOUY" // acute
            + "AEIOUY" // circumflex
            + "AON" // tilde
            + "AEIOUY" // umlaut
            + "A" // ring
            + "C" // cedilla
            + "OU" // double acute
    ;/*from ww w  .  jav  a2 s .c  om*/
    private static final String UPPERCASE_UNICODE = "\u00C0\u00C8\u00CC\u00D2\u00D9"
            + "\u00C1\u00C9\u00CD\u00D3\u00DA\u00DD" + "\u00C2\u00CA\u00CE\u00D4\u00DB\u0176" + "\u00C3\u00D5\u00D1"
            + "\u00C4\u00CB\u00CF\u00D6\u00DC\u0178" + "\u00C5" + "\u00C7" + "\u0150\u0170";

    public static String toUppercaseNoAccents(String txt) {
        if (txt == null) {
            return null;
        }
        String txtUpper = txt.toUpperCase();
        StringBuilder sb = new StringBuilder();
        int n = txtUpper.length();
        for (int i = 0; i < n; i++) {
            char c = txtUpper.charAt(i);
            int pos = UPPERCASE_UNICODE.indexOf(c);
            if (pos > -1) {
                sb.append(UPPERCASE_ASCII.charAt(pos));
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }
}

Related

  1. toUpperCaseHead(String str)
  2. toUppercaseHeadCharactor(String str)
  3. toUpperCaseIdent(String ident)
  4. toUpperCaseName(String s)
  5. toUpperCaseNamespace(String string)
  6. toUpperCaseNotation(String camelNotation)
  7. toUpperCaseOfFirstChar(String string)
  8. toUpperCaseUnderscore(String text)
  9. toUpperCaseWithUnderscores(String className)