From 56d1892e2439ae1b03e45c5215edafcc6e4d22d5 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 23 Dec 2013 02:12:36 +0000 Subject: [PATCH] * replace multiple replacement pairs --- .../filebot/format/ExpressionFormat.lib.groovy | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/source/net/sourceforge/filebot/format/ExpressionFormat.lib.groovy b/source/net/sourceforge/filebot/format/ExpressionFormat.lib.groovy index 65e5e23a..38fb510a 100644 --- a/source/net/sourceforge/filebot/format/ExpressionFormat.lib.groovy +++ b/source/net/sourceforge/filebot/format/ExpressionFormat.lib.groovy @@ -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) } +/** + * 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