-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathValidSQL.java
More file actions
32 lines (28 loc) · 766 Bytes
/
ValidSQL.java
File metadata and controls
32 lines (28 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package DataBricks;
import java.util.ArrayList;
import java.util.List;
/**
* Created by cicean on 8/9/2018.
*/
public class ValidSQL {
public List<String> parse(String s) {
List<String> res = new ArrayList<>();
int i = 0, n = s.length();
while (i < n) {
String cmd = "";
boolean quote = false;
while (i < n && (s.charAt(i) != ';' || quote)) {
cmd += s.charAt(i);
if (s.charAt(i) == '\\' && i + 1 < n) {
cmd += s.charAt(++i);
} else if (s.charAt(i) == '"') {
quote = !quote;
}
i++;
}
res.add(cmd);
i++;
}
return res;
}
}