Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[android] "is-supported-script" expression support #12845

Merged
merged 1 commit into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2848,6 +2848,66 @@ public static Expression resolvedLocale(Expression collator) {
return new Expression("resolved-locale", collator);
}

/**
* Returns true if the input string is expected to render legibly.
* Returns false if the input string contains sections that cannot be rendered without potential loss of meaning
* (e.g. Indic scripts that require complex text shaping,
* or right-to-left scripts if the the mapbox-gl-rtl-text plugin is not in use in Mapbox GL JS).
* <p>
* Example usage:
* </p>
* <pre>
* {@code
* mapboxMap.addLayer(new SymbolLayer("layer-id", "source-id")
* .withProperties(
* textField(
* switchCase(
* isSupportedScript(get("name_property")), get("name_property"),
* literal("not-compatible")
* )
* )
* ));
* }
* </pre>
*
* @param expression the expression to evaluate
* @return expression
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-is-supported-script">Style specification</a>
*/
public static Expression isSupportedScript(Expression expression) {
return new Expression("is-supported-script", expression);
}

/**
* Returns true if the input string is expected to render legibly.
* Returns false if the input string contains sections that cannot be rendered without potential loss of meaning
* (e.g. Indic scripts that require complex text shaping,
* or right-to-left scripts if the the mapbox-gl-rtl-text plugin is not in use in Mapbox GL JS).
* <p>
* Example usage:
* </p>
* <pre>
* {@code
* mapboxMap.addLayer(new SymbolLayer("layer-id", "source-id")
* .withProperties(
* textField(
* switchCase(
* isSupportedScript("ಗೌರವಾರ್ಥವಾಗಿ"), literal("ಗೌರವಾರ್ಥವಾಗಿ"),
* literal("not-compatible")
* )
* )
* );
* }
* </pre>
*
* @param string the string to evaluate
* @return expression
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-is-supported-script">Style specification</a>
*/
public static Expression isSupportedScript(String string) {
return new Expression("is-supported-script", literal(string));
}

/**
* Returns the input string converted to uppercase.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static com.mapbox.mapboxsdk.style.expressions.Expression.heatmapDensity;
import static com.mapbox.mapboxsdk.style.expressions.Expression.id;
import static com.mapbox.mapboxsdk.style.expressions.Expression.interpolate;
import static com.mapbox.mapboxsdk.style.expressions.Expression.isSupportedScript;
import static com.mapbox.mapboxsdk.style.expressions.Expression.length;
import static com.mapbox.mapboxsdk.style.expressions.Expression.let;
import static com.mapbox.mapboxsdk.style.expressions.Expression.linear;
Expand Down Expand Up @@ -1388,4 +1389,18 @@ public void testStringReverseConversion() {
String actual = Expression.toString(get("name_en")).toString();
assertEquals("Reverse string conversion should match", expected, actual);
}

@Test
public void testIsSupportedScriptLiteral() {
Object[] expected = new Object[] {"is-supported-script", "ಗೌರವಾರ್ಥವಾಗಿ"};
Object[] actual = isSupportedScript("ಗೌರವಾರ್ಥವಾಗಿ").toArray();
assertTrue("expression should match", Arrays.deepEquals(expected, actual));
}

@Test
public void testIsSupportedScriptExpressions() {
Object[] expected = new Object[] {"is-supported-script", new Object[] {"get", "property_name"}};
Object[] actual = isSupportedScript(get("property_name")).toArray();
assertTrue("expression should match", Arrays.deepEquals(expected, actual));
}
}