2000-09-18 16:07:07 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-09 13:37:48 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2005-09-09 13:37:48 +00:00
|
|
|
* $RCSfile: strucvt.cxx,v $
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2006-05-04 13:52:44 +00:00
|
|
|
* $Revision: 1.8 $
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2006-05-04 13:52:44 +00:00
|
|
|
* last change: $Author: rt $ $Date: 2006-05-04 14:52:44 $
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2005-09-09 13:37:48 +00:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
|
|
|
*
|
2005-09-09 13:37:48 +00:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2005-09-09 13:37:48 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2005-09-09 13:37:48 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2005-09-09 13:37:48 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
// =======================================================================
|
|
|
|
|
|
|
|
void UniString::InitStringRes( const char* pUTF8Str, xub_StrLen nLen )
|
|
|
|
{
|
|
|
|
DBG_CTOR( UniString, DbgCheckUniString );
|
|
|
|
|
2001-03-16 14:27:41 +00:00
|
|
|
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 );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// =======================================================================
|
|
|
|
|
|
|
|
UniString::UniString( const ByteString& rByteStr, rtl_TextEncoding eTextEncoding, sal_uInt32 nCvtFlags )
|
|
|
|
{
|
|
|
|
DBG_CTOR( UniString, DbgCheckUniString );
|
|
|
|
DBG_CHKOBJ( &rByteStr, ByteString, DbgCheckByteString );
|
|
|
|
|
2001-03-16 14:27:41 +00:00
|
|
|
mpData = NULL;
|
|
|
|
rtl_string2UString( (rtl_uString **)(&mpData),
|
|
|
|
rByteStr.mpData->maStr, rByteStr.mpData->mnLen,
|
|
|
|
eTextEncoding, nCvtFlags );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
UniString::UniString( const ByteString& rByteStr, xub_StrLen nPos, xub_StrLen nLen,
|
|
|
|
rtl_TextEncoding eTextEncoding, sal_uInt32 nCvtFlags )
|
|
|
|
{
|
|
|
|
DBG_CTOR( UniString, DbgCheckUniString );
|
|
|
|
DBG_CHKOBJ( &rByteStr, ByteString, DbgCheckByteString );
|
|
|
|
|
|
|
|
// Stringlaenge ermitteln
|
|
|
|
if ( nPos > rByteStr.mpData->mnLen )
|
|
|
|
nLen = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Laenge korrigieren, wenn noetig
|
|
|
|
xub_StrLen nMaxLen = rByteStr.mpData->mnLen-nPos;
|
|
|
|
if ( nLen > nMaxLen )
|
|
|
|
nLen = nMaxLen;
|
|
|
|
}
|
|
|
|
|
2001-03-16 14:27:41 +00:00
|
|
|
mpData = NULL;
|
|
|
|
rtl_string2UString( (rtl_uString **)(&mpData),
|
|
|
|
rByteStr.mpData->maStr+nPos, nLen,
|
|
|
|
eTextEncoding, nCvtFlags );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
UniString::UniString( const char* pByteStr,
|
|
|
|
rtl_TextEncoding eTextEncoding, sal_uInt32 nCvtFlags )
|
|
|
|
{
|
|
|
|
DBG_CTOR( UniString, DbgCheckUniString );
|
|
|
|
DBG_ASSERT( pByteStr, "UniString::UniString() - pByteStr is NULL" );
|
|
|
|
|
2001-03-16 14:27:41 +00:00
|
|
|
mpData = NULL;
|
|
|
|
rtl_string2UString( (rtl_uString **)(&mpData),
|
|
|
|
pByteStr, ImplStringLen( pByteStr ),
|
|
|
|
eTextEncoding, nCvtFlags );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
UniString::UniString( const char* pByteStr, xub_StrLen nLen,
|
|
|
|
rtl_TextEncoding eTextEncoding, sal_uInt32 nCvtFlags )
|
|
|
|
{
|
|
|
|
DBG_CTOR( UniString, DbgCheckUniString );
|
|
|
|
DBG_ASSERT( pByteStr, "UniString::UniString() - pByteStr is NULL" );
|
|
|
|
|
|
|
|
if ( nLen == STRING_LEN )
|
|
|
|
nLen = ImplStringLen( pByteStr );
|
|
|
|
|
2001-03-16 14:27:41 +00:00
|
|
|
mpData = NULL;
|
|
|
|
rtl_string2UString( (rtl_uString **)(&mpData),
|
|
|
|
pByteStr, nLen,
|
|
|
|
eTextEncoding, nCvtFlags );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// =======================================================================
|
|
|
|
|
2001-03-20 09:31:27 +00:00
|
|
|
UniString::UniString( const rtl::OUString& rStr )
|
2006-05-04 13:52:44 +00:00
|
|
|
: mpData(NULL)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
DBG_CTOR( UniString, DbgCheckUniString );
|
|
|
|
|
2003-03-27 16:05:12 +00:00
|
|
|
OSL_ENSURE(rStr.pData->length < STRING_MAXLEN,
|
|
|
|
"Overflowing rtl::OUString -> UniString cut to zero length");
|
2006-05-04 13:52:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (rStr.pData->length < STRING_MAXLEN)
|
|
|
|
{
|
|
|
|
mpData = reinterpret_cast< UniStringData * >(const_cast< rtl::OUString & >(rStr).pData);
|
|
|
|
STRING_ACQUIRE((STRING_TYPE *)mpData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
STRING_NEW((STRING_TYPE **)&mpData);
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2001-03-20 09:31:27 +00:00
|
|
|
UniString& UniString::Assign( const rtl::OUString& rStr )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
DBG_CHKTHIS( UniString, DbgCheckUniString );
|
|
|
|
|
2003-03-27 16:05:12 +00:00
|
|
|
OSL_ENSURE(rStr.pData->length < STRING_MAXLEN,
|
|
|
|
"Overflowing rtl::OUString -> UniString cut to zero length");
|
2006-05-04 13:52:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (rStr.pData->length < STRING_MAXLEN)
|
|
|
|
{
|
|
|
|
STRING_RELEASE((STRING_TYPE *)mpData);
|
|
|
|
mpData = reinterpret_cast< UniStringData * >(const_cast< rtl::OUString & >(rStr).pData);
|
|
|
|
STRING_ACQUIRE((STRING_TYPE *)mpData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
STRING_NEW((STRING_TYPE **)&mpData);
|
|
|
|
}
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2005-01-03 16:09:12 +00:00
|
|
|
|
|
|
|
// =======================================================================
|
|
|
|
|
|
|
|
#ifndef _TOOLS_RC_HXX
|
|
|
|
#include <rc.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef _TOOLS_RCID_H
|
|
|
|
#include <rcid.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
UniString::UniString( const ResId& rResId )
|
|
|
|
{
|
|
|
|
rResId.SetRT( RSC_STRING );
|
|
|
|
ResMgr* pResMgr = rResId.GetResMgr();
|
|
|
|
if ( !pResMgr )
|
|
|
|
pResMgr = Resource::GetResManager();
|
|
|
|
|
|
|
|
mpData = NULL;
|
|
|
|
if ( pResMgr->GetResource( rResId ) )
|
|
|
|
{
|
|
|
|
// String laden
|
|
|
|
RSHEADER_TYPE * pResHdr = (RSHEADER_TYPE*)pResMgr->GetClass();
|
|
|
|
//sal_uInt32 nLen = pResHdr->GetLocalOff() - sizeof( RSHEADER_TYPE );
|
|
|
|
|
|
|
|
sal_uInt32 nStringLen = strlen( (char*)(pResHdr+1) );
|
|
|
|
InitStringRes( (const char*)(pResHdr+1), nStringLen );
|
|
|
|
|
|
|
|
sal_uInt32 nSize = sizeof( RSHEADER_TYPE ) + nStringLen + 1;
|
|
|
|
nSize += nSize % 2;
|
|
|
|
pResMgr->Increment( nSize );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-04 13:52:44 +00:00
|
|
|
STRING_NEW((STRING_TYPE **)&mpData);
|
|
|
|
|
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2005-01-03 16:09:12 +00:00
|
|
|
*this = UniString::CreateFromAscii( "<resource id " );
|
|
|
|
Append( UniString::CreateFromInt32( rResId.GetId() ) );
|
|
|
|
AppendAscii( " not found>" );
|
2006-05-04 13:52:44 +00:00
|
|
|
#endif
|
2005-01-03 16:09:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ResHookProc pImplResHookProc = ResMgr::GetReadStringHook();
|
|
|
|
if ( pImplResHookProc )
|
|
|
|
pImplResHookProc( *this );
|
|
|
|
}
|
|
|
|
|