Libraryless. Click here for Pure Java version (97L/1K).
1 | static LS javaTok_noMLS(String s) { |
2 | new ArrayList<String> tok; |
3 | int l = s == null ? 0 : s.length(); |
4 | |
5 | int i = 0, n = 0; |
6 | while (i < l) { |
7 | int j = i; |
8 | char c, d; |
9 | |
10 | // scan for whitespace |
11 | while (j < l) { |
12 | c = s.charAt(j); |
13 | d = j+1 >= l ? '\0' : s.charAt(j+1); |
14 | if (c == ' ' || c == '\t' || c == '\r' || c == '\n') |
15 | ++j; |
16 | else if (c == '/' && d == '*') { |
17 | do ++j; while (j < l && !s.substring(j, Math.min(j+2, l)).equals("*/")); |
18 | j = Math.min(j+2, l); |
19 | } else if (c == '/' && d == '/') { |
20 | do ++j; while (j < l && "\r\n".indexOf(s.charAt(j)) < 0); |
21 | } else |
22 | break; |
23 | } |
24 | |
25 | tok.add(javaTok_substringN(s, i, j)); |
26 | ++n; |
27 | i = j; |
28 | if (i >= l) break; |
29 | c = s.charAt(i); |
30 | d = i+1 >= l ? '\0' : s.charAt(i+1); |
31 | |
32 | // scan for non-whitespace |
33 | |
34 | if (c == '\'' || c == '"') { |
35 | char opener = c; |
36 | ++j; |
37 | while (j < l) { |
38 | int c2 = s.charAt(j); |
39 | if (c2 == opener || c2 == '\n' && opener == '\'') { // allow multi-line strings, but not for ' |
40 | ++j; |
41 | break; |
42 | } else if (c2 == '\\' && j+1 < l) |
43 | j += 2; |
44 | else |
45 | ++j; |
46 | } |
47 | } else if (Character.isJavaIdentifierStart(c)) |
48 | do ++j; while (j < l && Character.isJavaIdentifierPart(s.charAt(j))); |
49 | else if (Character.isDigit(c)) { |
50 | do ++j; while (j < l && Character.isDigit(s.charAt(j))); |
51 | if (j < l && s.charAt(j) == 'L') ++j; // Long constants like 1L |
52 | } else |
53 | ++j; |
54 | |
55 | tok.add(javaTok_substringC(s, i, j)); |
56 | ++n; |
57 | i = j; |
58 | } |
59 | |
60 | if ((tok.size() % 2) == 0) tok.add(""); |
61 | return tok; |
62 | } |
Began life as a copy of #1000688
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1025691 |
Snippet name: | javaTok_noMLS - javaTok without multi-line-strings (for unstructure) |
Eternal ID of this version: | #1025691/3 |
Text MD5: | 3fe46623152e43c511f45b5895a9cc59 |
Transpilation MD5: | ebcc55503555ec823dd935a8ab0eb104 |
Author: | stefan |
Category: | |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-10-13 20:04:05 |
Source code size: | 1707 bytes / 62 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 259 / 383 |
Version history: | 2 change(s) |
Referenced in: | [show references] |