summaryrefslogtreecommitdiff
path: root/tools/source
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-03-19 20:31:38 +0000
committerCaolán McNamara <caolanm@redhat.com>2012-03-20 12:57:33 +0000
commitbdfba4dbf666868c6d10b972259884877dd01848 (patch)
tree2860856ab873b182752f2dc60c30d802a9a84aee /tools/source
parent260ed4ed0317f4f16a675dde48750bc40923bc96 (diff)
make ResId->OUString the primary route
Diffstat (limited to 'tools/source')
-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: */