mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-02 08:25:02 -04:00
Don't match numbers that are too long
This commit is contained in:
parent
49710f27f9
commit
fcb003f440
@ -24,7 +24,11 @@ public final class StringUtilities {
|
||||
List<Integer> numbers = new ArrayList<Integer>();
|
||||
Matcher matcher = DIGIT.matcher(s);
|
||||
while (matcher.find()) {
|
||||
numbers.add(new Integer(matcher.group()));
|
||||
try {
|
||||
numbers.add(new Integer(matcher.group()));
|
||||
} catch (NumberFormatException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return numbers;
|
||||
}
|
||||
@ -36,7 +40,11 @@ public final class StringUtilities {
|
||||
|
||||
Matcher matcher = DIGIT.matcher(s);
|
||||
if (matcher.find()) {
|
||||
return new Integer(matcher.group());
|
||||
try {
|
||||
return new Integer(matcher.group());
|
||||
} catch (NumberFormatException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
25
test/net/filebot/util/StringUtilitiesTest.java
Normal file
25
test/net/filebot/util/StringUtilitiesTest.java
Normal file
@ -0,0 +1,25 @@
|
||||
package net.filebot.util;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class StringUtilitiesTest {
|
||||
|
||||
@Test
|
||||
public void matchInteger() {
|
||||
Integer n = StringUtilities.matchInteger("1091_20150217210000");
|
||||
|
||||
assertEquals("1091", n.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchIntegers() {
|
||||
List<Integer> n = StringUtilities.matchIntegers("1091_20150217210000");
|
||||
|
||||
assertEquals("[1091]", n.toString());
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,11 @@
|
||||
|
||||
package net.filebot.util;
|
||||
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses( { FileUtilitiesTest.class, ByteBufferOutputStreamTest.class, PreferencesMapTest.class, PreferencesListTest.class, TreeIteratorTest.class, FilterIteratorTest.class })
|
||||
@SuiteClasses({ FileUtilitiesTest.class, ByteBufferOutputStreamTest.class, PreferencesMapTest.class, PreferencesListTest.class, TreeIteratorTest.class, FilterIteratorTest.class, StringUtilities.class })
|
||||
public class UtilTestSuite {
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user