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

25
LINES

< > BotCompany Repo | #1030024 // parseColonHeadingSections

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

Libraryless. Click here for Pure Java version (2967L/19K).

/* input e.g. [[
Inputs:

"Where is the code repository?"
"Where is the fork?"

Expected output:

"Where is the *?"
]] */

static SS parseColonHeadingSections(S text) {
  LS lines = lines(text);
  L<Int> l = indicesOfEndingWithTrim(lines, ":");
  new LinkedHashMap<S> out;
  if (nempty(l))
    mapPutIfNemptyValue(out, "", rtrim(lines(takeFirst(lines, first(l)))));
  for i over l: {
    int i1 = get(l, i);
    int i2 = or(get(l, i+1), l(lines)+1);
    S heading = dropSuffix(":", trim(lines.get(i1)));
    out.put(heading, lines(subList(lines, i1+1, i2)));
  }
  ret out;
}

Author comment

Began life as a copy of #1027381

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1030024
Snippet name: parseColonHeadingSections
Eternal ID of this version: #1030024/1
Text MD5: a290aa87127c894444e42da08ffc2356
Transpilation MD5: fa22019a2302af73318049fe468e5623
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-10-30 11:19:17
Source code size: 599 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 227 / 283
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)