Skip to content

Instantly share code, notes, and snippets.

@0guzhan
Created January 30, 2013 21:43
Show Gist options
  • Save 0guzhan/4677372 to your computer and use it in GitHub Desktop.
Save 0guzhan/4677372 to your computer and use it in GitHub Desktop.
Useful utility class for those needs to convert turkish specific characters to english counterparts on runtime of java applications. Due to some encoding problems it is difficult to manage or it is required by business needs. I hope, it helps...
/**
* A no non-sense preclusive method
* for converting Turkish alphabet specific characters
* into English counterparts.
*
* @param turkishContent non-null String possible includes turkish specific characters
*
* @return equivalent of input string in English alphabet
*
* @throws IllegalArgumentException if parameter is null
*
* @author oguzhan.acargil
*
* @see http://0guzhan.blogspot.com
* */
public static String toEnglish(String turkishContent) {
if (turkishContent != null) {
char[] trContentArray = turkishContent.toCharArray();
int contentLength = trContentArray.length;
for (int index = 0; index < contentLength; index++) {
if('\u00e7' == trContentArray[index]) {
trContentArray[index] = 'c';
}
if('\u011f' == trContentArray[index]) {
trContentArray[index] = 'g';
}
if('\u0131' == trContentArray[index]) {
trContentArray[index] = 'i';
}
if('\u00f6' == trContentArray[index]) {
trContentArray[index] = 'o';
}
if('\u015f' == trContentArray[index]) {
trContentArray[index] = 's';
}
if('\u00fc' == trContentArray[index]) {
trContentArray[index] = 'u';
}
// end of lower cases
if('\u00c7' == trContentArray[index]) {
trContentArray[index] = 'C';
}
if('\u011e' == trContentArray[index]) {
trContentArray[index] = 'G';
}
if('\u0130' == trContentArray[index]) {
trContentArray[index] = 'I';
}
if('\u00d6' == trContentArray[index]) {
trContentArray[index] = 'O';
}
if('\u015e' == trContentArray[index]) {
trContentArray[index] = 'S';
}
if('\u00dc' == trContentArray[index]) {
trContentArray[index] = 'U';
}
// end of upper cases
}
return new String(trContentArray);
}
else {
throw new IllegalArgumentException("toEnglish(String) received null parameter!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment