xref: /aoo42x/main/sal/inc/rtl/ustrbuf.hxx (revision a8f4084d)
1565d668cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3565d668cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4565d668cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5565d668cSAndrew Rist  * distributed with this work for additional information
6565d668cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7565d668cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8565d668cSAndrew Rist  * "License"); you may not use this file except in compliance
9565d668cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10565d668cSAndrew Rist  *
11565d668cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12565d668cSAndrew Rist  *
13565d668cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14565d668cSAndrew Rist  * software distributed under the License is distributed on an
15565d668cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16565d668cSAndrew Rist  * KIND, either express or implied.  See the License for the
17565d668cSAndrew Rist  * specific language governing permissions and limitations
18565d668cSAndrew Rist  * under the License.
19565d668cSAndrew Rist  *
20565d668cSAndrew Rist  *************************************************************/
21565d668cSAndrew Rist 
22565d668cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _RTL_USTRBUF_HXX_
25cdf0e10cSrcweir #define _RTL_USTRBUF_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <osl/diagnose.h>
28cdf0e10cSrcweir #include <rtl/ustrbuf.h>
29cdf0e10cSrcweir #ifndef _RTL_USTRING_HXX
30cdf0e10cSrcweir #include <rtl/ustring.hxx>
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #ifdef __cplusplus
34cdf0e10cSrcweir 
35cdf0e10cSrcweir namespace rtl
36cdf0e10cSrcweir {
37cdf0e10cSrcweir 
38cdf0e10cSrcweir /** @HTML
39cdf0e10cSrcweir     A string buffer implements a mutable sequence of characters.
40cdf0e10cSrcweir     <p>
41cdf0e10cSrcweir     String buffers are safe for use by multiple threads. The methods
42cdf0e10cSrcweir     are synchronized where necessary so that all the operations on any
43cdf0e10cSrcweir     particular instance behave as if they occur in some serial order.
44cdf0e10cSrcweir     <p>
45cdf0e10cSrcweir     String buffers are used by the compiler to implement the binary
46cdf0e10cSrcweir     string concatenation operator <code>+</code>. For example, the code:
47cdf0e10cSrcweir     <p><blockquote><pre>
48cdf0e10cSrcweir         x = "a" + 4 + "c"
49cdf0e10cSrcweir     </pre></blockquote><p>
50cdf0e10cSrcweir     is compiled to the equivalent of:
51cdf0e10cSrcweir     <p><blockquote><pre>
52cdf0e10cSrcweir         x = new OUStringBuffer().append("a").append(4).append("c")
53cdf0e10cSrcweir                               .toString()
54cdf0e10cSrcweir     </pre></blockquote><p>
55cdf0e10cSrcweir     The principal operations on a <code>OUStringBuffer</code> are the
56cdf0e10cSrcweir     <code>append</code> and <code>insert</code> methods, which are
57cdf0e10cSrcweir     overloaded so as to accept data of any type. Each effectively
58cdf0e10cSrcweir     converts a given datum to a string and then appends or inserts the
59cdf0e10cSrcweir     characters of that string to the string buffer. The
60cdf0e10cSrcweir     <code>append</code> method always adds these characters at the end
61cdf0e10cSrcweir     of the buffer; the <code>insert</code> method adds the characters at
62cdf0e10cSrcweir     a specified point.
63cdf0e10cSrcweir     <p>
64cdf0e10cSrcweir     For example, if <code>z</code> refers to a string buffer object
65cdf0e10cSrcweir     whose current contents are "<code>start</code>", then
66cdf0e10cSrcweir     the method call <code>z.append("le")</code> would cause the string
67cdf0e10cSrcweir     buffer to contain "<code>startle</code>", whereas
68cdf0e10cSrcweir     <code>z.insert(4, "le")</code> would alter the string buffer to
69cdf0e10cSrcweir     contain "<code>starlet</code>".
70cdf0e10cSrcweir     <p>
71cdf0e10cSrcweir     Every string buffer has a capacity. As long as the length of the
72cdf0e10cSrcweir     character sequence contained in the string buffer does not exceed
73cdf0e10cSrcweir     the capacity, it is not necessary to allocate a new internal
74cdf0e10cSrcweir     buffer array. If the internal buffer overflows, it is
75cdf0e10cSrcweir     automatically made larger.
76cdf0e10cSrcweir  */
77cdf0e10cSrcweir class OUStringBuffer
78cdf0e10cSrcweir {
79cdf0e10cSrcweir public:
80cdf0e10cSrcweir     /**
81cdf0e10cSrcweir         Constructs a string buffer with no characters in it and an
82cdf0e10cSrcweir         initial capacity of 16 characters.
83cdf0e10cSrcweir      */
OUStringBuffer()84cdf0e10cSrcweir     OUStringBuffer()
85cdf0e10cSrcweir         : pData(NULL)
86cdf0e10cSrcweir         , nCapacity( 16 )
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir         rtl_uString_new_WithLength( &pData, nCapacity );
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     /**
92cdf0e10cSrcweir         Allocates a new string buffer that contains the same sequence of
93cdf0e10cSrcweir         characters as the string buffer argument.
94cdf0e10cSrcweir 
95cdf0e10cSrcweir         @param   value   a <code>OStringBuffer</code>.
96cdf0e10cSrcweir      */
OUStringBuffer(const OUStringBuffer & value)97cdf0e10cSrcweir     OUStringBuffer( const OUStringBuffer & value )
98cdf0e10cSrcweir         : pData(NULL)
99cdf0e10cSrcweir         , nCapacity( value.nCapacity )
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir         rtl_uStringbuffer_newFromStringBuffer( &pData, value.nCapacity, value.pData );
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     /**
105cdf0e10cSrcweir         Constructs a string buffer with no characters in it and an
106cdf0e10cSrcweir         initial capacity specified by the <code>length</code> argument.
107cdf0e10cSrcweir 
108cdf0e10cSrcweir         @param      length   the initial capacity.
109cdf0e10cSrcweir      */
OUStringBuffer(sal_Int32 length)110cdf0e10cSrcweir     OUStringBuffer(sal_Int32 length)
111cdf0e10cSrcweir         : pData(NULL)
112cdf0e10cSrcweir         , nCapacity( length )
113cdf0e10cSrcweir     {
114cdf0e10cSrcweir         rtl_uString_new_WithLength( &pData, length );
115cdf0e10cSrcweir     }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     /**
118cdf0e10cSrcweir         Constructs a string buffer so that it represents the same
119cdf0e10cSrcweir         sequence of characters as the string argument.
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         The initial
122cdf0e10cSrcweir         capacity of the string buffer is <code>16</code> plus the length
123cdf0e10cSrcweir         of the string argument.
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         @param   str   the initial contents of the buffer.
126cdf0e10cSrcweir      */
OUStringBuffer(OUString value)127cdf0e10cSrcweir     OUStringBuffer(OUString value)
128cdf0e10cSrcweir         : pData(NULL)
129cdf0e10cSrcweir         , nCapacity( value.getLength() + 16 )
130cdf0e10cSrcweir     {
131cdf0e10cSrcweir         rtl_uStringbuffer_newFromStr_WithLength( &pData, value.getStr(), value.getLength() );
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     /** Assign to this a copy of value.
135cdf0e10cSrcweir      */
operator =(const OUStringBuffer & value)136cdf0e10cSrcweir     OUStringBuffer& operator = ( const OUStringBuffer& value )
137cdf0e10cSrcweir     {
138cdf0e10cSrcweir         if (this != &value)
139cdf0e10cSrcweir         {
140cdf0e10cSrcweir             rtl_uStringbuffer_newFromStringBuffer(&pData,
141cdf0e10cSrcweir                                                   value.nCapacity,
142cdf0e10cSrcweir                                                   value.pData);
143cdf0e10cSrcweir             nCapacity = value.nCapacity;
144cdf0e10cSrcweir         }
145cdf0e10cSrcweir         return *this;
146cdf0e10cSrcweir     }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     /**
149cdf0e10cSrcweir         Release the string data.
150cdf0e10cSrcweir      */
~OUStringBuffer()151cdf0e10cSrcweir     ~OUStringBuffer()
152cdf0e10cSrcweir     {
153cdf0e10cSrcweir         rtl_uString_release( pData );
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     /**
157cdf0e10cSrcweir         Fill the string data in the new string and clear the buffer.
158cdf0e10cSrcweir 
159*a8f4084dSMatthias Seidel         This method is more efficient than the constructor of the string. It does
160cdf0e10cSrcweir         not copy the buffer.
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         @return the string previously contained in the buffer.
163cdf0e10cSrcweir      */
makeStringAndClear()164cdf0e10cSrcweir     OUString makeStringAndClear()
165cdf0e10cSrcweir     {
166cdf0e10cSrcweir         OUString aRet( pData );
167cdf0e10cSrcweir         rtl_uString_new(&pData);
168cdf0e10cSrcweir         nCapacity = 0;
169cdf0e10cSrcweir         return aRet;
170cdf0e10cSrcweir     }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     /**
173cdf0e10cSrcweir         Returns the length (character count) of this string buffer.
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         @return  the number of characters in this string buffer.
176cdf0e10cSrcweir      */
getLength() const177cdf0e10cSrcweir     sal_Int32 getLength() const
178cdf0e10cSrcweir     {
179cdf0e10cSrcweir         return pData->length;
180cdf0e10cSrcweir     }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     /**
183cdf0e10cSrcweir         Returns the current capacity of the String buffer.
184cdf0e10cSrcweir 
185cdf0e10cSrcweir         The capacity
186cdf0e10cSrcweir         is the amount of storage available for newly inserted
187cdf0e10cSrcweir         characters. The real buffer size is 2 bytes longer, because
188cdf0e10cSrcweir         all strings are 0 terminated.
189cdf0e10cSrcweir 
190cdf0e10cSrcweir         @return  the current capacity of this string buffer.
191cdf0e10cSrcweir      */
getCapacity() const192cdf0e10cSrcweir     sal_Int32 getCapacity() const
193cdf0e10cSrcweir     {
194cdf0e10cSrcweir         return nCapacity;
195cdf0e10cSrcweir     }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     /**
198cdf0e10cSrcweir         Ensures that the capacity of the buffer is at least equal to the
199cdf0e10cSrcweir         specified minimum.
200cdf0e10cSrcweir 
201cdf0e10cSrcweir         The new capacity will be at least as large as the maximum of the current
202cdf0e10cSrcweir         length (so that no contents of the buffer is destroyed) and the given
203*a8f4084dSMatthias Seidel         minimumCapacity. If the given minimumCapacity is negative, nothing is
204cdf0e10cSrcweir         changed.
205cdf0e10cSrcweir 
206cdf0e10cSrcweir         @param   minimumCapacity   the minimum desired capacity.
207cdf0e10cSrcweir      */
ensureCapacity(sal_Int32 minimumCapacity)208cdf0e10cSrcweir     void ensureCapacity(sal_Int32 minimumCapacity)
209cdf0e10cSrcweir     {
210cdf0e10cSrcweir         rtl_uStringbuffer_ensureCapacity( &pData, &nCapacity, minimumCapacity );
211cdf0e10cSrcweir     }
212cdf0e10cSrcweir 
213cdf0e10cSrcweir     /**
214cdf0e10cSrcweir         Sets the length of this String buffer.
215cdf0e10cSrcweir 
216cdf0e10cSrcweir         If the <code>newLength</code> argument is less than the current
217cdf0e10cSrcweir         length of the string buffer, the string buffer is truncated to
218cdf0e10cSrcweir         contain exactly the number of characters given by the
219cdf0e10cSrcweir         <code>newLength</code> argument.
220cdf0e10cSrcweir         <p>
221cdf0e10cSrcweir         If the <code>newLength</code> argument is greater than or equal
222cdf0e10cSrcweir         to the current length, sufficient null characters
223cdf0e10cSrcweir         (<code>'&#92;u0000'</code>) are appended to the string buffer so that
224cdf0e10cSrcweir         length becomes the <code>newLength</code> argument.
225cdf0e10cSrcweir         <p>
226cdf0e10cSrcweir         The <code>newLength</code> argument must be greater than or equal
227cdf0e10cSrcweir         to <code>0</code>.
228cdf0e10cSrcweir 
229cdf0e10cSrcweir         @param      newLength   the new length of the buffer.
230cdf0e10cSrcweir      */
setLength(sal_Int32 newLength)231cdf0e10cSrcweir     void setLength(sal_Int32 newLength)
232cdf0e10cSrcweir     {
233cdf0e10cSrcweir         OSL_ASSERT(newLength >= 0);
234cdf0e10cSrcweir         // Avoid modifications if pData points to const empty string:
235cdf0e10cSrcweir         if( newLength != pData->length )
236cdf0e10cSrcweir         {
237cdf0e10cSrcweir             if( newLength > nCapacity )
238cdf0e10cSrcweir                 rtl_uStringbuffer_ensureCapacity(&pData, &nCapacity, newLength);
239cdf0e10cSrcweir             else
240cdf0e10cSrcweir                 pData->buffer[newLength] = 0;
241cdf0e10cSrcweir             pData->length = newLength;
242cdf0e10cSrcweir         }
243cdf0e10cSrcweir     }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     /**
246cdf0e10cSrcweir         Returns the character at a specific index in this string buffer.
247cdf0e10cSrcweir 
248cdf0e10cSrcweir         The first character of a string buffer is at index
249cdf0e10cSrcweir         <code>0</code>, the next at index <code>1</code>, and so on, for
250cdf0e10cSrcweir         array indexing.
251cdf0e10cSrcweir         <p>
252cdf0e10cSrcweir         The index argument must be greater than or equal to
253cdf0e10cSrcweir         <code>0</code>, and less than the length of this string buffer.
254cdf0e10cSrcweir 
255cdf0e10cSrcweir         @param      index   the index of the desired character.
256cdf0e10cSrcweir         @return     the character at the specified index of this string buffer.
257cdf0e10cSrcweir      */
charAt(sal_Int32 index) const258cdf0e10cSrcweir     sal_Unicode charAt( sal_Int32 index ) const
259cdf0e10cSrcweir     {
260cdf0e10cSrcweir         OSL_ASSERT(index >= 0 && index < pData->length);
261cdf0e10cSrcweir         return pData->buffer[ index ];
262cdf0e10cSrcweir     }
263cdf0e10cSrcweir 
264cdf0e10cSrcweir     /**
265cdf0e10cSrcweir         Return a null terminated unicode character array.
266cdf0e10cSrcweir      */
267cdf0e10cSrcweir     operator        const sal_Unicode *() const { return pData->buffer; }
268cdf0e10cSrcweir 
269cdf0e10cSrcweir     /**
270cdf0e10cSrcweir         Return a null terminated unicode character array.
271cdf0e10cSrcweir      */
getStr() const272cdf0e10cSrcweir     const sal_Unicode*  getStr() const { return pData->buffer; }
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 
275cdf0e10cSrcweir     /**
276cdf0e10cSrcweir         The character at the specified index of this string buffer is set
277cdf0e10cSrcweir         to <code>ch</code>.
278cdf0e10cSrcweir 
279cdf0e10cSrcweir         The index argument must be greater than or equal to
280cdf0e10cSrcweir         <code>0</code>, and less than the length of this string buffer.
281cdf0e10cSrcweir 
282cdf0e10cSrcweir         @param      index   the index of the character to modify.
283cdf0e10cSrcweir         @param      ch      the new character.
284cdf0e10cSrcweir      */
setCharAt(sal_Int32 index,sal_Unicode ch)285cdf0e10cSrcweir     OUStringBuffer & setCharAt(sal_Int32 index, sal_Unicode ch)
286cdf0e10cSrcweir     {
287cdf0e10cSrcweir         OSL_ASSERT(index >= 0 && index < pData->length);
288cdf0e10cSrcweir         pData->buffer[ index ] = ch;
289cdf0e10cSrcweir         return *this;
290cdf0e10cSrcweir     }
291cdf0e10cSrcweir 
292cdf0e10cSrcweir     /**
293cdf0e10cSrcweir         Appends the string to this string buffer.
294cdf0e10cSrcweir 
295cdf0e10cSrcweir         The characters of the <code>String</code> argument are appended, in
296cdf0e10cSrcweir         order, to the contents of this string buffer, increasing the
297cdf0e10cSrcweir         length of this string buffer by the length of the argument.
298cdf0e10cSrcweir 
299cdf0e10cSrcweir         @param   str   a string.
300cdf0e10cSrcweir         @return  this string buffer.
301cdf0e10cSrcweir      */
append(const OUString & str)302cdf0e10cSrcweir     OUStringBuffer & append(const OUString &str)
303cdf0e10cSrcweir     {
304cdf0e10cSrcweir         return append( str.getStr(), str.getLength() );
305cdf0e10cSrcweir     }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir     /**
308cdf0e10cSrcweir         Appends the string representation of the <code>char</code> array
309cdf0e10cSrcweir         argument to this string buffer.
310cdf0e10cSrcweir 
311cdf0e10cSrcweir         The characters of the array argument are appended, in order, to
312cdf0e10cSrcweir         the contents of this string buffer. The length of this string
313cdf0e10cSrcweir         buffer increases by the length of the argument.
314cdf0e10cSrcweir 
315cdf0e10cSrcweir         @param   str   the characters to be appended.
316cdf0e10cSrcweir         @return  this string buffer.
317cdf0e10cSrcweir      */
append(const sal_Unicode * str)318cdf0e10cSrcweir     OUStringBuffer & append( const sal_Unicode * str )
319cdf0e10cSrcweir     {
320cdf0e10cSrcweir         return append( str, rtl_ustr_getLength( str ) );
321cdf0e10cSrcweir     }
322cdf0e10cSrcweir 
323cdf0e10cSrcweir     /**
324cdf0e10cSrcweir         Appends the string representation of the <code>char</code> array
325cdf0e10cSrcweir         argument to this string buffer.
326cdf0e10cSrcweir 
327cdf0e10cSrcweir         Characters of the character array <code>str</code> are appended,
328cdf0e10cSrcweir         in order, to the contents of this string buffer. The length of this
329cdf0e10cSrcweir         string buffer increases by the value of <code>len</code>.
330cdf0e10cSrcweir 
331cdf0e10cSrcweir         @param str the characters to be appended; must be non-null, and must
332cdf0e10cSrcweir         point to at least len characters
333cdf0e10cSrcweir         @param len the number of characters to append; must be non-negative
334cdf0e10cSrcweir         @return  this string buffer.
335cdf0e10cSrcweir      */
append(const sal_Unicode * str,sal_Int32 len)336cdf0e10cSrcweir     OUStringBuffer & append( const sal_Unicode * str, sal_Int32 len)
337cdf0e10cSrcweir     {
338cdf0e10cSrcweir         // insert behind the last character
339cdf0e10cSrcweir         rtl_uStringbuffer_insert( &pData, &nCapacity, getLength(), str, len );
340cdf0e10cSrcweir         return *this;
341cdf0e10cSrcweir     }
342cdf0e10cSrcweir 
343cdf0e10cSrcweir     /**
344cdf0e10cSrcweir         Appends a 8-Bit ASCII character string to this string buffer.
345cdf0e10cSrcweir 
346cdf0e10cSrcweir        Since this method is optimized for performance. the ASCII
347cdf0e10cSrcweir         character values are not converted in any way. The caller
348cdf0e10cSrcweir         has to make sure that all ASCII characters are in the
349cdf0e10cSrcweir         allowed range between 0 and 127. The ASCII string must be
350cdf0e10cSrcweir         NULL-terminated.
351cdf0e10cSrcweir         <p>
352cdf0e10cSrcweir         The characters of the array argument are appended, in order, to
353cdf0e10cSrcweir         the contents of this string buffer. The length of this string
354cdf0e10cSrcweir         buffer increases by the length of the argument.
355cdf0e10cSrcweir 
356cdf0e10cSrcweir         @param   str   the 8-Bit ASCII characters to be appended.
357cdf0e10cSrcweir         @return  this string buffer.
358cdf0e10cSrcweir      */
appendAscii(const sal_Char * str)359cdf0e10cSrcweir     OUStringBuffer & appendAscii( const sal_Char * str )
360cdf0e10cSrcweir     {
361cdf0e10cSrcweir         return appendAscii( str, rtl_str_getLength( str ) );
362cdf0e10cSrcweir     }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir     /**
365cdf0e10cSrcweir         Appends a 8-Bit ASCII character string to this string buffer.
366cdf0e10cSrcweir 
367cdf0e10cSrcweir         Since this method is optimized for performance. the ASCII
368cdf0e10cSrcweir         character values are not converted in any way. The caller
369cdf0e10cSrcweir         has to make sure that all ASCII characters are in the
370cdf0e10cSrcweir         allowed range between 0 and 127. The ASCII string must be
371cdf0e10cSrcweir         NULL-terminated.
372cdf0e10cSrcweir         <p>
373cdf0e10cSrcweir         Characters of the character array <code>str</code> are appended,
374cdf0e10cSrcweir         in order, to the contents of this string buffer. The length of this
375cdf0e10cSrcweir         string buffer increases by the value of <code>len</code>.
376cdf0e10cSrcweir 
377cdf0e10cSrcweir         @param str the 8-Bit ASCII characters to be appended; must be non-null,
378cdf0e10cSrcweir         and must point to at least len characters
379cdf0e10cSrcweir         @param len the number of characters to append; must be non-negative
380cdf0e10cSrcweir         @return  this string buffer.
381cdf0e10cSrcweir      */
appendAscii(const sal_Char * str,sal_Int32 len)382cdf0e10cSrcweir     OUStringBuffer & appendAscii( const sal_Char * str, sal_Int32 len)
383cdf0e10cSrcweir     {
384cdf0e10cSrcweir         rtl_uStringbuffer_insert_ascii( &pData, &nCapacity, getLength(), str, len );
385cdf0e10cSrcweir         return *this;
386cdf0e10cSrcweir     }
387cdf0e10cSrcweir 
388cdf0e10cSrcweir 
389cdf0e10cSrcweir     /**
390cdf0e10cSrcweir         Appends the string representation of the <code>sal_Bool</code>
391cdf0e10cSrcweir         argument to the string buffer.
392cdf0e10cSrcweir 
393cdf0e10cSrcweir         The argument is converted to a string as if by the method
394cdf0e10cSrcweir         <code>String.valueOf</code>, and the characters of that
395cdf0e10cSrcweir         string are then appended to this string buffer.
396cdf0e10cSrcweir 
397cdf0e10cSrcweir         @param   b   a <code>sal_Bool</code>.
398cdf0e10cSrcweir         @return  this string buffer.
399cdf0e10cSrcweir      */
append(sal_Bool b)400cdf0e10cSrcweir     OUStringBuffer & append(sal_Bool b)
401cdf0e10cSrcweir     {
402cdf0e10cSrcweir         sal_Unicode sz[RTL_USTR_MAX_VALUEOFBOOLEAN];
403cdf0e10cSrcweir         return append( sz, rtl_ustr_valueOfBoolean( sz, b ) );
404cdf0e10cSrcweir     }
405cdf0e10cSrcweir 
406cdf0e10cSrcweir     /**
407cdf0e10cSrcweir         Appends the string representation of the <code>char</code>
408cdf0e10cSrcweir         argument to this string buffer.
409cdf0e10cSrcweir 
410cdf0e10cSrcweir         The argument is appended to the contents of this string buffer.
411cdf0e10cSrcweir         The length of this string buffer increases by <code>1</code>.
412cdf0e10cSrcweir 
413cdf0e10cSrcweir         @param   ch   a <code>char</code>.
414cdf0e10cSrcweir         @return  this string buffer.
415cdf0e10cSrcweir      */
append(sal_Unicode c)416cdf0e10cSrcweir     OUStringBuffer & append(sal_Unicode c)
417cdf0e10cSrcweir     {
418cdf0e10cSrcweir         return append( &c, 1 );
419cdf0e10cSrcweir     }
420cdf0e10cSrcweir 
421cdf0e10cSrcweir     /**
422cdf0e10cSrcweir         Appends the string representation of the <code>sal_Int32</code>
423cdf0e10cSrcweir         argument to this string buffer.
424cdf0e10cSrcweir 
425cdf0e10cSrcweir         The argument is converted to a string as if by the method
426cdf0e10cSrcweir         <code>String.valueOf</code>, and the characters of that
427cdf0e10cSrcweir         string are then appended to this string buffer.
428cdf0e10cSrcweir 
429cdf0e10cSrcweir         @param   i   an <code>sal_Int32</code>.
430cdf0e10cSrcweir         @return  this string buffer.
431cdf0e10cSrcweir      */
append(sal_Int32 i,sal_Int16 radix=10)432cdf0e10cSrcweir     OUStringBuffer & append(sal_Int32 i, sal_Int16 radix = 10 )
433cdf0e10cSrcweir     {
434cdf0e10cSrcweir         sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT32];
435cdf0e10cSrcweir         return append( sz, rtl_ustr_valueOfInt32( sz, i, radix ) );
436cdf0e10cSrcweir     }
437cdf0e10cSrcweir 
438cdf0e10cSrcweir     /**
439cdf0e10cSrcweir         Appends the string representation of the <code>long</code>
440cdf0e10cSrcweir         argument to this string buffer.
441cdf0e10cSrcweir 
442cdf0e10cSrcweir         The argument is converted to a string as if by the method
443cdf0e10cSrcweir         <code>String.valueOf</code>, and the characters of that
444cdf0e10cSrcweir         string are then appended to this string buffer.
445cdf0e10cSrcweir 
446cdf0e10cSrcweir         @param   l   a <code>long</code>.
447cdf0e10cSrcweir         @return  this string buffer.
448cdf0e10cSrcweir      */
append(sal_Int64 l,sal_Int16 radix=10)449cdf0e10cSrcweir     OUStringBuffer & append(sal_Int64 l, sal_Int16 radix = 10 )
450cdf0e10cSrcweir     {
451cdf0e10cSrcweir         sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT64];
452cdf0e10cSrcweir         return append( sz, rtl_ustr_valueOfInt64( sz, l, radix ) );
453cdf0e10cSrcweir     }
454cdf0e10cSrcweir 
455cdf0e10cSrcweir     /**
456cdf0e10cSrcweir         Appends the string representation of the <code>float</code>
457cdf0e10cSrcweir         argument to this string buffer.
458cdf0e10cSrcweir 
459cdf0e10cSrcweir         The argument is converted to a string as if by the method
460cdf0e10cSrcweir         <code>String.valueOf</code>, and the characters of that
461cdf0e10cSrcweir         string are then appended to this string buffer.
462cdf0e10cSrcweir 
463cdf0e10cSrcweir         @param   f   a <code>float</code>.
464cdf0e10cSrcweir         @return  this string buffer.
465cdf0e10cSrcweir      */
append(float f)466cdf0e10cSrcweir     OUStringBuffer & append(float f)
467cdf0e10cSrcweir     {
468cdf0e10cSrcweir         sal_Unicode sz[RTL_USTR_MAX_VALUEOFFLOAT];
469cdf0e10cSrcweir         return append( sz, rtl_ustr_valueOfFloat( sz, f ) );
470cdf0e10cSrcweir     }
471cdf0e10cSrcweir 
472cdf0e10cSrcweir     /**
473cdf0e10cSrcweir         Appends the string representation of the <code>double</code>
474cdf0e10cSrcweir         argument to this string buffer.
475cdf0e10cSrcweir 
476cdf0e10cSrcweir         The argument is converted to a string as if by the method
477cdf0e10cSrcweir         <code>String.valueOf</code>, and the characters of that
478cdf0e10cSrcweir         string are then appended to this string buffer.
479cdf0e10cSrcweir 
480cdf0e10cSrcweir         @param   d   a <code>double</code>.
481cdf0e10cSrcweir         @return  this string buffer.
482cdf0e10cSrcweir      */
append(double d)483cdf0e10cSrcweir     OUStringBuffer & append(double d)
484cdf0e10cSrcweir     {
485cdf0e10cSrcweir         sal_Unicode sz[RTL_USTR_MAX_VALUEOFDOUBLE];
486cdf0e10cSrcweir         return append( sz, rtl_ustr_valueOfDouble( sz, d ) );
487cdf0e10cSrcweir     }
488cdf0e10cSrcweir 
489cdf0e10cSrcweir     /**
490cdf0e10cSrcweir        Appends a single UTF-32 character to this string buffer.
491cdf0e10cSrcweir 
492cdf0e10cSrcweir        <p>The single UTF-32 character will be represented within the string
493cdf0e10cSrcweir        buffer as either one or two UTF-16 code units.</p>
494cdf0e10cSrcweir 
495cdf0e10cSrcweir        @param c a well-formed UTF-32 code unit (that is, a value in the range
496cdf0e10cSrcweir        <code>0</code>&ndash;<code>0x10FFFF</code>, but excluding
497cdf0e10cSrcweir        <code>0xD800</code>&ndash;<code>0xDFFF</code>)
498cdf0e10cSrcweir 
499cdf0e10cSrcweir        @return
500cdf0e10cSrcweir        this string buffer
501cdf0e10cSrcweir      */
appendUtf32(sal_uInt32 c)502cdf0e10cSrcweir     OUStringBuffer & appendUtf32(sal_uInt32 c) {
503cdf0e10cSrcweir         return insertUtf32(getLength(), c);
504cdf0e10cSrcweir     }
505cdf0e10cSrcweir 
506cdf0e10cSrcweir     /**
507cdf0e10cSrcweir         Inserts the string into this string buffer.
508cdf0e10cSrcweir 
509cdf0e10cSrcweir         The characters of the <code>String</code> argument are inserted, in
510cdf0e10cSrcweir         order, into this string buffer at the indicated offset. The length
511cdf0e10cSrcweir         of this string buffer is increased by the length of the argument.
512cdf0e10cSrcweir         <p>
513cdf0e10cSrcweir         The offset argument must be greater than or equal to
514cdf0e10cSrcweir         <code>0</code>, and less than or equal to the length of this
515cdf0e10cSrcweir         string buffer.
516cdf0e10cSrcweir 
517cdf0e10cSrcweir         @param      offset   the offset.
518cdf0e10cSrcweir         @param      str      a string.
519cdf0e10cSrcweir         @return     this string buffer.
520cdf0e10cSrcweir      */
insert(sal_Int32 offset,const OUString & str)521cdf0e10cSrcweir     OUStringBuffer & insert(sal_Int32 offset, const OUString & str)
522cdf0e10cSrcweir     {
523cdf0e10cSrcweir         return insert( offset, str.getStr(), str.getLength() );
524cdf0e10cSrcweir     }
525cdf0e10cSrcweir 
526cdf0e10cSrcweir     /**
527cdf0e10cSrcweir         Inserts the string representation of the <code>char</code> array
528cdf0e10cSrcweir         argument into this string buffer.
529cdf0e10cSrcweir 
530cdf0e10cSrcweir         The characters of the array argument are inserted into the
531cdf0e10cSrcweir         contents of this string buffer at the position indicated by
532cdf0e10cSrcweir         <code>offset</code>. The length of this string buffer increases by
533cdf0e10cSrcweir         the length of the argument.
534cdf0e10cSrcweir         <p>
535cdf0e10cSrcweir         The offset argument must be greater than or equal to
536cdf0e10cSrcweir         <code>0</code>, and less than or equal to the length of this
537cdf0e10cSrcweir         string buffer.
538cdf0e10cSrcweir 
539cdf0e10cSrcweir         @param      offset   the offset.
540cdf0e10cSrcweir         @param      ch       a character array.
541cdf0e10cSrcweir         @return     this string buffer.
542cdf0e10cSrcweir      */
insert(sal_Int32 offset,const sal_Unicode * str)543cdf0e10cSrcweir     OUStringBuffer & insert( sal_Int32 offset, const sal_Unicode * str )
544cdf0e10cSrcweir     {
545cdf0e10cSrcweir         return insert( offset, str, rtl_ustr_getLength( str ) );
546cdf0e10cSrcweir     }
547cdf0e10cSrcweir 
548cdf0e10cSrcweir     /**
549cdf0e10cSrcweir         Inserts the string representation of the <code>char</code> array
550cdf0e10cSrcweir         argument into this string buffer.
551cdf0e10cSrcweir 
552cdf0e10cSrcweir         The characters of the array argument are inserted into the
553cdf0e10cSrcweir         contents of this string buffer at the position indicated by
554cdf0e10cSrcweir         <code>offset</code>. The length of this string buffer increases by
555cdf0e10cSrcweir         the length of the argument.
556cdf0e10cSrcweir         <p>
557cdf0e10cSrcweir         The offset argument must be greater than or equal to
558cdf0e10cSrcweir         <code>0</code>, and less than or equal to the length of this
559cdf0e10cSrcweir         string buffer.
560cdf0e10cSrcweir 
561cdf0e10cSrcweir         @param      offset   the offset.
562cdf0e10cSrcweir         @param      ch       a character array.
563cdf0e10cSrcweir         @param      len     the number of characters to append.
564cdf0e10cSrcweir         @return     this string buffer.
565cdf0e10cSrcweir      */
insert(sal_Int32 offset,const sal_Unicode * str,sal_Int32 len)566cdf0e10cSrcweir     OUStringBuffer & insert( sal_Int32 offset, const sal_Unicode * str, sal_Int32 len)
567cdf0e10cSrcweir     {
568cdf0e10cSrcweir         // insert behind the last character
569cdf0e10cSrcweir         rtl_uStringbuffer_insert( &pData, &nCapacity, offset, str, len );
570cdf0e10cSrcweir         return *this;
571cdf0e10cSrcweir     }
572cdf0e10cSrcweir 
573cdf0e10cSrcweir     /**
574cdf0e10cSrcweir         Inserts the string representation of the <code>sal_Bool</code>
575cdf0e10cSrcweir         argument into this string buffer.
576cdf0e10cSrcweir 
577cdf0e10cSrcweir         The second argument is converted to a string as if by the method
578cdf0e10cSrcweir         <code>String.valueOf</code>, and the characters of that
579cdf0e10cSrcweir         string are then inserted into this string buffer at the indicated
580cdf0e10cSrcweir         offset.
581cdf0e10cSrcweir         <p>
582cdf0e10cSrcweir         The offset argument must be greater than or equal to
583cdf0e10cSrcweir         <code>0</code>, and less than or equal to the length of this
584cdf0e10cSrcweir         string buffer.
585cdf0e10cSrcweir 
586cdf0e10cSrcweir         @param      offset   the offset.
587cdf0e10cSrcweir         @param      b        a <code>sal_Bool</code>.
588cdf0e10cSrcweir         @return     this string buffer.
589cdf0e10cSrcweir      */
insert(sal_Int32 offset,sal_Bool b)590cdf0e10cSrcweir     OUStringBuffer & insert(sal_Int32 offset, sal_Bool b)
591cdf0e10cSrcweir     {
592cdf0e10cSrcweir         sal_Unicode sz[RTL_USTR_MAX_VALUEOFBOOLEAN];
593cdf0e10cSrcweir         return insert( offset, sz, rtl_ustr_valueOfBoolean( sz, b ) );
594cdf0e10cSrcweir     }
595cdf0e10cSrcweir 
596cdf0e10cSrcweir     /**
597cdf0e10cSrcweir         Inserts the string representation of the <code>char</code>
598cdf0e10cSrcweir         argument into this string buffer.
599cdf0e10cSrcweir 
600cdf0e10cSrcweir         The second argument is inserted into the contents of this string
601cdf0e10cSrcweir         buffer at the position indicated by <code>offset</code>. The length
602cdf0e10cSrcweir         of this string buffer increases by one.
603cdf0e10cSrcweir         <p>
604cdf0e10cSrcweir         The offset argument must be greater than or equal to
605cdf0e10cSrcweir         <code>0</code>, and less than or equal to the length of this
606cdf0e10cSrcweir         string buffer.
607cdf0e10cSrcweir 
608cdf0e10cSrcweir         @param      offset   the offset.
609cdf0e10cSrcweir         @param      ch       a <code>char</code>.
610cdf0e10cSrcweir         @return     this string buffer.
611cdf0e10cSrcweir      */
insert(sal_Int32 offset,sal_Unicode c)612cdf0e10cSrcweir     OUStringBuffer & insert(sal_Int32 offset, sal_Unicode c)
613cdf0e10cSrcweir     {
614cdf0e10cSrcweir         return insert( offset, &c, 1 );
615cdf0e10cSrcweir     }
616cdf0e10cSrcweir 
617cdf0e10cSrcweir     /**
618cdf0e10cSrcweir         Inserts the string representation of the second <code>sal_Int32</code>
619cdf0e10cSrcweir         argument into this string buffer.
620cdf0e10cSrcweir 
621cdf0e10cSrcweir         The second argument is converted to a string as if by the method
622cdf0e10cSrcweir         <code>String.valueOf</code>, and the characters of that
623cdf0e10cSrcweir         string are then inserted into this string buffer at the indicated
624cdf0e10cSrcweir         offset.
625cdf0e10cSrcweir         <p>
626cdf0e10cSrcweir         The offset argument must be greater than or equal to
627cdf0e10cSrcweir         <code>0</code>, and less than or equal to the length of this
628cdf0e10cSrcweir         string buffer.
629cdf0e10cSrcweir 
630cdf0e10cSrcweir         @param      offset   the offset.
631cdf0e10cSrcweir         @param      b        an <code>sal_Int32</code>.
632cdf0e10cSrcweir         @return     this string buffer.
633cdf0e10cSrcweir         @exception  StringIndexOutOfBoundsException  if the offset is invalid.
634cdf0e10cSrcweir      */
insert(sal_Int32 offset,sal_Int32 i,sal_Int16 radix=10)635cdf0e10cSrcweir     OUStringBuffer & insert(sal_Int32 offset, sal_Int32 i, sal_Int16 radix = 10 )
636cdf0e10cSrcweir     {
637cdf0e10cSrcweir         sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT32];
638cdf0e10cSrcweir         return insert( offset, sz, rtl_ustr_valueOfInt32( sz, i, radix ) );
639cdf0e10cSrcweir     }
640cdf0e10cSrcweir 
641cdf0e10cSrcweir     /**
642cdf0e10cSrcweir         Inserts the string representation of the <code>long</code>
643cdf0e10cSrcweir         argument into this string buffer.
644cdf0e10cSrcweir 
645cdf0e10cSrcweir         The second argument is converted to a string as if by the method
646cdf0e10cSrcweir         <code>String.valueOf</code>, and the characters of that
647cdf0e10cSrcweir         string are then inserted into this string buffer at the indicated
648cdf0e10cSrcweir         offset.
649cdf0e10cSrcweir         <p>
650cdf0e10cSrcweir         The offset argument must be greater than or equal to
651cdf0e10cSrcweir         <code>0</code>, and less than or equal to the length of this
652cdf0e10cSrcweir         string buffer.
653cdf0e10cSrcweir 
654cdf0e10cSrcweir         @param      offset   the offset.
655cdf0e10cSrcweir         @param      b        a <code>long</code>.
656cdf0e10cSrcweir         @return     this string buffer.
657cdf0e10cSrcweir         @exception  StringIndexOutOfBoundsException  if the offset is invalid.
658cdf0e10cSrcweir      */
insert(sal_Int32 offset,sal_Int64 l,sal_Int16 radix=10)659cdf0e10cSrcweir     OUStringBuffer & insert(sal_Int32 offset, sal_Int64 l, sal_Int16 radix = 10 )
660cdf0e10cSrcweir     {
661cdf0e10cSrcweir         sal_Unicode sz[RTL_USTR_MAX_VALUEOFINT64];
662cdf0e10cSrcweir         return insert( offset, sz, rtl_ustr_valueOfInt64( sz, l, radix ) );
663cdf0e10cSrcweir     }
664cdf0e10cSrcweir 
665cdf0e10cSrcweir     /**
666cdf0e10cSrcweir         Inserts the string representation of the <code>float</code>
667cdf0e10cSrcweir         argument into this string buffer.
668cdf0e10cSrcweir 
669cdf0e10cSrcweir         The second argument is converted to a string as if by the method
670cdf0e10cSrcweir         <code>String.valueOf</code>, and the characters of that
671cdf0e10cSrcweir         string are then inserted into this string buffer at the indicated
672cdf0e10cSrcweir         offset.
673cdf0e10cSrcweir         <p>
674cdf0e10cSrcweir         The offset argument must be greater than or equal to
675cdf0e10cSrcweir         <code>0</code>, and less than or equal to the length of this
676cdf0e10cSrcweir         string buffer.
677cdf0e10cSrcweir 
678cdf0e10cSrcweir         @param      offset   the offset.
679cdf0e10cSrcweir         @param      b        a <code>float</code>.
680cdf0e10cSrcweir         @return     this string buffer.
681cdf0e10cSrcweir         @exception  StringIndexOutOfBoundsException  if the offset is invalid.
682cdf0e10cSrcweir      */
insert(sal_Int32 offset,float f)683cdf0e10cSrcweir     OUStringBuffer insert(sal_Int32 offset, float f)
684cdf0e10cSrcweir     {
685cdf0e10cSrcweir         sal_Unicode sz[RTL_USTR_MAX_VALUEOFFLOAT];
686cdf0e10cSrcweir         return insert( offset, sz, rtl_ustr_valueOfFloat( sz, f ) );
687cdf0e10cSrcweir     }
688cdf0e10cSrcweir 
689cdf0e10cSrcweir     /**
690cdf0e10cSrcweir         Inserts the string representation of the <code>double</code>
691cdf0e10cSrcweir         argument into this string buffer.
692cdf0e10cSrcweir 
693cdf0e10cSrcweir         The second argument is converted to a string as if by the method
694cdf0e10cSrcweir         <code>String.valueOf</code>, and the characters of that
695cdf0e10cSrcweir         string are then inserted into this string buffer at the indicated
696cdf0e10cSrcweir         offset.
697cdf0e10cSrcweir         <p>
698cdf0e10cSrcweir         The offset argument must be greater than or equal to
699cdf0e10cSrcweir         <code>0</code>, and less than or equal to the length of this
700cdf0e10cSrcweir         string buffer.
701cdf0e10cSrcweir 
702cdf0e10cSrcweir         @param      offset   the offset.
703cdf0e10cSrcweir         @param      b        a <code>double</code>.
704cdf0e10cSrcweir         @return     this string buffer.
705cdf0e10cSrcweir         @exception  StringIndexOutOfBoundsException  if the offset is invalid.
706cdf0e10cSrcweir      */
insert(sal_Int32 offset,double d)707cdf0e10cSrcweir     OUStringBuffer & insert(sal_Int32 offset, double d)
708cdf0e10cSrcweir     {
709cdf0e10cSrcweir         sal_Unicode sz[RTL_USTR_MAX_VALUEOFDOUBLE];
710cdf0e10cSrcweir         return insert( offset, sz, rtl_ustr_valueOfDouble( sz, d ) );
711cdf0e10cSrcweir     }
712cdf0e10cSrcweir 
713cdf0e10cSrcweir     /**
714cdf0e10cSrcweir        Inserts a single UTF-32 character into this string buffer.
715cdf0e10cSrcweir 
716cdf0e10cSrcweir        <p>The single UTF-32 character will be represented within the string
717cdf0e10cSrcweir        buffer as either one or two UTF-16 code units.</p>
718cdf0e10cSrcweir 
719cdf0e10cSrcweir        @param offset the offset into this string buffer (from zero to the length
720cdf0e10cSrcweir        of this string buffer, inclusive)
721cdf0e10cSrcweir 
722cdf0e10cSrcweir        @param c a well-formed UTF-32 code unit (that is, a value in the range
723cdf0e10cSrcweir        <code>0</code>&ndash;<code>0x10FFFF</code>, but excluding
724cdf0e10cSrcweir        <code>0xD800</code>&ndash;<code>0xDFFF</code>)
725cdf0e10cSrcweir 
726cdf0e10cSrcweir        @return this string buffer
727cdf0e10cSrcweir      */
insertUtf32(sal_Int32 offset,sal_uInt32 c)728cdf0e10cSrcweir     OUStringBuffer & insertUtf32(sal_Int32 offset, sal_uInt32 c) {
729cdf0e10cSrcweir         rtl_uStringbuffer_insertUtf32(&pData, &nCapacity, offset, c);
730cdf0e10cSrcweir         return *this;
731cdf0e10cSrcweir     }
732cdf0e10cSrcweir 
733cdf0e10cSrcweir     /** Allows access to the internal data of this OUStringBuffer, for effective
734cdf0e10cSrcweir         manipulation.
735cdf0e10cSrcweir 
736cdf0e10cSrcweir         This method should be used with care.  After you have called this
737cdf0e10cSrcweir         method, you may use the returned pInternalData or pInternalCapacity only
738cdf0e10cSrcweir         as long as you make no other method call on this OUStringBuffer.
739cdf0e10cSrcweir 
740cdf0e10cSrcweir         @param pInternalData
741cdf0e10cSrcweir         This output parameter receives a pointer to the internal data
742cdf0e10cSrcweir         (rtl_uString pointer).  pInternalData itself must not be null.
743cdf0e10cSrcweir 
744cdf0e10cSrcweir         @param pInternalCapacity
745cdf0e10cSrcweir         This output parameter receives a pointer to the internal capacity.
746cdf0e10cSrcweir         pInternalCapacity itself must not be null.
747cdf0e10cSrcweir      */
accessInternals(rtl_uString *** pInternalData,sal_Int32 ** pInternalCapacity)748cdf0e10cSrcweir     inline void accessInternals(rtl_uString *** pInternalData,
749cdf0e10cSrcweir                                 sal_Int32 ** pInternalCapacity)
750cdf0e10cSrcweir     {
751cdf0e10cSrcweir         *pInternalData = &pData;
752cdf0e10cSrcweir         *pInternalCapacity = &nCapacity;
753cdf0e10cSrcweir     }
754cdf0e10cSrcweir 
755cdf0e10cSrcweir private:
756cdf0e10cSrcweir     /**
757cdf0e10cSrcweir         A pointer to the data structur which contains the data.
758cdf0e10cSrcweir      */
759cdf0e10cSrcweir     rtl_uString * pData;
760cdf0e10cSrcweir 
761cdf0e10cSrcweir     /**
762cdf0e10cSrcweir         The len of the pData->buffer.
763cdf0e10cSrcweir      */
764cdf0e10cSrcweir     sal_Int32       nCapacity;
765cdf0e10cSrcweir };
766cdf0e10cSrcweir 
767cdf0e10cSrcweir }
768cdf0e10cSrcweir 
769cdf0e10cSrcweir #endif  /* __cplusplus */
770cdf0e10cSrcweir #endif  /* _RTL_USTRBUF_HXX_ */
771