summaryrefslogtreecommitdiff
path: root/tools/source/string/strucvt.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'tools/source/string/strucvt.cxx')
-rw-r--r--tools/source/string/strucvt.cxx85
1 files changed, 44 insertions, 41 deletions
diff --git a/tools/source/string/strucvt.cxx b/tools/source/string/strucvt.cxx
index 144d9e41603a..94884db24c27 100644
--- a/tools/source/string/strucvt.cxx
+++ b/tools/source/string/strucvt.cxx
@@ -26,23 +26,6 @@
*
************************************************************************/
-
-// =======================================================================
-
-void UniString::InitStringRes( const char* pUTF8Str, sal_Int32 nLen )
-{
- DBG_CTOR( UniString, DbgCheckUniString );
- OSL_ENSURE(nLen <= STRING_MAXLEN, "Overflowing UniString");
-
- mpData = NULL;
- rtl_string2UString( (rtl_uString **)(&mpData),
- pUTF8Str, nLen,
- RTL_TEXTENCODING_UTF8,
- RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MAPTOPRIVATE |
- RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT |
- RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT );
-}
-
// =======================================================================
UniString::UniString( const rtl::OString& rByteStr, rtl_TextEncoding eTextEncoding, sal_uInt32 nCvtFlags )
@@ -134,51 +117,71 @@ UniString& UniString::Assign( const rtl::OUString& rStr )
// =======================================================================
+#include <rtl/ustrbuf.hxx>
#include <tools/rc.hxx>
#include <tools/rcid.h>
UniString::UniString( const ResId& rResId )
+ : mpData(NULL)
{
- rResId.SetRT( RSC_STRING );
- ResMgr* pResMgr = rResId.GetResMgr();
- mpData = NULL;
- if ( pResMgr && pResMgr->GetResource( rResId ) )
- {
- // String laden
- RSHEADER_TYPE * pResHdr = (RSHEADER_TYPE*)pResMgr->GetClass();
- //sal_uInt32 nLen = pResHdr->GetLocalOff() - sizeof( RSHEADER_TYPE );
+ rtl::OUString sStr(ResId::toString(rResId));
- sal_Int32 nStringLen = rtl_str_getLength( (char*)(pResHdr+1) );
- InitStringRes( (const char*)(pResHdr+1), nStringLen );
+ DBG_CTOR( UniString, DbgCheckUniString );
+
+ OSL_ENSURE(sStr.pData->length < STRING_MAXLEN,
+ "Overflowing rtl::OUString -> UniString cut to zero length");
- sal_uInt32 nSize = sizeof( RSHEADER_TYPE )
- + sal::static_int_cast< sal_uInt32 >(nStringLen) + 1;
- nSize += nSize % 2;
- pResMgr->Increment( nSize );
+ if (sStr.pData->length < STRING_MAXLEN)
+ {
+ mpData = reinterpret_cast< UniStringData * >(sStr.pData);
+ STRING_ACQUIRE((STRING_TYPE *)mpData);
}
else
{
STRING_NEW((STRING_TYPE **)&mpData);
+ }
+
+
+}
+
+rtl::OUString ResId::toString(const ResId& rResId)
+{
+ rResId.SetRT( RSC_STRING );
+ ResMgr* pResMgr = rResId.GetResMgr();
+
+ if ( !pResMgr || !pResMgr->GetResource( rResId ) )
+ {
+ rtl::OUString sRet;
#if OSL_DEBUG_LEVEL > 0
- *this = UniString::CreateFromAscii( "<resource id " );
- Append( UniString::CreateFromInt32( rResId.GetId() ) );
- AppendAscii( " not found>" );
+ sRet = rtl::OUStringBuffer().
+ appendAscii(RTL_CONSTASCII_STRINGPARAM("<resource id ")).
+ append(static_cast<sal_Int32>(rResId.GetId())).
+ appendAscii(RTL_CONSTASCII_STRINGPARAM(" not found>")).
+ makeStringAndClear();
#endif
+
if( pResMgr )
pResMgr->PopContext();
+
+ return sRet;
}
+ // String loading
+ RSHEADER_TYPE * pResHdr = (RSHEADER_TYPE*)pResMgr->GetClass();
+
+ sal_Int32 nStringLen = rtl_str_getLength( (char*)(pResHdr+1) );
+ rtl::OUString sRet((const char*)(pResHdr+1), nStringLen, RTL_TEXTENCODING_UTF8);
+
+ sal_uInt32 nSize = sizeof( RSHEADER_TYPE )
+ + sal::static_int_cast< sal_uInt32 >(nStringLen) + 1;
+ nSize += nSize % 2;
+ pResMgr->Increment( nSize );
ResHookProc pImplResHookProc = ResMgr::GetReadStringHook();
if ( pImplResHookProc )
- pImplResHookProc( *this );
-}
-
-rtl::OUString ResId::toString(const ResId& aId)
-{
- // TODO: Optimize this.
- return rtl::OUString(UniString(aId));
+ sRet = pImplResHookProc(sRet);
+ return sRet;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */