Libraryless. Click here for Pure Java version (2750L/16K).
sclass StringBufferWithMaxSize implements Appendable { int maxSize; // in characters new StringBuilder buf; *(int *maxSize) {} public Appendable append(char c) { ret append(str(c)); } public Appendable append(CharSequence csq, int start, int end) { ret append(csq.subSequence(start, end)); } int size() { ret l(buf); } public synchronized Appendable append(CharSequence csq) { if (full()) this; int n = l(csq); if (size()+n > maxSize) buf.append(subCharSequence(csq, maxSize-size())); else buf.append(csq); this; } bool full() { ret size() >= maxSize; } synchronized toString { ret str(buf); } }
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: | 246 / 439 |
Version history: | 1 change(s) |
Referenced in: | [show references] |