X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FStringUtils.java;h=1e9d7ed7463a6b2356677f9af0e158ff2b283820;hp=a6117a04053e863b3d9952c4fccd33f0533f33c7;hb=e8aa5bf9227a0d6a6d0bb6a8bc0cc04d0f4d601a;hpb=805005449dacb1e7b825db63836bf100e472ddd0 diff --git a/src/be/nikiroo/utils/StringUtils.java b/src/be/nikiroo/utils/StringUtils.java index a6117a0..1e9d7ed 100644 --- a/src/be/nikiroo/utils/StringUtils.java +++ b/src/be/nikiroo/utils/StringUtils.java @@ -36,8 +36,7 @@ public class StringUtils { End } - static private Pattern marks = Pattern - .compile("[\\p{InCombiningDiacriticalMarks}\\p{IsLm}\\p{IsSk}]+"); + static private Pattern marks = getMarks(); /** * Fix the size of the given {@link String} either with space-padding or by @@ -146,7 +145,9 @@ public class StringUtils { if (removeAllAccents) { input = Normalizer.normalize(input, Form.NFKD); - input = marks.matcher(input).replaceAll(""); + if (marks != null) { + input = marks.matcher(input).replaceAll(""); + } } input = Normalizer.normalize(input, Form.NFKC); @@ -195,15 +196,15 @@ public class StringUtils { * the time as a {@link String} * * @return the number of milliseconds since the standard base time known as - * "the epoch", namely January 1, 1970, 00:00:00 GMT + * "the epoch", namely January 1, 1970, 00:00:00 GMT, or -1 in case + * of error + * + * @throws ParseException + * in case of parse error */ - static public long toTime(String displayTime) { + static public long toTime(String displayTime) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - try { - return sdf.parse(displayTime).getTime(); - } catch (ParseException e) { - return -1; - } + return sdf.parse(displayTime).getTime(); } /** @@ -340,4 +341,19 @@ public class StringUtils { scan.close(); } } + + /** + * The "remove accents" pattern. + * + * @return the pattern, or NULL if a problem happens + */ + private static Pattern getMarks() { + try { + return Pattern + .compile("[\\p{InCombiningDiacriticalMarks}\\p{IsLm}\\p{IsSk}]+"); + } catch (Exception e) { + // Can fail on Android... + return null; + } + } }