Skip to content

Commit 65f8419

Browse files
committed
Add StringBuilder class
1 parent 125d446 commit 65f8419

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/Processing.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3635,6 +3635,26 @@ class PShader {
36353635

36363636

36373637

3638+
// Java StringBuilder
3639+
class StringBuilder {
3640+
::std::string buf;
3641+
public:
3642+
StringBuilder() = default;
3643+
StringBuilder(const ::std::string& s) : buf(s) {}
3644+
template<class T> StringBuilder& append(T v) { buf += ::std::to_string(v); return *this; }
3645+
StringBuilder& append(const ::std::string& s) { buf += s; return *this; }
3646+
StringBuilder& append(const char* s) { buf += s; return *this; }
3647+
StringBuilder& append(char c) { buf += c; return *this; }
3648+
StringBuilder& insert(int idx, const ::std::string& s) { buf.insert(idx,s); return *this; }
3649+
StringBuilder& deleteCharAt(int idx) { buf.erase(idx,1); return *this; }
3650+
StringBuilder& reverse() { ::std::reverse(buf.begin(),buf.end()); return *this; }
3651+
void setCharAt(int idx, char c) { buf[idx]=c; }
3652+
char charAt(int idx) const { return buf[idx]; }
3653+
int length() const { return (int)buf.size(); }
3654+
::std::string toString() const { return buf; }
3655+
operator ::std::string() const { return buf; }
3656+
};
3657+
36383658
// Java collection stubs
36393659
template<class T>
36403660
class HashSet {

0 commit comments

Comments
 (0)