]. titlesource: --> charRangesOfHTMLComments [ranges include <!-- and -->] [1030488]

Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

21
LINES

< > BotCompany Repo | #1030488 // charRangesOfHTMLComments [ranges include <!-- and -->]

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2970L/17K).

1  
static L<IntRange> charRangesOfHTMLComments(S html) {
2  
  ret charRangesOfHTMLComments(htmlTok(html));
3  
}
4  
5  
static L<IntRange> charRangesOfHTMLComments(LS tok) {
6  
  new L<IntRange> l;
7  
  int pos = 0;
8  
  for idx over tok: {
9  
    S t = tok.get(idx);
10  
    if (even(idx)) {
11  
      int i = 0;
12  
      while ((i = indexOf(t, "<!--", i)) >= 0) {
13  
        int j = smartIndexOf(t, "-->", i+4);
14  
        l.add(intRange(pos+i, pos+j+3));
15  
        i = j+3;
16  
      }
17  
    }
18  
    pos += l(t);
19  
  }
20  
  ret l;
21  
}

Author comment

Began life as a copy of #1028644

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030488
Snippet name: charRangesOfHTMLComments [ranges include <!-- and -->]
Eternal ID of this version: #1030488/1
Text MD5: 5cbfeb87fcea187e9e4a64a9eacd1133
Transpilation MD5: d95dfa0ee9dba996d34f8fb09bddf55f
Author: stefan
Category: javax / html parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-12-28 00:02:26
Source code size: 495 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 194 / 262
Referenced in: [show references]