Libraryless. Click here for Pure Java version (2750L/16K).
1 | sclass StringBufferWithMaxSize implements Appendable { |
2 | int maxSize; // in characters |
3 | new StringBuilder buf; |
4 | |
5 | *(int *maxSize) {} |
6 | |
7 | public Appendable append(char c) { ret append(str(c)); } |
8 | public Appendable append(CharSequence csq, int start, int end) { ret append(csq.subSequence(start, end)); } |
9 | |
10 | int size() { ret l(buf); } |
11 | |
12 | public synchronized Appendable append(CharSequence csq) { |
13 | if (full()) this; |
14 | int n = l(csq); |
15 | if (size()+n > maxSize) |
16 | buf.append(subCharSequence(csq, maxSize-size())); |
17 | else |
18 | buf.append(csq); |
19 | this; |
20 | } |
21 | |
22 | bool full() { ret size() >= maxSize; } |
23 | |
24 | synchronized toString { ret str(buf); } |
25 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1030843 |
Snippet name: | StringBufferWithMaxSize |
Eternal ID of this version: | #1030843/2 |
Text MD5: | 2c752c8712a0e769e0fbd9ca0cea6bb4 |
Transpilation MD5: | a87e17176a6d1cf15f804f40f3336334 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-04-02 15:26:37 |
Source code size: | 689 bytes / 25 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 247 / 443 |
Version history: | 1 change(s) |
Referenced in: | [show references] |