From 65065fee356a82d419aaa2477fd1e3cc47eb7cf2 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Wed, 27 Nov 2024 20:02:40 +0100 Subject: [PATCH 1/2] Implement splitConditionalTagValue (better way) --- .../binary/BinaryMapRouteReaderAdapter.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapRouteReaderAdapter.java b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapRouteReaderAdapter.java index 3785ead845d..f4141099ce5 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapRouteReaderAdapter.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapRouteReaderAdapter.java @@ -259,7 +259,8 @@ private void analyze() { type = HIGHWAY_TYPE; } else if(t.endsWith(":conditional") && v != null){ conditions = new ArrayList(); - String[] cts = v.split("\\);"); + + String[] cts = splitConditionalTagValue(v); for(String c : cts) { int ch = c.indexOf('@'); if (ch > 0) { @@ -319,6 +320,25 @@ private void analyze() { } } } + + private String[] splitConditionalTagValue(String v) { + // 50 @ (Mo-Th 22:00-05:00;Fr 19:00-05:00;Sa,Su); 50 @ winter; 30 @ snow + int parenthesis = 0; + char DELIMITER = '~'; + char[] chars = v.toCharArray(); + for (int i = 0; i < chars.length; i++) { + if (chars[i] == '(') { + parenthesis++; + } + if (chars[i] == ')') { + parenthesis--; + } + if (chars[i] == ';' && parenthesis == 0) { + chars[i] = DELIMITER; + } + } + return String.valueOf(chars).split(String.valueOf(DELIMITER)); + } } public static class RouteRegion extends BinaryIndexPart { From 6183392c027a76a949d73d936fa9eb0ceada8156 Mon Sep 17 00:00:00 2001 From: RZR-UA Date: Wed, 27 Nov 2024 20:03:23 +0100 Subject: [PATCH 2/2] Parse TOKEN_SEASON / TOKEN_WEATHER for conditional --- .../net/osmand/util/OpeningHoursParser.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/util/OpeningHoursParser.java b/OsmAnd-java/src/main/java/net/osmand/util/OpeningHoursParser.java index 6dbb9777f26..4738125973c 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/OpeningHoursParser.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/OpeningHoursParser.java @@ -1715,7 +1715,9 @@ private enum TokenType { TOKEN_DAY_WEEK(7), TOKEN_HOUR_MINUTES (8), TOKEN_OFF_ON(9), - TOKEN_COMMENT(10); + TOKEN_COMMENT(10), + TOKEN_SEASON(11), + TOKEN_WEATHER(12); public final int ord; @@ -1764,6 +1766,8 @@ public static void parseRuleV2(String r, int sequenceIndex, List tokens, Li // skip rule if the first token unknown return; } + if (t != null && t.type == TokenType.TOKEN_SEASON) { + // TODO convert @ winter @ summer into months? + if (i == 0) { + return; + } else { + continue; + } + } + if (t != null && t.type == TokenType.TOKEN_WEATHER) { + // currently unsupported + if (i == 0) { + return; + } else { + continue; + } + } if (t == null || t.type.ord() > currentParse.ord()) { presentTokens.add(currentParse); if (currentParse == TokenType.TOKEN_MONTH || currentParse == TokenType.TOKEN_DAY_MONTH