1 /* Copyright (C) 2021-2024 Free Software Foundation, Inc. 2 Contributed by Oracle. 3 4 This file is part of GNU Binutils. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 3, or (at your option) 9 any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, 51 Franklin Street - Fifth Floor, Boston, 19 MA 02110-1301, USA. */ 20 21 /* 22 * java/lang/StringBuilder 23 * 24 * Based on JavaTM 2 Platform Standard Ed. 5.0 25 */ 26 27 #ifndef _StringBuilder_h 28 #define _StringBuilder_h 29 30 class StringBuilder 31 { 32 public: 33 StringBuilder (); 34 StringBuilder (int capacity); 35 virtual ~StringBuilder (); 36 37 int length()38 length () 39 { 40 return count; 41 } 42 43 int capacity()44 capacity () 45 { 46 return maxCapacity; 47 } 48 49 bool endsWith (const char str[]); 50 void ensureCapacity (int minimumCapacity); 51 void expandCapacity (int minimumCapacity); 52 void trimToSize (); 53 void trim (); 54 void setLength (int newLength); 55 char charAt (int index); 56 void getChars (int srcBegin, int srcEnd, char dst[], int dstBegin); 57 void setCharAt (int index, char ch); 58 StringBuilder *append (StringBuilder *sb); 59 StringBuilder *append (const char str[]); 60 StringBuilder *append (const char str[], int offset, int len); 61 StringBuilder *append (bool b); 62 StringBuilder *append (char c); 63 StringBuilder *append (int i); 64 StringBuilder *append (unsigned int i); 65 StringBuilder *append (long lng); 66 StringBuilder *append (unsigned long i); 67 StringBuilder *append (long long lng); 68 StringBuilder *append (unsigned long long lng); 69 StringBuilder *append (float f); 70 StringBuilder *append (double d); 71 StringBuilder *_delete (int start, int end); 72 StringBuilder *deleteCharAt (int index); 73 StringBuilder *insert (int index, const char str[], int offset, int len); 74 StringBuilder *insert (int offset, const char str[]); 75 StringBuilder *insert (int offset, bool b); 76 StringBuilder *insert (int offset, char c); 77 StringBuilder *insert (int offset, int i); 78 StringBuilder *insert (int offset, long l); 79 StringBuilder *insert (int offset, float f); 80 StringBuilder *insert (int offset, double d); 81 StringBuilder *reverse (); 82 char *toString (); 83 void toFile (FILE *fp); 84 void toFileLn (FILE *fp); 85 void write (int fd); 86 87 // Not in Java 88 StringBuilder *appendf (const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); 89 StringBuilder *sprintf (const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); 90 91 int indexOf (const char str[]); 92 int indexOf (const char str[], int fromIndex); 93 int lastIndexOf (const char str[]); 94 int lastIndexOf (const char str[], int fromIndex); 95 96 private: 97 char *value; 98 int count; 99 int maxCapacity; 100 }; 101 102 #endif /* _StringBuilder_h */ 103