/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package se.gbif.bourgogne.utilities;
import org.apache.commons.lang3.StringUtils;
/**
*
* @author korbinus
*/
public class Strings {
/**
* Represents a failed index search. Stolen from
* org.apache.commons.lang3.StringUtils
*
*/
private final static int INDEX_NOT_FOUND = -1;
/**
* Replace awful Unicode errors with beautiful letters.
* Although StringUtils.replace() checks if a sequence is present in the provided
* string, we check first in order to avoid useless calls.
*
* @param String
* @return String
*/
public static String unscramble(String str) {
// Å å
if (str.indexOf("Ã…") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ã…", "Å");
}
if (str.indexOf("Ã¥") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ã¥", "å");
}
// Ä ä
if (str.indexOf("Ä") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ä", "Ä");
}
if (str.indexOf("ä") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ä", "ä");
}
// Ö ö
if (str.indexOf("Ö") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ö", "Ö");
}
if (str.indexOf("ö") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ö", "ö");
}
// Ø ø
if (str.indexOf("Ø") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ø", "Ø");
}
if (str.indexOf("ø") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ø", "ø");
}
// É é
if (str.indexOf("É") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "É", "É");
}
if (str.indexOf("é") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "é", "é");
}
// Ë ë (yes Mickaël writes here)
if (str.indexOf("Ë") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ë", "Ë");
}
if (str.indexOf("ë") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ë", "ë");
}
// È è
if (str.indexOf("È") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "È", "È");
}
if (str.indexOf("è") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "è", "è");
}
// Ê ê
if (str.indexOf("Ê") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ê", "Ê");
}
if (str.indexOf("ê") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ê", "ê");
}
// À à
if (str.indexOf("À") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "À", "À");
}
if (str.indexOf("\u00C3\u00A0") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "\u00C3\u00A0", "à");
}
// Ã ã
if (str.indexOf("Ã") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ã", "Ã");
}
if (str.indexOf("ã") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ã", "ã");
}
// Á á
if (str.indexOf("\u00C3\u0081") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "\u00C3\u0081", "Á");
}
if (str.indexOf("á") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "á", "á");
}
// Â â
if (str.indexOf("Â") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Â", "Â");
}
if (str.indexOf("â") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "â", "â");
}
// Ü ü
if (str.indexOf("Ü") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ü", "Ü");
}
if (str.indexOf("ü") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ü", "ü");
}
// Ù ù
if (str.indexOf("Ù") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ù", "Ù");
}
if (str.indexOf("ù") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ù", "ù");
}
// Ú ú
if (str.indexOf("Ú") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ú", "Ú");
}
if (str.indexOf("ú") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ú", "ú");
}
// Û û
if (str.indexOf("Û") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Û", "Û");
}
if (str.indexOf("û") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "û", "û");
}
// Ñ ñ
if (str.indexOf("Ñ") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ñ", "Ñ");
}
if (str.indexOf("ñ") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ñ", "ñ");
}
// Ç ç
if (str.indexOf("Ç") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ç", "Ç");
}
if (str.indexOf("ç") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ç", "ç");
}
// Ò ò
if (str.indexOf("Ã’") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ã’", "Ò");
}
if (str.indexOf("ò") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ò", "ò");
}
// Ó ó
if (str.indexOf("Ó") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ó", "Ó");
}
if (str.indexOf("ó") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ó", "ó");
}
// Ô ô
if (str.indexOf("Ô") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ô", "Ô");
}
if (str.indexOf("ô") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ô", "ô");
}
// Õ õ
if (str.indexOf("Õ") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Õ", "Õ");
}
if (str.indexOf("õ") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "õ", "õ");
}
// Ì ì
if (str.indexOf("Ì") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ÃŒ", "Ì");
}
if (str.indexOf("ì") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ì", "ì");
}
// Í í
if (str.indexOf("\u00C3\u008D") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "\u00C3\u008D", "Í");
}
if (str.indexOf("Ã") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ã", "í");
}
// Ï ï
if (str.indexOf("\u00C3\u008F") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "\u00C3\u008F", "Ï");
}
if (str.indexOf("ï") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ï", "ï");
}
// Î î
if (str.indexOf("ÃŽ") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ÃŽ", "Î");
}
if (str.indexOf("î") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "î", "î");
}
// Ð
if (str.indexOf("\u00C3\u0090") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "\u00C3\u0090", "Ð");
}
// Æ æ
if (str.indexOf("Æ") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Æ", "Æ");
}
if (str.indexOf("æ") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "æ", "æ");
}
// Œ œ
if (str.indexOf("Å’") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Å’", "Œ");
}
if (str.indexOf("Å“") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Å“", "œ");
}
// ð
if (str.indexOf("ð") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ð", "ð");
}
// ß
if (str.indexOf("ß") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ß", "ß");
}
// Ý ý
if (str.indexOf("\u00C3\u009D") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "\u00C3\u009D", "Ý");
}
if (str.indexOf("ý") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ý", "ý");
}
// Ÿ ÿ
if (str.indexOf("Ÿ") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ÿ", "Ÿ");
}
if (str.indexOf("ÿ") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ÿ", "ÿ");
}
// Ž ž
if (str.indexOf("Ž") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Ž", "Ž");
}
if (str.indexOf("ž") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "ž", "ž");
}
// Þ
if (str.indexOf("Þ") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "Þ", "Þ");
}
// þ
if (str.indexOf("þ") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "þ", "þ");
}
// ×
if (str.indexOf("×") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "×", "×");
}
// ÷
if (str.indexOf("÷") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "÷", "÷");
}
// °
if (str.indexOf("°") > INDEX_NOT_FOUND) {
str = StringUtils.replace(str, "°", "°");
}
return str;
}
}