1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 UniString::UniString( const char* pByteStr
,
21 rtl_TextEncoding eTextEncoding
, sal_uInt32 nCvtFlags
)
23 DBG_CTOR( UniString
, DbgCheckUniString
);
24 DBG_ASSERT( pByteStr
, "UniString::UniString() - pByteStr is NULL" );
27 rtl_string2UString( (rtl_uString
**)(&mpData
),
28 pByteStr
, ImplStringLen( pByteStr
),
29 eTextEncoding
, nCvtFlags
);
32 UniString::UniString( const char* pByteStr
, xub_StrLen nLen
,
33 rtl_TextEncoding eTextEncoding
, sal_uInt32 nCvtFlags
)
35 DBG_CTOR( UniString
, DbgCheckUniString
);
36 DBG_ASSERT( pByteStr
, "UniString::UniString() - pByteStr is NULL" );
38 if ( nLen
== STRING_LEN
)
39 nLen
= ImplStringLen( pByteStr
);
42 rtl_string2UString( (rtl_uString
**)(&mpData
),
44 eTextEncoding
, nCvtFlags
);
47 UniString::UniString( const OUString
& rStr
)
50 DBG_CTOR( UniString
, DbgCheckUniString
);
52 OSL_ENSURE(rStr
.pData
->length
< STRING_MAXLEN
,
53 "Overflowing OUString -> UniString cut to zero length");
56 if (rStr
.pData
->length
< STRING_MAXLEN
)
58 mpData
= reinterpret_cast< UniStringData
* >(const_cast< OUString
& >(rStr
).pData
);
59 STRING_ACQUIRE((STRING_TYPE
*)mpData
);
63 STRING_NEW((STRING_TYPE
**)&mpData
);
67 UniString
& UniString::Assign( const OUString
& rStr
)
69 DBG_CHKTHIS( UniString
, DbgCheckUniString
);
71 OSL_ENSURE(rStr
.pData
->length
< STRING_MAXLEN
,
72 "Overflowing OUString -> UniString cut to zero length");
74 if (rStr
.pData
->length
< STRING_MAXLEN
)
77 STRING_RELEASE((STRING_TYPE
*)mpData
);
78 mpData
= reinterpret_cast< UniStringData
* >(const_cast< OUString
& >(rStr
).pData
);
79 STRING_ACQUIRE((STRING_TYPE
*)mpData
);
83 STRING_NEW((STRING_TYPE
**)&mpData
);
89 #include <rtl/ustrbuf.hxx>
90 #include <tools/rc.hxx>
91 #include <tools/rcid.h>
93 UniString::UniString( const ResId
& rResId
)
96 OUString
sStr(rResId
.toString());
98 DBG_CTOR( UniString
, DbgCheckUniString
);
100 OSL_ENSURE(sStr
.pData
->length
< STRING_MAXLEN
,
101 "Overflowing OUString -> UniString cut to zero length");
103 if (sStr
.pData
->length
< STRING_MAXLEN
)
105 mpData
= reinterpret_cast< UniStringData
* >(sStr
.pData
);
106 STRING_ACQUIRE((STRING_TYPE
*)mpData
);
110 STRING_NEW((STRING_TYPE
**)&mpData
);
114 OUString
ResId::toString() const
117 ResMgr
* pResMgr
= GetResMgr();
119 if ( !pResMgr
|| !pResMgr
->GetResource( *this ) )
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();
132 pResMgr
->PopContext();
138 RSHEADER_TYPE
* pResHdr
= (RSHEADER_TYPE
*)pResMgr
->GetClass();
140 sal_Int32 nStringLen
= rtl_str_getLength( (char*)(pResHdr
+1) );
141 OUString
sRet((const char*)(pResHdr
+1), nStringLen
, RTL_TEXTENCODING_UTF8
);
143 sal_uInt32 nSize
= sizeof( RSHEADER_TYPE
)
144 + sal::static_int_cast
< sal_uInt32
>(nStringLen
) + 1;
146 pResMgr
->Increment( nSize
);
148 ResHookProc pImplResHookProc
= ResMgr::GetReadStringHook();
149 if ( pImplResHookProc
)
150 sRet
= pImplResHookProc(sRet
);
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */