From 94a380384f0ecd0eee3bf979d8a9f2ff8f4c56a7 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 25 Jun 2014 10:28:15 +0000 Subject: [PATCH] * force all \s+ to single space char --- source/net/filebot/format/ExpressionFormat.java | 3 ++- source/net/filebot/similarity/Normalization.java | 13 ++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/source/net/filebot/format/ExpressionFormat.java b/source/net/filebot/format/ExpressionFormat.java index 1c0a70d5..1b7da84a 100644 --- a/source/net/filebot/format/ExpressionFormat.java +++ b/source/net/filebot/format/ExpressionFormat.java @@ -1,5 +1,6 @@ package net.filebot.format; +import static net.filebot.similarity.Normalization.*; import static net.filebot.util.ExceptionUtilities.*; import static net.filebot.util.FileUtilities.*; import groovy.lang.GroovyClassLoader; @@ -198,7 +199,7 @@ public class ExpressionFormat extends Format { protected Object normalizeBindingValue(Object value) { // if the binding value is a String, remove illegal characters if (value instanceof CharSequence) { - return replacePathSeparators(value.toString()).trim(); + return replaceSpace(replacePathSeparators((CharSequence) value), " ").trim(); } // if the binding value is an Object, just leave it diff --git a/source/net/filebot/similarity/Normalization.java b/source/net/filebot/similarity/Normalization.java index 42a1afd5..06e8812a 100644 --- a/source/net/filebot/similarity/Normalization.java +++ b/source/net/filebot/similarity/Normalization.java @@ -9,6 +9,9 @@ public class Normalization { private static final Pattern apostrophe = compile("['`´‘’ʻ]+"); private static final Pattern punctuation = compile("[\\p{Punct}\\p{Space}]+"); + private static final Pattern space = compile("\\s+"); + private static final Pattern spaceLikePunctuation = compile("[:?._]"); + private static final Pattern[] brackets = new Pattern[] { compile("\\([^\\(]*\\)"), compile("\\[[^\\[]*\\]"), compile("\\{[^\\{]*\\}") }; private static final Pattern trailingParentheses = compile("(?