Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 41499 : UniString::UniString( const char* pByteStr,
21 : rtl_TextEncoding eTextEncoding, sal_uInt32 nCvtFlags )
22 : {
23 : DBG_CTOR( UniString, DbgCheckUniString );
24 : DBG_ASSERT( pByteStr, "UniString::UniString() - pByteStr is NULL" );
25 :
26 41499 : mpData = NULL;
27 : rtl_string2UString( (rtl_uString **)(&mpData),
28 41499 : pByteStr, ImplStringLen( pByteStr ),
29 82998 : eTextEncoding, nCvtFlags );
30 41499 : }
31 :
32 76451 : UniString::UniString( const char* pByteStr, xub_StrLen nLen,
33 : rtl_TextEncoding eTextEncoding, sal_uInt32 nCvtFlags )
34 : {
35 : DBG_CTOR( UniString, DbgCheckUniString );
36 : DBG_ASSERT( pByteStr, "UniString::UniString() - pByteStr is NULL" );
37 :
38 76451 : if ( nLen == STRING_LEN )
39 0 : nLen = ImplStringLen( pByteStr );
40 :
41 76451 : mpData = NULL;
42 : rtl_string2UString( (rtl_uString **)(&mpData),
43 : pByteStr, nLen,
44 76451 : eTextEncoding, nCvtFlags );
45 76451 : }
46 :
47 3427191 : UniString::UniString( const rtl::OUString& rStr )
48 3427191 : : mpData(NULL)
49 : {
50 : DBG_CTOR( UniString, DbgCheckUniString );
51 :
52 : OSL_ENSURE(rStr.pData->length < STRING_MAXLEN,
53 : "Overflowing rtl::OUString -> UniString cut to zero length");
54 :
55 :
56 3427191 : if (rStr.pData->length < STRING_MAXLEN)
57 : {
58 3427191 : mpData = reinterpret_cast< UniStringData * >(const_cast< rtl::OUString & >(rStr).pData);
59 3427191 : STRING_ACQUIRE((STRING_TYPE *)mpData);
60 : }
61 : else
62 : {
63 0 : STRING_NEW((STRING_TYPE **)&mpData);
64 : }
65 3427191 : }
66 :
67 782734 : UniString& UniString::Assign( const rtl::OUString& rStr )
68 : {
69 : DBG_CHKTHIS( UniString, DbgCheckUniString );
70 :
71 : OSL_ENSURE(rStr.pData->length < STRING_MAXLEN,
72 : "Overflowing rtl::OUString -> UniString cut to zero length");
73 :
74 782734 : if (rStr.pData->length < STRING_MAXLEN)
75 : {
76 782734 : if( mpData != NULL )
77 782732 : STRING_RELEASE((STRING_TYPE *)mpData);
78 782734 : mpData = reinterpret_cast< UniStringData * >(const_cast< rtl::OUString & >(rStr).pData);
79 782734 : STRING_ACQUIRE((STRING_TYPE *)mpData);
80 : }
81 : else
82 : {
83 0 : STRING_NEW((STRING_TYPE **)&mpData);
84 : }
85 :
86 782734 : return *this;
87 : }
88 :
89 : #include <rtl/ustrbuf.hxx>
90 : #include <tools/rc.hxx>
91 : #include <tools/rcid.h>
92 :
93 127158 : UniString::UniString( const ResId& rResId )
94 127158 : : mpData(NULL)
95 : {
96 127158 : rtl::OUString sStr(rResId.toString());
97 :
98 : DBG_CTOR( UniString, DbgCheckUniString );
99 :
100 : OSL_ENSURE(sStr.pData->length < STRING_MAXLEN,
101 : "Overflowing rtl::OUString -> UniString cut to zero length");
102 :
103 127158 : if (sStr.pData->length < STRING_MAXLEN)
104 : {
105 127158 : mpData = reinterpret_cast< UniStringData * >(sStr.pData);
106 127158 : STRING_ACQUIRE((STRING_TYPE *)mpData);
107 : }
108 : else
109 : {
110 0 : STRING_NEW((STRING_TYPE **)&mpData);
111 127158 : }
112 127158 : }
113 :
114 285600 : rtl::OUString ResId::toString() const
115 : {
116 285600 : SetRT( RSC_STRING );
117 285600 : ResMgr* pResMgr = GetResMgr();
118 :
119 285600 : if ( !pResMgr || !pResMgr->GetResource( *this ) )
120 : {
121 0 : rtl::OUString sRet;
122 :
123 : #if OSL_DEBUG_LEVEL > 0
124 : sRet = rtl::OUStringBuffer().
125 : appendAscii(RTL_CONSTASCII_STRINGPARAM("<resource id ")).
126 : append(static_cast<sal_Int32>(GetId())).
127 : appendAscii(RTL_CONSTASCII_STRINGPARAM(" not found>")).
128 : makeStringAndClear();
129 : #endif
130 :
131 0 : if( pResMgr )
132 0 : pResMgr->PopContext();
133 :
134 0 : return sRet;
135 : }
136 :
137 : // String loading
138 285600 : RSHEADER_TYPE * pResHdr = (RSHEADER_TYPE*)pResMgr->GetClass();
139 :
140 285600 : sal_Int32 nStringLen = rtl_str_getLength( (char*)(pResHdr+1) );
141 285600 : rtl::OUString sRet((const char*)(pResHdr+1), nStringLen, RTL_TEXTENCODING_UTF8);
142 :
143 : sal_uInt32 nSize = sizeof( RSHEADER_TYPE )
144 285600 : + sal::static_int_cast< sal_uInt32 >(nStringLen) + 1;
145 285600 : nSize += nSize % 2;
146 285600 : pResMgr->Increment( nSize );
147 :
148 285600 : ResHookProc pImplResHookProc = ResMgr::GetReadStringHook();
149 285600 : if ( pImplResHookProc )
150 820 : sRet = pImplResHookProc(sRet);
151 285600 : return sRet;
152 : }
153 :
154 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|