update dev300-m57
[ooovba.git] / tools / source / string / tustring.cxx
blobf04ac7708f365f7162a1cb55aff5f6ce25e7ea01
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tustring.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_tools.hxx"
34 #include <string.h>
36 #include "boost/static_assert.hpp"
38 #ifndef _OSL_INTERLCK_H
39 #include <osl/interlck.h>
40 #endif
41 #ifndef _RTL_ALLOC_H
42 #include <rtl/alloc.h>
43 #endif
44 #ifndef _RTL_MEMORY_H
45 #include <rtl/memory.h>
46 #endif
47 #include <rtl/tencinfo.h>
48 #include <rtl/instance.hxx>
50 #include <tools/string.hxx>
51 #include <impstrg.hxx>
53 #include <tools/debug.hxx>
55 // =======================================================================
57 DBG_NAME( UniString )
58 DBG_NAMEEX( ByteString )
60 // -----------------------------------------------------------------------
62 #define STRCODE sal_Unicode
63 #define STRCODEU sal_Unicode
64 #define STRING UniString
65 #define STRINGDATA UniStringData
66 #define DBGCHECKSTRING DbgCheckUniString
67 #define STRING_TYPE rtl_uString
68 #define STRING_ACQUIRE rtl_uString_acquire
69 #define STRING_RELEASE rtl_uString_release
70 #define STRING_NEW rtl_uString_new
72 // -----------------------------------------------------------------------
74 #include <strimp.cxx>
75 #include <strucvt.cxx>
76 #include <strascii.cxx>
78 UniString::UniString(char c): mpData(ImplAllocData(1)) { mpData->maStr[0] = c; }
80 // -----------------------------------------------------------------------
82 UniString UniString::CreateFromInt32( sal_Int32 n, sal_Int16 nRadix )
84 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT32];
85 BOOST_STATIC_ASSERT(RTL_USTR_MAX_VALUEOFINT32 <= STRING_MAXLEN);
86 return UniString(
87 aBuf,
88 static_cast< xub_StrLen >(rtl_ustr_valueOfInt32( aBuf, n, nRadix )) );
91 // -----------------------------------------------------------------------
93 UniString UniString::CreateFromInt64( sal_Int64 n, sal_Int16 nRadix )
95 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT64];
96 BOOST_STATIC_ASSERT(RTL_USTR_MAX_VALUEOFINT64 <= STRING_MAXLEN);
97 return UniString(
98 aBuf,
99 static_cast< xub_StrLen >(rtl_ustr_valueOfInt64( aBuf, n, nRadix )) );
102 // -----------------------------------------------------------------------
104 UniString UniString::CreateFromFloat( float f )
106 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFFLOAT];
107 BOOST_STATIC_ASSERT(RTL_USTR_MAX_VALUEOFFLOAT <= STRING_MAXLEN);
108 return UniString(
109 aBuf, static_cast< xub_StrLen >(rtl_ustr_valueOfFloat( aBuf, f )) );
112 // -----------------------------------------------------------------------
114 UniString UniString::CreateFromDouble( double d )
116 sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFDOUBLE];
117 BOOST_STATIC_ASSERT(RTL_USTR_MAX_VALUEOFDOUBLE <= STRING_MAXLEN);
118 return UniString(
119 aBuf, static_cast< xub_StrLen >(rtl_ustr_valueOfDouble( aBuf, d )) );
122 // -----------------------------------------------------------------------
124 namespace { struct Empty : public rtl::Static< const UniString, Empty> {}; }
125 const UniString& UniString::EmptyString()
127 return Empty::get();
130 // -----------------------------------------------------------------------
132 sal_Int32 UniString::ToInt32() const
134 DBG_CHKTHIS( UniString, DbgCheckUniString );
136 return rtl_ustr_toInt32( mpData->maStr, 10 );
139 // -----------------------------------------------------------------------
141 sal_Int64 UniString::ToInt64() const
143 DBG_CHKTHIS( UniString, DbgCheckUniString );
145 return rtl_ustr_toInt64( mpData->maStr, 10 );
148 // -----------------------------------------------------------------------
150 float UniString::ToFloat() const
152 DBG_CHKTHIS( UniString, DbgCheckUniString );
154 return rtl_ustr_toFloat( mpData->maStr );
157 // -----------------------------------------------------------------------
159 double UniString::ToDouble() const
161 DBG_CHKTHIS( UniString, DbgCheckUniString );
163 return rtl_ustr_toDouble( mpData->maStr );