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 43948 : 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 43948 : mpData = NULL;
27 : rtl_string2UString( (rtl_uString **)(&mpData),
28 43948 : pByteStr, ImplStringLen( pByteStr ),
29 87896 : eTextEncoding, nCvtFlags );
30 43948 : }
31 :
32 80426 : 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 80426 : if ( nLen == STRING_LEN )
39 0 : nLen = ImplStringLen( pByteStr );
40 :
41 80426 : mpData = NULL;
42 : rtl_string2UString( (rtl_uString **)(&mpData),
43 : pByteStr, nLen,
44 80426 : eTextEncoding, nCvtFlags );
45 80426 : }
46 :
47 8693292 : UniString::UniString( const OUString& rStr )
48 8693292 : : mpData(NULL)
49 : {
50 : DBG_CTOR( UniString, DbgCheckUniString );
51 :
52 : OSL_ENSURE(rStr.pData->length < STRING_MAXLEN,
53 : "Overflowing OUString -> UniString cut to zero length");
54 :
55 :
56 8693292 : if (rStr.pData->length < STRING_MAXLEN)
57 : {
58 8693292 : mpData = reinterpret_cast< UniStringData * >(const_cast< OUString & >(rStr).pData);
59 8693292 : STRING_ACQUIRE((STRING_TYPE *)mpData);
60 : }
61 : else
62 : {
63 0 : STRING_NEW((STRING_TYPE **)&mpData);
64 : }
65 8693292 : }
66 :
67 2654877 : UniString& UniString::Assign( const OUString& rStr )
68 : {
69 : DBG_CHKTHIS( UniString, DbgCheckUniString );
70 :
71 : OSL_ENSURE(rStr.pData->length < STRING_MAXLEN,
72 : "Overflowing OUString -> UniString cut to zero length");
73 :
74 2654877 : if (rStr.pData->length < STRING_MAXLEN)
75 : {
76 2654877 : if( mpData != NULL )
77 2654176 : STRING_RELEASE((STRING_TYPE *)mpData);
78 2654877 : mpData = reinterpret_cast< UniStringData * >(const_cast< OUString & >(rStr).pData);
79 2654877 : STRING_ACQUIRE((STRING_TYPE *)mpData);
80 : }
81 : else
82 : {
83 0 : STRING_NEW((STRING_TYPE **)&mpData);
84 : }
85 :
86 2654877 : return *this;
87 : }
88 :
89 : #include <rtl/ustrbuf.hxx>
90 : #include <tools/rc.hxx>
91 : #include <tools/rcid.h>
92 :
93 324632 : UniString::UniString( const ResId& rResId )
94 324632 : : mpData(NULL)
95 : {
96 324632 : OUString sStr(rResId.toString());
97 :
98 : DBG_CTOR( UniString, DbgCheckUniString );
99 :
100 : OSL_ENSURE(sStr.pData->length < STRING_MAXLEN,
101 : "Overflowing OUString -> UniString cut to zero length");
102 :
103 324632 : if (sStr.pData->length < STRING_MAXLEN)
104 : {
105 324632 : mpData = reinterpret_cast< UniStringData * >(sStr.pData);
106 324632 : STRING_ACQUIRE((STRING_TYPE *)mpData);
107 : }
108 : else
109 : {
110 0 : STRING_NEW((STRING_TYPE **)&mpData);
111 324632 : }
112 324632 : }
113 :
114 964685 : OUString ResId::toString() const
115 : {
116 964685 : SetRT( RSC_STRING );
117 964685 : ResMgr* pResMgr = GetResMgr();
118 :
119 964685 : if ( !pResMgr || !pResMgr->GetResource( *this ) )
120 : {
121 0 : OUString sRet;
122 :
123 : #if OSL_DEBUG_LEVEL > 0
124 : sRet = OUStringBuffer().
125 : append("<resource id ").
126 : append(static_cast<sal_Int32>(GetId())).
127 : append(" 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 964685 : RSHEADER_TYPE * pResHdr = (RSHEADER_TYPE*)pResMgr->GetClass();
139 :
140 964685 : sal_Int32 nStringLen = rtl_str_getLength( (char*)(pResHdr+1) );
141 964685 : OUString sRet((const char*)(pResHdr+1), nStringLen, RTL_TEXTENCODING_UTF8);
142 :
143 : sal_uInt32 nSize = sizeof( RSHEADER_TYPE )
144 964685 : + sal::static_int_cast< sal_uInt32 >(nStringLen) + 1;
145 964685 : nSize += nSize % 2;
146 964685 : pResMgr->Increment( nSize );
147 :
148 964685 : ResHookProc pImplResHookProc = ResMgr::GetReadStringHook();
149 964685 : if ( pImplResHookProc )
150 807427 : sRet = pImplResHookProc(sRet);
151 964685 : return sRet;
152 : }
153 :
154 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|