MCPcopy Create free account
hub / github.com/datastax/fallout / split

Method split

src/main/java/com/datastax/fallout/util/ShellUtils.java:44–90  ·  view source on GitHub ↗
(CharSequence string)

Source from the content-addressed store, hash-verified

42 // This is from http://stackoverflow.com/a/20725050/322152. We're not using org.apache.commons.exec.CommandLine
43 // because it fails to parse "run 'echo "foo"'" correctly (v1.3 misses off the final ')
44 public static String[] split(CharSequence string)
45 {
46 List<String> tokens = new ArrayList<>();
47 boolean escaping = false;
48 char quoteChar = ' ';
49 boolean quoting = false;
50 StringBuilder current = new StringBuilder();
51 for (int i = 0; i < string.length(); i++)
52 {
53 char c = string.charAt(i);
54 if (escaping)
55 {
56 current.append(c);
57 escaping = false;
58 }
59 else if (c == '\\' && !(quoting && quoteChar == '\''))
60 {
61 escaping = true;
62 }
63 else if (quoting && c == quoteChar)
64 {
65 quoting = false;
66 }
67 else if (!quoting && (c == '\'' || c == '"'))
68 {
69 quoting = true;
70 quoteChar = c;
71 }
72 else if (!quoting && Character.isWhitespace(c))
73 {
74 if (current.length() > 0)
75 {
76 tokens.add(current.toString());
77 current = new StringBuilder();
78 }
79 }
80 else
81 {
82 current.append(c);
83 }
84 }
85 if (current.length() > 0)
86 {
87 tokens.add(current.toString());
88 }
89 return tokens.toArray(new String[] {});
90 }
91
92 public static String escape(String param)
93 {

Callers 15

runFunction · 0.80
ToxClass · 0.80
ToolPlatformClass · 0.80
registerMethod · 0.80
CountCheckerClass · 0.80
assertEscapeMethod · 0.80
runMethod · 0.80
split_blank_is_emptyMethod · 0.80

Calls 3

addMethod · 0.65
appendMethod · 0.45
toStringMethod · 0.45

Tested by 15

registerMethod · 0.64
assertEscapeMethod · 0.64
runMethod · 0.64
split_blank_is_emptyMethod · 0.64
split_unquotedMethod · 0.64
split_double_quotedMethod · 0.64
split_single_quotedMethod · 0.64