Libraryless. Click here for Pure Java version (2397L/18K/52K).
!636 !sf !string == !L<S> !cast !class _javax 19 // this is only required because of #629 bugs... main { static O in; static boolean silent; psvm { if (in == null) in = "values (1,,'yo\"yo\"',3),(4,null,5);"; new main m; List data = m.process((S) in); if (!silent) print(structure(data)); in = data; } List data; List row; List process(String in) { data = null; debug(in); L<S> tok = mysqlTok(in); data = new List; int i = indexOfIgnoreCase(tok, "values"), j = indexOfIgnoreCase(tok, ";"); if (i < 0 || j < 0) fail("ouch"); debug(i, j); for (i += 2; i < j; i += 2) { S token = tok.get(i); if (token == "(") { start_a_row(); } else if (token == ")") { end_row(); } else if (token == ",") { } else if (token.startsWith("\"") || token.startsWith("'")) save(mysqlUnquote(token)); else if (isInteger(token)) save(token); else if (token.equalsIgnoreCase("null")) save(null); else badToken(token); } return data; } void start_a_row() { debug("start_a_row"); row = new List; } boolean end_row() { debug("end_row"); if (row != null) { data.add(row); row = null; return true; } return false; } void save(Object value) { debug("save"); row.add(value); } static boolean debug; void debug(O... o) { if (debug) print(structure(o)); } void badToken(S token) { fail("Bad token: " + token); } }
Began life as a copy of #1000654
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1000656 |
Snippet name: | Parse MySQL values (part of insert statement) |
Eternal ID of this version: | #1000656/1 |
Text MD5: | 10f2d1288dc745e13d1e14b1046027ae |
Transpilation MD5: | 20a1374b702ab773ece28ae67888a88d |
Author: | stefan |
Category: | |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-08-22 16:39:18 |
Source code size: | 1674 bytes / 85 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 755 / 1292 |
Referenced in: | [show references] |