mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-02 08:25:02 -04:00
* added truncate and truncate-by-word String methods to help with custom formats
This commit is contained in:
parent
d4a13b7eb3
commit
2bd8ffc464
@ -163,6 +163,28 @@ public class ExpressionFormatMethods {
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static String truncate(String self, int limit) {
|
||||
if (limit >= self.length())
|
||||
return self;
|
||||
|
||||
return self.substring(0, limit);
|
||||
}
|
||||
|
||||
public static String truncate(String self, int hardLimit, String nonWordPattern) {
|
||||
if (hardLimit >= self.length())
|
||||
return self;
|
||||
|
||||
int softLimit = 0;
|
||||
Matcher matcher = compile(nonWordPattern, CASE_INSENSITIVE | UNICODE_CHARACTER_CLASS).matcher(self);
|
||||
while (matcher.find()) {
|
||||
if (matcher.start() > hardLimit)
|
||||
break;
|
||||
|
||||
softLimit = matcher.start();
|
||||
}
|
||||
return truncate(self, softLimit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return substring before the given pattern.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user