Libraryless. Click here for Pure Java version (2540L/16K).
1 | static int shorten_default = 100; |
2 | |
3 | sS shorten(CharSequence s) { ret shorten(s, shorten_default); } |
4 | |
5 | sS shorten(CharSequence s, int max) { |
6 | ret shorten(s, max, "..."); |
7 | } |
8 | |
9 | sS shorten(CharSequence s, int max, S shortener) { |
10 | if (s == null) ret ""; |
11 | if (max < 0) ret str(s); |
12 | return s.length() <= max ? str(s) : subCharSequence(s, 0, min(s.length(), max-l(shortener))) + shortener; |
13 | } |
14 | |
15 | sS shorten(int max, CharSequence s) { ret shorten(s, max); } |
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1000644 |
Snippet name: | shorten function |
Eternal ID of this version: | #1000644/9 |
Text MD5: | 05874cd24b584b697eeadfc8814cfca6 |
Transpilation MD5: | f82e05803c4a06693700102b6a704571 |
Author: | stefan |
Category: | |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-07-25 12:47:08 |
Source code size: | 459 bytes / 15 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 863 / 9726 |
Version history: | 8 change(s) |
Referenced in: | [show references] |