Skip to content

Commit

Permalink
add an optional input to the list.to_map tag
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 7, 2020
1 parent 8c5a780 commit 63eadd4
Showing 1 changed file with 8 additions and 3 deletions.
Expand Up @@ -902,20 +902,25 @@ else if (input.size() > 1) {
});

// <--[tag]
// @attribute <ListTag.to_map>
// @attribute <ListTag.to_map[(<separator>)]>
// @returns MapTag
// @description
// Interprets a list of "key/value" pairs as a map, and returns the resulting MapTag.
// Optionally specify the map separator symbol, by default '/'.
// -->
registerTag("to_map", (attribute, object) -> {
String symbol = "/";
if (attribute.hasContext(1)) {
symbol = attribute.getContext(1);
}
MapTag map = new MapTag();
for (String entry : object) {
int slash = entry.indexOf('/');
int slash = entry.indexOf(symbol);
if (slash == -1) {
return null;
}
String key = entry.substring(0, slash);
String value = entry.substring(slash + 1);
String value = entry.substring(slash + symbol.length());
map.putObject(key, new ElementTag(value));
}
return map;
Expand Down

0 comments on commit 63eadd4

Please sign in to comment.