Skip to content

Commit

Permalink
add tag maptag.to_list
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 15, 2020
1 parent 9c640f7 commit 3c57bc3
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public static void registerTags() {
// @attribute <MapTag.list_keys>
// @returns ListTag
// @description
// Returns an list of all keys in this map.
// Returns a list of all keys in this map.
// For example, on a map of "a/1|b/2|c/3|", using "list_keys" will return "a|b|c|".
// -->
registerTag("list_keys", (attribute, object) -> {
Expand All @@ -317,7 +317,7 @@ public static void registerTags() {
// @attribute <MapTag.list_values>
// @returns ListTag
// @description
// Returns an list of all values this map.
// Returns a list of all values in this map.
// For example, on a map of "a/1|b/2|c/3|", using "list_values" will return "1|2|3|".
// -->
registerTag("list_values", (attribute, object) -> {
Expand All @@ -328,6 +328,21 @@ public static void registerTags() {
return result;
});

// <--[tag]
// @attribute <MapTag.to_list>
// @returns ListTag
// @description
// Returns a list of all key/value pairs in this map.
// Note that slash ('/') escaping will be lost, so maps that have slashes in their keys will not be possible to convert back to a map.
// -->
registerTag("to_list", (attribute, object) -> {
ListTag result = new ListTag();
for (Map.Entry<StringHolder, ObjectTag> entry : object.map.entrySet()) {
result.add(entry.getKey().str + "/" + entry.getValue().identify());
}
return result;
});

// <--[tag]
// @attribute <MapTag.to_json>
// @returns ElementTag
Expand Down

0 comments on commit 3c57bc3

Please sign in to comment.