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

12
LINES

< > BotCompany Repo | #1036420 // charIndexToLineAndColumn

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

Libraryless. Click here for Pure Java version (9957L/56K).

1  
static LineAndColumn charIndexToLineAndColumn(S text, int charIndex) {
2  
  int line = 1, col = 1;
3  
  charIndex = min(charIndex, l(text));
4  
  for i to charIndex: {
5  
    if (text.charAt(i) == '\n') {
6  
      ++line;
7  
      col = 1;
8  
    } else
9  
      ++col;
10  
  }
11  
  ret LineAndColumn(line, col);
12  
}

Author comment

Began life as a copy of #1033994

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1036420
Snippet name: charIndexToLineAndColumn
Eternal ID of this version: #1036420/4
Text MD5: d0a9907552d7121c48429951186b2421
Transpilation MD5: 0b96cb9cf1001ce86925061bb3817117
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-12-11 18:15:29
Source code size: 294 bytes / 12 lines
Pitched / IR pitched: No / No
Views / Downloads: 123 / 185
Version history: 3 change(s)
Referenced in: [show references]