1 | // TODO: return groups including the brackets |
2 | static L<S> ungroupCharacters(S s) {
|
3 | new L<S> l; |
4 | for i over s: |
5 | if (s.charAt(i) == '\\' && i+1 < l(s)) { // parse escaped character
|
6 | ++i; |
7 | l.add(substring(s, i, i+1)); |
8 | } else if (s.charAt(i) == '[') { // parse group
|
9 | int j = i+1; |
10 | new StringBuilder buf; |
11 | while (j < l(s) && s.charAt(j) != ']') {
|
12 | if (s.charAt(j) == '\\' && j+1 < l(s)) ++j; |
13 | buf.append(s.charAt(j++)); |
14 | } |
15 | l.add(str(buf)); |
16 | i = j; |
17 | } else if (s.charAt(i) == '{') { // parse symbol
|
18 | int j = i; |
19 | new StringBuilder buf; |
20 | while (j < l(s) && s.charAt(j) != '}') {
|
21 | if (s.charAt(j) == '\\' && j+1 < l(s)) ++j; // handle escaped characters |
22 | buf.append(s.charAt(j++)); |
23 | } |
24 | buf.append('}');
|
25 | l.add(str(buf)); |
26 | i = j; |
27 | } else |
28 | l.add(substring(s, i, i+1)); |
29 | ret l; |
30 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1006107 |
| Snippet name: | ungroupCharacters - superseded by ocr_ungroupCharacters |
| Eternal ID of this version: | #1006107/1 |
| Text MD5: | a44b41b881ddb193f39940794cec9beb |
| Author: | stefan |
| Category: | javax / ocr |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2016-12-26 00:11:53 |
| Source code size: | 923 bytes / 30 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 741 / 745 |
| Referenced in: | [show references] |