* replace multiple replacement pairs

This commit is contained in:
Reinhard Pointner 2013-12-23 02:12:36 +00:00
parent 878f311cae
commit 56d1892e24
1 changed files with 16 additions and 0 deletions

View File

@ -168,6 +168,22 @@ String.metaClass.transliterate = { transformIdentifier -> com.ibm.icu.text.Trans
String.metaClass.ascii = { fallback = ' ' -> delegate.transliterate("Any-Latin;Latin-ASCII;[:Diacritic:]remove").replaceAll("[^\\p{ASCII}]+", fallback) } String.metaClass.ascii = { fallback = ' ' -> delegate.transliterate("Any-Latin;Latin-ASCII;[:Diacritic:]remove").replaceAll("[^\\p{ASCII}]+", fallback) }
/**
* Replace multiple replacement pairs
*
* e.g. replace('ä', 'ae', 'ö', 'oe', 'ü', 'ue')
*/
String.metaClass.replace = { String... tr ->
String s = delegate;
for (int i = 0; i < tr.length-1; i+=2) {
CharSequence t = tr[i]
CharSequence r = tr[i+1]
s = s.replace(t, r)
}
return s
}
/** /**
* General helpers and utilities * General helpers and utilities