1 #ifndef __STRING_UTIL_HH
2 #define __STRING_UTIL_HH
12 typedef unsigned char Byte;
14 #ifdef STRING_UTILS_INLINED
20 /**Internal String struct.
21 the data itself. Handles simple tasks (resizing, resetting)
24 // GNU malloc: storage overhead is 8 bytes anyway.
26 friend class String_handle;
27 int maxlen; // maxlen is arraysize-1
36 /// init from src. Conservative allocation.
37 INLINE StringData(StringData const &src);
41 /** POST: maxlen >= j.
42 IN: j, maximum stringlength_i_.
45 INLINE void setmax(int j);
47 /** POST: maxlen >= j.
48 IN: j, maximum stringlength_i_.
49 contents are kept if it grows.
51 INLINE void remax(int j);
53 /// check if writeable.
59 /// reduce memory usage.
60 INLINE void tighten();
63 INLINE void set( Byte const* by_c_l, int length_i );
65 INLINE void set( char const* ch_c_l );
68 INLINE void append( Byte const* by_c_l, int length_i );
70 INLINE void operator += ( char const* ch_c_l );
72 INLINE char const* ch_c_l() const;
76 INLINE Byte const* by_c_l() const;
81 INLINE void trunc(int j);
83 /** not really safe. Can alter length_i_ without StringData knowing it.
85 INLINE Byte &operator [](int j);
86 INLINE Byte operator [](int j) const;
93 Reference counting for strings.
95 handles ref. counting, and provides a very thin interface using
102 /// decrease ref count. Named kind of like a Tanenbaum semafore
105 /// increase ref count
106 INLINE void up(StringData *d);
108 /** make sure data has only one reference.
109 POST: data->references == 1
114 INLINE String_handle();
115 INLINE ~String_handle();
116 INLINE String_handle(String_handle const & src);
118 INLINE Byte const* by_c_l() const;
119 INLINE char const* ch_c_l() const;
123 INLINE void operator =(String_handle const &src);
124 INLINE void operator += (char const *s);
125 INLINE Byte operator[](int j) const;
127 /** Access elements. WARNING: NOT SAFE
128 don't use this for loops. Use by_c_l()
130 INLINE Byte &operator[](int j);
131 INLINE void append( Byte const* by_c_l, int length_i );
132 INLINE void set( Byte const* by_c_l, int length_i );
133 INLINE void operator = (char const *p);
134 INLINE void trunc(int j);
135 INLINE int length_i() const;
140 #if (NDEBUG == BLONDE)
146 #ifdef STRING_UTILS_INLINED
147 #include "stringutil.cc"
150 #endif // __STRING_UTIL_HH //