diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-05-10 15:24:53 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-05-10 15:24:53 +1200 |
commit | f22357a774d86864ef212bfa2fa086eca99ec0a0 (patch) | |
tree | d309e1e98a239e288457a6dac8e3cdba4fe2a016 /src/org/traccar/helper | |
parent | 426611e0fd6aaad5e882b2661a66f8c2e48a6af0 (diff) | |
download | trackermap-server-f22357a774d86864ef212bfa2fa086eca99ec0a0.tar.gz trackermap-server-f22357a774d86864ef212bfa2fa086eca99ec0a0.tar.bz2 trackermap-server-f22357a774d86864ef212bfa2fa086eca99ec0a0.zip |
Improve pattern check utility
Diffstat (limited to 'src/org/traccar/helper')
-rw-r--r-- | src/org/traccar/helper/PatternUtil.java | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/org/traccar/helper/PatternUtil.java b/src/org/traccar/helper/PatternUtil.java index 184e6b31b..3d61cc698 100644 --- a/src/org/traccar/helper/PatternUtil.java +++ b/src/org/traccar/helper/PatternUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,22 +24,30 @@ public final class PatternUtil { private PatternUtil() { } - public static String checkPattern(String pattern, String input) { + public static class MatchResult { + public String pattern; + public String matched; + public String remaining; + } + + public static MatchResult checkPattern(String pattern, String input) { - String match = null; + MatchResult result = new MatchResult(); for (int i = 0; i < pattern.length(); i++) { try { - Matcher matcher = Pattern.compile(pattern.substring(0, i) + ".*").matcher(input); + Matcher matcher = Pattern.compile("(" + pattern.substring(0, i) + ").*").matcher(input); if (matcher.matches()) { - match = pattern.substring(0, i); + result.pattern = pattern.substring(0, i); + result.matched = matcher.group(1); + result.remaining = input.substring(matcher.group(1).length()); } } catch (PatternSyntaxException error) { Log.warning(error); } } - return match; + return result; } } |