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

15
LINES

< > BotCompany Repo | #1000644 - shorten function

JavaX fragment (include)

static int shorten_default = 100;

static S shorten(S s) { ret shorten(s, shorten_default); }

static S shorten(S s, int max) {
  ret shorten(s, max, "...");
}

static S shorten(S s, int max, S shortener) {
  if (s == null) ret "";
  if (max < 0) ret s;
  return s.length() <= max ? s : substring(s, 0, min(s.length(), max-l(shortener))) + shortener;
}

static S shorten(int max, S s) { ret shorten(s, max); }

download  show line numbers  debug dex   

Travelled to 11 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1000644
Snippet name: shorten function
Eternal ID of this version: #1000644/7
Text MD5: f64f4f3f1de18e8b4ad4fb6912a13951
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-11-08 05:27:51
Source code size: 423 bytes / 15 lines
Pitched / IR pitched: No / No
Views / Downloads: 447 / 9080
Version history: 6 change(s)
Referenced in: [show references]