mirror of
https://github.com/mitb-archive/filebot
synced 2025-03-09 13:59:49 -04:00
az.match('[a-f]': '/volume1', '[g-x]': '/volume2') ?: '/volume3'
This commit is contained in:
parent
37bce60df2
commit
9d08f5f192
@ -433,13 +433,13 @@ public class ExpressionFormatMethods {
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply multiple replacements.
|
||||
* Apply replacement mappings.
|
||||
*
|
||||
* e.g. replace(ä:'ae', ö:'oe', ü:'ue')
|
||||
*/
|
||||
public static String replace(String self, Map<?, ?> replace) {
|
||||
public static String replace(String self, Map<?, ?> replacer) {
|
||||
// the first two parameters are required, the rest of the parameter sequence is optional
|
||||
for (Entry<?, ?> it : replace.entrySet()) {
|
||||
for (Entry<?, ?> it : replacer.entrySet()) {
|
||||
if (it.getKey() instanceof Pattern) {
|
||||
self = ((Pattern) it.getKey()).matcher(self).replaceAll(it.getValue().toString());
|
||||
} else {
|
||||
@ -449,6 +449,22 @@ public class ExpressionFormatMethods {
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find matching pattern and return mapped value.
|
||||
*
|
||||
* e.g. az.match('[a-f]': '/volume1', '[g-x]': '/volume2') ?: '/volume3'
|
||||
*/
|
||||
public static Object match(String self, Map<?, ?> matcher) {
|
||||
// the first two parameters are required, the rest of the parameter sequence is optional
|
||||
for (Entry<?, ?> it : matcher.entrySet()) {
|
||||
Pattern p = it.getKey() instanceof Pattern ? (Pattern) it.getKey() : Pattern.compile(it.getKey().toString(), CASE_INSENSITIVE | UNICODE_CHARACTER_CLASS | MULTILINE);
|
||||
if (p.matcher(self).find()) {
|
||||
return it.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String joining(Collection<?> self, String delimiter) throws Exception {
|
||||
String[] list = self.stream().filter(Objects::nonNull).map(Objects::toString).filter(s -> !s.isEmpty()).toArray(String[]::new);
|
||||
if (list.length > 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user