Files
libreoffice/tools/source/string/strucvt.cxx

188 lines
5.7 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2000-09-18 16:07:07 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-09-18 16:07:07 +00:00
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
2000-09-18 16:07:07 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 16:07:07 +00:00
*
* This file is part of OpenOffice.org.
2000-09-18 16:07:07 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2000-09-18 16:07:07 +00:00
*
* OpenOffice.org 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 version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2000-09-18 16:07:07 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2000-09-18 16:07:07 +00:00
*
************************************************************************/
// =======================================================================
2012-02-25 20:12:34 +00:00
UniString::UniString( const rtl::OString& rByteStr, rtl_TextEncoding eTextEncoding, sal_uInt32 nCvtFlags )
2000-09-18 16:07:07 +00:00
{
DBG_CTOR( UniString, DbgCheckUniString );
2001-03-16 14:27:41 +00:00
mpData = NULL;
rtl_string2UString( (rtl_uString **)(&mpData),
2012-02-25 20:12:34 +00:00
rByteStr.getStr(), rByteStr.getLength(),
2001-03-16 14:27:41 +00:00
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 )
: mpData(NULL)
2000-09-18 16:07:07 +00:00
{
DBG_CTOR( UniString, DbgCheckUniString );
OSL_ENSURE(rStr.pData->length < STRING_MAXLEN,
"Overflowing rtl::OUString -> UniString cut to zero length");
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 );
OSL_ENSURE(rStr.pData->length < STRING_MAXLEN,
"Overflowing rtl::OUString -> UniString cut to zero length");
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;
}
// =======================================================================
2012-03-19 20:31:38 +00:00
#include <rtl/ustrbuf.hxx>
#include <tools/rc.hxx>
#include <tools/rcid.h>
UniString::UniString( const ResId& rResId )
2012-03-19 20:31:38 +00:00
: mpData(NULL)
{
2012-03-19 20:31:38 +00:00
rtl::OUString sStr(ResId::toString(rResId));
2012-03-19 20:31:38 +00:00
DBG_CTOR( UniString, DbgCheckUniString );
OSL_ENSURE(sStr.pData->length < STRING_MAXLEN,
"Overflowing rtl::OUString -> UniString cut to zero length");
2012-03-19 20:31:38 +00:00
if (sStr.pData->length < STRING_MAXLEN)
{
mpData = reinterpret_cast< UniStringData * >(sStr.pData);
STRING_ACQUIRE((STRING_TYPE *)mpData);
}
else
{
STRING_NEW((STRING_TYPE **)&mpData);
2012-03-19 20:31:38 +00:00
}
}
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
2012-03-19 20:31:38 +00:00
sRet = rtl::OUStringBuffer().
appendAscii(RTL_CONSTASCII_STRINGPARAM("<resource id ")).
append(static_cast<sal_Int32>(rResId.GetId())).
appendAscii(RTL_CONSTASCII_STRINGPARAM(" not found>")).
makeStringAndClear();
#endif
2012-03-19 20:31:38 +00:00
if( pResMgr )
pResMgr->PopContext();
2012-03-19 20:31:38 +00:00
return sRet;
}
2012-03-19 20:31:38 +00:00
// 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 )
2012-03-19 20:31:38 +00:00
sRet = pImplResHookProc(sRet);
return sRet;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */