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

26
LINES

< > BotCompany Repo | #1016665 // _SubModulePrint

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

Libraryless. Click here for Pure Java version (2238L/14K).

sclass _SubModulePrint implements Appendable {
  S prefix;
  bool beginningOfLine = true;
  
  *() {}
  *(S *prefix) {}
  
  public Appendable append(char c) { ret append(str(c)); }
  public Appendable append(CharSequence csq, int start, int end) { ret append(csq.subSequence(start, end)); }
  
  public Appendable append(CharSequence csq) {
    S s = str(csq);
    if (empty(s)) this;
    if (beginningOfLine) print_raw(makePrefix());
    bool nl = s.endsWith("\n");
    if (nl) s = dropLast(s);
    if (nempty(prefix) && contains(s, '\n'))
      s = s.replace("\n", "\n" + prefix);
    print_raw(s);
    if (nl) print_raw("\n");
    beginningOfLine = nl;
    this;
  }
  
  swappable S makePrefix() { ret prefix; }
}

Author comment

Began life as a copy of #1012700

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1016665
Snippet name: _SubModulePrint
Eternal ID of this version: #1016665/3
Text MD5: 6aa64cafda2d7761eb6bbe86a6691f91
Transpilation MD5: 4322fa5f75f0451250ee95f8fe538641
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-01-18 17:37:02
Source code size: 743 bytes / 26 lines
Pitched / IR pitched: No / No
Views / Downloads: 369 / 992
Version history: 2 change(s)
Referenced in: [show references]