Skip to content

Instantly share code, notes, and snippets.

@jprante
Created February 11, 2015 13:54
Show Gist options
  • Save jprante/3ef160e916c452df5e79 to your computer and use it in GitHub Desktop.
Save jprante/3ef160e916c452df5e79 to your computer and use it in GitHub Desktop.
Detect latin/greek characters
def file = new File('names.txt')
file.eachLine { line ->
if (line.length() > 16) {
line = line.substring(16)
line.tokenize('$').each { word ->
word = word.substring(1)
print word
def latin = false
def greek = false
word.replaceAll("\\p{C}","").replaceAll("\\p{Space}","").replaceAll("\\p{Punct}","").toCharArray().each { c ->
def i = c as int
if (i > 32 && i < 256) {
latin = true
}
else if (i > 0x0370 && i < 0x0400) {
greek = true
}
else {
print " not latin/greek char:" << Integer.toHexString(i)
}
}
if (latin) {
print " latin"
}
if (greek) {
print " greek"
}
print "\n"
}
print "\n"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment