From 08cf9720e820ef83949c8ce1c4204f40ab84bf4f Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 25 Jun 2013 02:40:19 +0000 Subject: [PATCH] * simplify csv lookup and replacement of values based on csv mappings --- .../net/sourceforge/filebot/format/ExpressionFormat.lib.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/source/net/sourceforge/filebot/format/ExpressionFormat.lib.groovy b/source/net/sourceforge/filebot/format/ExpressionFormat.lib.groovy index a73e2614..940c6e81 100644 --- a/source/net/sourceforge/filebot/format/ExpressionFormat.lib.groovy +++ b/source/net/sourceforge/filebot/format/ExpressionFormat.lib.groovy @@ -5,6 +5,7 @@ import java.util.regex.Pattern // simplified switch/case pattern matching Object.metaClass.match = { Map cases -> def val = delegate; cases.findResult { switch(val) { case it.key: return it.value} } } +def csv(path, delim = ';', keyIndex = 0, valueIndex = 1) { def f = path as File; def values = [:]; f.splitEachLine(delim) { values.put(it[keyIndex], it[valueIndex]) }; return values } def c(c) { try { c.call() } catch (Throwable e) { null } }