1*34dd1e25SAndrew Rist /**************************************************************
2*34dd1e25SAndrew Rist  *
3*34dd1e25SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*34dd1e25SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*34dd1e25SAndrew Rist  * distributed with this work for additional information
6*34dd1e25SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*34dd1e25SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*34dd1e25SAndrew Rist  * "License"); you may not use this file except in compliance
9*34dd1e25SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*34dd1e25SAndrew Rist  *
11*34dd1e25SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*34dd1e25SAndrew Rist  *
13*34dd1e25SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*34dd1e25SAndrew Rist  * software distributed under the License is distributed on an
15*34dd1e25SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*34dd1e25SAndrew Rist  * KIND, either express or implied.  See the License for the
17*34dd1e25SAndrew Rist  * specific language governing permissions and limitations
18*34dd1e25SAndrew Rist  * under the License.
19*34dd1e25SAndrew Rist  *
20*34dd1e25SAndrew Rist  *************************************************************/
21*34dd1e25SAndrew Rist 
22*34dd1e25SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <stdio.h>
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <sal/main.h>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
29cdf0e10cSrcweir #include <rtl/string.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir using rtl::OUString;
32cdf0e10cSrcweir using rtl::OUStringBuffer;
33cdf0e10cSrcweir using rtl::OString;
34cdf0e10cSrcweir 
SAL_IMPLEMENT_MAIN()35cdf0e10cSrcweir SAL_IMPLEMENT_MAIN()
36cdf0e10cSrcweir {
37cdf0e10cSrcweir     // string concatination
38cdf0e10cSrcweir 
39cdf0e10cSrcweir     sal_Int32 n = 42;
40cdf0e10cSrcweir     double pi = 3.14159;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir     // give it an initial size, should be a good guess.
43cdf0e10cSrcweir     // stringbuffer extends if necessary
44cdf0e10cSrcweir     OUStringBuffer buf( 128 );
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     // append an ascii string
47cdf0e10cSrcweir     buf.appendAscii( "pi ( here " );
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     // numbers can be simply appended
50cdf0e10cSrcweir     buf.append( pi );
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     // lets the compiler count the stringlength, so this is more efficient than
53cdf0e10cSrcweir     // the above appendAscii call, where length of the string must be calculated at
54cdf0e10cSrcweir     // runtime
55cdf0e10cSrcweir     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" ) multiplied with " ) );
56cdf0e10cSrcweir     buf.append( n );
57cdf0e10cSrcweir     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" gives ") );
58cdf0e10cSrcweir     buf.append( (double)( n * pi ) );
59cdf0e10cSrcweir     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "." ) );
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     // now transfer the buffer into the string.
62cdf0e10cSrcweir     // afterwards buffer is empty and may be reused again !
63cdf0e10cSrcweir     OUString string = buf.makeStringAndClear();
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     // I could of course also used the OStringBuffer directly
66cdf0e10cSrcweir     OString oString = rtl::OUStringToOString( string , RTL_TEXTENCODING_ASCII_US );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     // just to print something
69cdf0e10cSrcweir     printf( "%s\n" ,oString.getStr() );
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     return 0;
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
74