diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-21 15:18:55 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-21 15:18:55 +1300 |
commit | 6fc48063460a673815b182e0a8f3adf4db0fd08a (patch) | |
tree | 95ca92d4d2c677edcc2a331bfe6aa56a4bf1ef75 /src/org/traccar/helper/PatternBuilder.java | |
parent | 37a594b4ac0297988b2d2d073bfaee5700df043e (diff) | |
download | trackermap-server-6fc48063460a673815b182e0a8f3adf4db0fd08a.tar.gz trackermap-server-6fc48063460a673815b182e0a8f3adf4db0fd08a.tar.bz2 trackermap-server-6fc48063460a673815b182e0a8f3adf4db0fd08a.zip |
Refactor GL200 protocol decoder
Diffstat (limited to 'src/org/traccar/helper/PatternBuilder.java')
-rw-r--r-- | src/org/traccar/helper/PatternBuilder.java | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/org/traccar/helper/PatternBuilder.java b/src/org/traccar/helper/PatternBuilder.java index a0e24e017..b68089b53 100644 --- a/src/org/traccar/helper/PatternBuilder.java +++ b/src/org/traccar/helper/PatternBuilder.java @@ -31,6 +31,11 @@ public class PatternBuilder { return this; } + // GRouP + public PatternBuilder grp(String s) { + return xpr("(?:").xpr(s).xpr(")"); + } + // OPtional eXpression public PatternBuilder opx(String s) { return xpr("(?:").xpr(s).xpr(")?"); @@ -42,12 +47,21 @@ public class PatternBuilder { return this; } + // OPtional Text + public PatternBuilder opt(String s) { + return xpr("(?:").txt(s).xpr(")?"); + } + // NUMber public PatternBuilder num(String s) { s = s.replace("dddd", "d{4}").replace("ddd", "d{3}").replace("dd", "d{2}"); s = s.replace("xxxx", "x{4}").replace("xxx", "x{3}").replace("xx", "x{2}"); - pattern.append(s.replace("d", "\\d").replace("x", "\\p{XDigit}").replaceAll("([\\.\\|])", "\\\\$1")); + s = s.replace("d", "\\d").replace("x", "\\p{XDigit}").replaceAll("([\\.])", "\\\\$1"); + s = s.replaceAll("\\|$", "\\\\|"); // special case for delimiter + + pattern.append(s); + return this; } @@ -70,6 +84,12 @@ public class PatternBuilder { return not(s).txt(s); } + // BINary + public PatternBuilder bin(String s) { + pattern.append(s.replaceAll("(\\p{XDigit}{2})", "\\\\$1")); + return this; + } + public PatternBuilder groupBegin() { return xpr("(?:"); } |