@Test public void testSecondsLexer() { List<CoordinatesParser.Token> actual = CoordinatesParser.lex("39\u00B0 05' 45.503\" -94\u00B0 34' 24.290\""); List<CoordinatesParser.Token> expected = Arrays.asList( new CoordinatesParser.Token(CoordinatesParser.Type.DEG, "39", 0, 0), new CoordinatesParser.Token(CoordinatesParser.Type.MIN, "05", 0, 0), new CoordinatesParser.Token(CoordinatesParser.Type.SEC, "45.503", 0, 0), new CoordinatesParser.Token(CoordinatesParser.Type.H_PREFIX, "-", 0, 0), new CoordinatesParser.Token(CoordinatesParser.Type.DEG, "94", 0, 0), new CoordinatesParser.Token(CoordinatesParser.Type.MIN, "34", 0, 0), new CoordinatesParser.Token(CoordinatesParser.Type.SEC, "24.290", 0, 0) ); assertEquals(expected, actual); }
@NonNull static List<Token> lex(@NonNull String input) throws IllegalArgumentException { List<Token> result = new ArrayList<>(); StringBuilder atom = null; int i = 0; int len = input.length(); boolean before = true; while (i < len) { char c = input.charAt(i); if (Character.isDigit(c) || c == '.') { if (atom == null) atom = new StringBuilder(1).append(c); else atom.append(c); before = false; } else if (atom != null && c >= 'C' && c <= 'X') { atom.append(c); lexUtmOrGprs(result, atom, input, len, i); atom = null; break; } else if (c == 'N' || c == 'E' || c == '+') { result.add(new Token(before ? Type.H_PREFIX : Type.H_SUFFIX, String.valueOf(c), i, 1)); } else if (c == 'S' || c == 'W' || c == '-') { result.add(new Token(before ? Type.H_PREFIX : Type.H_SUFFIX, String.valueOf(c), i, 1)); } else if (Character.isWhitespace(c)) { if (atom != null) { result.add(new Token(Type.DEG, atom.toString(), i - atom.length(), atom.length())); } atom = null; before = true; } else if (c == '\u00B0') { if (atom != null) { result.add(new Token(Type.DEG, atom.toString(), i - atom.length(), atom.length() + 1)); } atom = null; } else if (c == '\'') { if (atom != null) { result.add(new Token(Type.MIN, atom.toString(), i - atom.length(), atom.length() + 1)); } atom = null; } else if (c == '"') { if (atom != null) { result.add(new Token(Type.SEC, atom.toString(), i - atom.length(), atom.length() + 1)); } atom = null; } i++; } if (atom != null) { result.add(new Token(Type.DEG, atom.toString(), i - atom.length(), atom.length())); } return result; }
CoordinatesParser { @NonNull static List<Token> lex(@NonNull String input) throws IllegalArgumentException { List<Token> result = new ArrayList<>(); StringBuilder atom = null; int i = 0; int len = input.length(); boolean before = true; while (i < len) { char c = input.charAt(i); if (Character.isDigit(c) || c == '.') { if (atom == null) atom = new StringBuilder(1).append(c); else atom.append(c); before = false; } else if (atom != null && c >= 'C' && c <= 'X') { atom.append(c); lexUtmOrGprs(result, atom, input, len, i); atom = null; break; } else if (c == 'N' || c == 'E' || c == '+') { result.add(new Token(before ? Type.H_PREFIX : Type.H_SUFFIX, String.valueOf(c), i, 1)); } else if (c == 'S' || c == 'W' || c == '-') { result.add(new Token(before ? Type.H_PREFIX : Type.H_SUFFIX, String.valueOf(c), i, 1)); } else if (Character.isWhitespace(c)) { if (atom != null) { result.add(new Token(Type.DEG, atom.toString(), i - atom.length(), atom.length())); } atom = null; before = true; } else if (c == '\u00B0') { if (atom != null) { result.add(new Token(Type.DEG, atom.toString(), i - atom.length(), atom.length() + 1)); } atom = null; } else if (c == '\'') { if (atom != null) { result.add(new Token(Type.MIN, atom.toString(), i - atom.length(), atom.length() + 1)); } atom = null; } else if (c == '"') { if (atom != null) { result.add(new Token(Type.SEC, atom.toString(), i - atom.length(), atom.length() + 1)); } atom = null; } i++; } if (atom != null) { result.add(new Token(Type.DEG, atom.toString(), i - atom.length(), atom.length())); } return result; } }
CoordinatesParser { @NonNull static List<Token> lex(@NonNull String input) throws IllegalArgumentException { List<Token> result = new ArrayList<>(); StringBuilder atom = null; int i = 0; int len = input.length(); boolean before = true; while (i < len) { char c = input.charAt(i); if (Character.isDigit(c) || c == '.') { if (atom == null) atom = new StringBuilder(1).append(c); else atom.append(c); before = false; } else if (atom != null && c >= 'C' && c <= 'X') { atom.append(c); lexUtmOrGprs(result, atom, input, len, i); atom = null; break; } else if (c == 'N' || c == 'E' || c == '+') { result.add(new Token(before ? Type.H_PREFIX : Type.H_SUFFIX, String.valueOf(c), i, 1)); } else if (c == 'S' || c == 'W' || c == '-') { result.add(new Token(before ? Type.H_PREFIX : Type.H_SUFFIX, String.valueOf(c), i, 1)); } else if (Character.isWhitespace(c)) { if (atom != null) { result.add(new Token(Type.DEG, atom.toString(), i - atom.length(), atom.length())); } atom = null; before = true; } else if (c == '\u00B0') { if (atom != null) { result.add(new Token(Type.DEG, atom.toString(), i - atom.length(), atom.length() + 1)); } atom = null; } else if (c == '\'') { if (atom != null) { result.add(new Token(Type.MIN, atom.toString(), i - atom.length(), atom.length() + 1)); } atom = null; } else if (c == '"') { if (atom != null) { result.add(new Token(Type.SEC, atom.toString(), i - atom.length(), atom.length() + 1)); } atom = null; } i++; } if (atom != null) { result.add(new Token(Type.DEG, atom.toString(), i - atom.length(), atom.length())); } return result; }  }
CoordinatesParser { @NonNull static List<Token> lex(@NonNull String input) throws IllegalArgumentException { List<Token> result = new ArrayList<>(); StringBuilder atom = null; int i = 0; int len = input.length(); boolean before = true; while (i < len) { char c = input.charAt(i); if (Character.isDigit(c) || c == '.') { if (atom == null) atom = new StringBuilder(1).append(c); else atom.append(c); before = false; } else if (atom != null && c >= 'C' && c <= 'X') { atom.append(c); lexUtmOrGprs(result, atom, input, len, i); atom = null; break; } else if (c == 'N' || c == 'E' || c == '+') { result.add(new Token(before ? Type.H_PREFIX : Type.H_SUFFIX, String.valueOf(c), i, 1)); } else if (c == 'S' || c == 'W' || c == '-') { result.add(new Token(before ? Type.H_PREFIX : Type.H_SUFFIX, String.valueOf(c), i, 1)); } else if (Character.isWhitespace(c)) { if (atom != null) { result.add(new Token(Type.DEG, atom.toString(), i - atom.length(), atom.length())); } atom = null; before = true; } else if (c == '\u00B0') { if (atom != null) { result.add(new Token(Type.DEG, atom.toString(), i - atom.length(), atom.length() + 1)); } atom = null; } else if (c == '\'') { if (atom != null) { result.add(new Token(Type.MIN, atom.toString(), i - atom.length(), atom.length() + 1)); } atom = null; } else if (c == '"') { if (atom != null) { result.add(new Token(Type.SEC, atom.toString(), i - atom.length(), atom.length() + 1)); } atom = null; } i++; } if (atom != null) { result.add(new Token(Type.DEG, atom.toString(), i - atom.length(), atom.length())); } return result; }  @NonNull static Result parseWithResult(@NonNull String input); @NonNull static GeoPoint parse(@NonNull String input); }
CoordinatesParser { @NonNull static List<Token> lex(@NonNull String input) throws IllegalArgumentException { List<Token> result = new ArrayList<>(); StringBuilder atom = null; int i = 0; int len = input.length(); boolean before = true; while (i < len) { char c = input.charAt(i); if (Character.isDigit(c) || c == '.') { if (atom == null) atom = new StringBuilder(1).append(c); else atom.append(c); before = false; } else if (atom != null && c >= 'C' && c <= 'X') { atom.append(c); lexUtmOrGprs(result, atom, input, len, i); atom = null; break; } else if (c == 'N' || c == 'E' || c == '+') { result.add(new Token(before ? Type.H_PREFIX : Type.H_SUFFIX, String.valueOf(c), i, 1)); } else if (c == 'S' || c == 'W' || c == '-') { result.add(new Token(before ? Type.H_PREFIX : Type.H_SUFFIX, String.valueOf(c), i, 1)); } else if (Character.isWhitespace(c)) { if (atom != null) { result.add(new Token(Type.DEG, atom.toString(), i - atom.length(), atom.length())); } atom = null; before = true; } else if (c == '\u00B0') { if (atom != null) { result.add(new Token(Type.DEG, atom.toString(), i - atom.length(), atom.length() + 1)); } atom = null; } else if (c == '\'') { if (atom != null) { result.add(new Token(Type.MIN, atom.toString(), i - atom.length(), atom.length() + 1)); } atom = null; } else if (c == '"') { if (atom != null) { result.add(new Token(Type.SEC, atom.toString(), i - atom.length(), atom.length() + 1)); } atom = null; } i++; } if (atom != null) { result.add(new Token(Type.DEG, atom.toString(), i - atom.length(), atom.length())); } return result; }  @NonNull static Result parseWithResult(@NonNull String input); @NonNull static GeoPoint parse(@NonNull String input);  }