1 | sbool checkNTokenHygiene(L<S> tok) { |
2 | ret l(tok) == 1 || checkNTokenHygiene_forward(tok) && checkNTokenHygiene_backward(tok); |
3 | } |
4 | |
5 | sbool checkNTokenHygiene_forward(L<S> tok) { |
6 | int level = 0; |
7 | for (int i = 0; i < l(tok)-1; i += 2) { |
8 | S t = tok.get(i); |
9 | for (char c : characters(t)) |
10 | if (c == '{') ++level; |
11 | else if (c == '}') level = max(0, level-1); |
12 | } |
13 | if (level == 0) true; |
14 | for (char c : characters(last(tok))) |
15 | if (c == '}') if (--level == 0) true; |
16 | false; |
17 | } |
18 | |
19 | sbool checkNTokenHygiene_backward(L<S> tok) { |
20 | int level = 0; |
21 | for (int i = l(tok)-1; i > 0; i -= 2) { |
22 | S t = tok.get(i); |
23 | for (char c : reversedCharacters(t)) |
24 | if (c == '}') ++level; |
25 | else if (c == '{') level = max(0, level-1); |
26 | } |
27 | if (level == 0) true; |
28 | for (char c : reversedCharacters(first(tok))) |
29 | if (c == '{') if (--level == 0) true; |
30 | false; |
31 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1017481 |
Snippet name: | checkNTokenHygiene - probably broken |
Eternal ID of this version: | #1017481/5 |
Text MD5: | f53848e7b04af6e6007a554949b22319 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-09-30 19:31:13 |
Source code size: | 894 bytes / 31 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 380 / 387 |
Version history: | 4 change(s) |
Referenced in: | [show references] |