Branch data 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 : 345273 : 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 : 345273 : mpData = NULL;
27 : : rtl_string2UString( (rtl_uString **)(&mpData),
28 : 345273 : pByteStr, ImplStringLen( pByteStr ),
29 : 345273 : eTextEncoding, nCvtFlags );
30 : 345273 : }
31 : :
32 : 414379 : 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 [ - + ]: 414379 : if ( nLen == STRING_LEN )
39 : 0 : nLen = ImplStringLen( pByteStr );
40 : :
41 : 414379 : mpData = NULL;
42 : : rtl_string2UString( (rtl_uString **)(&mpData),
43 : : pByteStr, nLen,
44 : 414379 : eTextEncoding, nCvtFlags );
45 : 414379 : }
46 : :
47 : 17709236 : UniString::UniString( const rtl::OUString& rStr )
48 : 17709236 : : 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 [ + - ]: 17709236 : if (rStr.pData->length < STRING_MAXLEN)
57 : : {
58 : 17709236 : mpData = reinterpret_cast< UniStringData * >(const_cast< rtl::OUString & >(rStr).pData);
59 : 17709236 : STRING_ACQUIRE((STRING_TYPE *)mpData);
60 : : }
61 : : else
62 : : {
63 : 0 : STRING_NEW((STRING_TYPE **)&mpData);
64 : : }
65 : 17709237 : }
66 : :
67 : 4216375 : 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 [ + - ]: 4216375 : if (rStr.pData->length < STRING_MAXLEN)
75 : : {
76 : 4216375 : STRING_RELEASE((STRING_TYPE *)mpData);
77 : 4216375 : mpData = reinterpret_cast< UniStringData * >(const_cast< rtl::OUString & >(rStr).pData);
78 : 4216375 : STRING_ACQUIRE((STRING_TYPE *)mpData);
79 : : }
80 : : else
81 : : {
82 : 0 : STRING_NEW((STRING_TYPE **)&mpData);
83 : : }
84 : :
85 : 4216375 : return *this;
86 : : }
87 : :
88 : : #include <rtl/ustrbuf.hxx>
89 : : #include <tools/rc.hxx>
90 : : #include <tools/rcid.h>
91 : :
92 : 624067 : UniString::UniString( const ResId& rResId )
93 : 624067 : : mpData(NULL)
94 : : {
95 [ + - ]: 624067 : rtl::OUString sStr(rResId.toString());
96 : :
97 : : DBG_CTOR( UniString, DbgCheckUniString );
98 : :
99 : : OSL_ENSURE(sStr.pData->length < STRING_MAXLEN,
100 : : "Overflowing rtl::OUString -> UniString cut to zero length");
101 : :
102 [ + - ]: 624067 : if (sStr.pData->length < STRING_MAXLEN)
103 : : {
104 : 624067 : mpData = reinterpret_cast< UniStringData * >(sStr.pData);
105 : 624067 : STRING_ACQUIRE((STRING_TYPE *)mpData);
106 : : }
107 : : else
108 : : {
109 : 0 : STRING_NEW((STRING_TYPE **)&mpData);
110 : 624067 : }
111 : 624067 : }
112 : :
113 : 1959639 : rtl::OUString ResId::toString() const
114 : : {
115 : 1959639 : SetRT( RSC_STRING );
116 : 1959639 : ResMgr* pResMgr = GetResMgr();
117 : :
118 [ + - ][ - + ]: 1959639 : if ( !pResMgr || !pResMgr->GetResource( *this ) )
[ - + ][ + - ]
119 : : {
120 : 0 : rtl::OUString sRet;
121 : :
122 : : #if OSL_DEBUG_LEVEL > 0
123 : : sRet = rtl::OUStringBuffer().
124 : : appendAscii(RTL_CONSTASCII_STRINGPARAM("<resource id ")).
125 : : append(static_cast<sal_Int32>(GetId())).
126 : : appendAscii(RTL_CONSTASCII_STRINGPARAM(" not found>")).
127 : : makeStringAndClear();
128 : : #endif
129 : :
130 [ # # ]: 0 : if( pResMgr )
131 [ # # ]: 0 : pResMgr->PopContext();
132 : :
133 : 0 : return sRet;
134 : : }
135 : :
136 : : // String loading
137 [ + - ]: 1959639 : RSHEADER_TYPE * pResHdr = (RSHEADER_TYPE*)pResMgr->GetClass();
138 : :
139 : 1959639 : sal_Int32 nStringLen = rtl_str_getLength( (char*)(pResHdr+1) );
140 [ + - ]: 1959639 : rtl::OUString sRet((const char*)(pResHdr+1), nStringLen, RTL_TEXTENCODING_UTF8);
141 : :
142 : : sal_uInt32 nSize = sizeof( RSHEADER_TYPE )
143 : 1959639 : + sal::static_int_cast< sal_uInt32 >(nStringLen) + 1;
144 : 1959639 : nSize += nSize % 2;
145 [ + - ]: 1959639 : pResMgr->Increment( nSize );
146 : :
147 [ + - ]: 1959639 : ResHookProc pImplResHookProc = ResMgr::GetReadStringHook();
148 [ + + ]: 1959639 : if ( pImplResHookProc )
149 [ + - ]: 1619745 : sRet = pImplResHookProc(sRet);
150 : 1959639 : return sRet;
151 : : }
152 : :
153 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|