-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
129 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
jackson-jq/src/main/java/net/thisptr/jackson/jq/internal/functions/JoinFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package net.thisptr.jackson.jq.internal.functions; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.TextNode; | ||
|
||
import net.thisptr.jackson.jq.Function; | ||
import net.thisptr.jackson.jq.JsonQuery; | ||
import net.thisptr.jackson.jq.Scope; | ||
import net.thisptr.jackson.jq.exception.JsonQueryException; | ||
import net.thisptr.jackson.jq.exception.JsonQueryTypeException; | ||
import net.thisptr.jackson.jq.internal.BuiltinFunction; | ||
|
||
@BuiltinFunction("join/1") | ||
public class JoinFunction implements Function { | ||
@Override | ||
public List<JsonNode> apply(final Scope scope, final List<JsonQuery> args, final JsonNode in) throws JsonQueryException { | ||
final List<JsonNode> out = new ArrayList<>(); | ||
for (final JsonNode sep : args.get(0).apply(scope, in)) { | ||
|
||
JsonNode isep = null; | ||
final StringBuilder builder = new StringBuilder(); | ||
for (final JsonNode item : in) { | ||
if (isep != null) { | ||
if (isep.isTextual()) { | ||
builder.append(isep.asText()); | ||
} else if (isep.isNull()) { | ||
// append nothing | ||
} else { | ||
throw new JsonQueryTypeException(new TextNode(builder.toString()), isep, "cannot be added"); | ||
} | ||
} | ||
|
||
if (item.isTextual()) { | ||
builder.append(item.asText()); | ||
} else if (item.isNull()) { | ||
// append nothing | ||
} else if (item.isNumber() || item.isBoolean()) { | ||
// https://github.com/stedolan/jq/commit/e17ccf229723d776c0d49341665256b855c70bda | ||
// https://github.com/stedolan/jq/issues/930 | ||
builder.append(item.toString()); | ||
} else { | ||
throw new JsonQueryTypeException(new TextNode(builder.toString()), item, "cannot be added"); | ||
} | ||
|
||
isep = sep; | ||
} | ||
out.add(new TextNode(builder.toString())); | ||
} | ||
return out; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.