From f50e0450c62ace23528893c53f654e3e736e3736 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 10 Oct 2012 16:15:04 +0000 Subject: [PATCH] * helper for enforcing filename length limits --- source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy index 6d6eaad6..bda93902 100644 --- a/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy +++ b/source/net/sourceforge/filebot/cli/ScriptShell.lib.groovy @@ -51,6 +51,9 @@ String.metaClass.hasExtension = { String... ext -> hasExtension(delegate, ext) } String.metaClass.validateFileName = { validateFileName(delegate) } String.metaClass.validateFilePath = { validateFilePath(delegate) } +// helper for enforcing filename length limits, e.g. truncate filename but keep extension +String.metaClass.truncateFileName = { int limit = 255 -> def ext = getExtension(delegate); def name = getNameWithoutExtension(delegate); return name.substring(0, Math.min(limit - (ext ? 1+ext.length() : 0), name.length())) + (ext ? '.'+ext : '') } + // Parallel helper import java.util.concurrent.*