diff options
25 files changed, 79 insertions, 107 deletions
diff --git a/comphelper/inc/comphelper/string.hxx b/comphelper/inc/comphelper/string.hxx index 693703d5ca3c..cfa9ddd474f6 100644 --- a/comphelper/inc/comphelper/string.hxx +++ b/comphelper/inc/comphelper/string.hxx @@ -37,51 +37,6 @@ // go into the stable URE API: namespace comphelper { namespace string { -/** Allocate a new string containing space for a given number of characters. - - The reference count of the new string will be 1. The length of the string - will be nLen. This function throws std::bad_alloc on out-of-memory - conditions. - - The characters of the capacity are not cleared, and the length is set to - nLen, unlike the similar method of rtl_uString_new_WithLength which - zeros out the buffer, and sets the length to 0. So should be somewhat - more efficient for allocating a new string. - - call rtl_uString_release to release the string - alternatively pass ownership to an OUString with - rtl::OUString(newStr, SAL_NO_ACQUIRE); - - @param newStr - pointer to the new string. - - @param len - the number of characters. - */ -COMPHELPER_DLLPUBLIC rtl_uString * SAL_CALL rtl_uString_alloc(sal_Int32 nLen); - -/** Allocate a new string containing space for a given number of characters. - - The reference count of the new string will be 1. The length of the string - will be nLen. This function does not handle out-of-memory conditions. - - The characters of the capacity are not cleared, and the length is set to - nLen, unlike the similar method of rtl_String_new_WithLength which - zeros out the buffer, and sets the length to 0. So should be somewhat - more efficient for allocating a new string. - - call rtl_String_release to release the string - alternatively pass ownership to an OUString with - rtl::OUString(newStr, SAL_NO_ACQUIRE); - - @param newStr - pointer to the new string. - - @param len - the number of characters. - */ -COMPHELPER_DLLPUBLIC rtl_String * SAL_CALL rtl_string_alloc(sal_Int32 nLen); - /** Compare an OString to a single char @param rIn The input OString diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx index 1dae9e8c203f..0674f9a7b065 100644 --- a/comphelper/source/misc/string.cxx +++ b/comphelper/source/misc/string.cxx @@ -377,43 +377,6 @@ bool isdigitAsciiString(const rtl::OUString &rString) namespace { - template <typename T, typename U> T* string_alloc(sal_Int32 nLen) - { - //Clearly this is somewhat cosy with the sal implmentation - - //rtl_[u]String contains U buffer[1], so an input of nLen - //allocates a buffer of nLen + 1 and we'll ensure a null termination - - T* newStr = - (sal::static_int_cast< sal_uInt32 >(nLen) - <= ((SAL_MAX_UINT32 - sizeof (T)) - / sizeof (U))) - ? (T*) rtl_allocateMemory( - sizeof (T) + nLen * sizeof (U)) - : NULL; - - if (!newStr) - throw std::bad_alloc(); - - newStr->refCount = 1; - newStr->length = nLen; - newStr->buffer[nLen] = 0; - return newStr; - } -} - -rtl_uString * SAL_CALL rtl_uString_alloc(sal_Int32 nLen) -{ - return string_alloc<rtl_uString, sal_Unicode>(nLen); -} - -rtl_String * SAL_CALL rtl_string_alloc(sal_Int32 nLen) -{ - return string_alloc<rtl_String, sal_Char>(nLen); -} - -namespace -{ template <typename T, typename O> T tmpl_reverseString(const T &rIn) { if (rIn.isEmpty()) diff --git a/editeng/source/editeng/editdoc.cxx b/editeng/source/editeng/editdoc.cxx index 80556b98c562..9b96ed77fef5 100644 --- a/editeng/source/editeng/editdoc.cxx +++ b/editeng/source/editeng/editdoc.cxx @@ -2052,7 +2052,7 @@ XubString EditDoc::GetText( LineEnd eEnd ) const if ( nSepSize ) nLen += (nNodes - 1) * nSepSize; - rtl_uString* newStr = comphelper::string::rtl_uString_alloc(nLen); + rtl_uString* newStr = rtl_uString_alloc(nLen); sal_Unicode* pCur = newStr->buffer; size_t nLastNode = nNodes-1; for ( sal_uInt16 nNode = 0; nNode < nNodes; nNode++ ) diff --git a/editeng/source/editeng/editobj.cxx b/editeng/source/editeng/editobj.cxx index 669f003fa607..275aa77c5a47 100644 --- a/editeng/source/editeng/editobj.cxx +++ b/editeng/source/editeng/editobj.cxx @@ -1435,8 +1435,6 @@ void BinTextObject::CreateData( SvStream& rIStream ) rIStream >> bUnicodeStrings; if ( bUnicodeStrings ) { - using comphelper::string::rtl_uString_alloc; - for ( sal_uInt16 nPara = 0; nPara < nParagraphs; nPara++ ) { ContentInfo& rC = aContents[nPara]; diff --git a/editeng/source/items/flditem.cxx b/editeng/source/items/flditem.cxx index c9eebe655f75..1c0a2c10d735 100644 --- a/editeng/source/items/flditem.cxx +++ b/editeng/source/items/flditem.cxx @@ -557,7 +557,6 @@ static rtl::OUString read_unicode( SvPersistStream & rStm ) rStm >> nL; if ( nL ) { - using comphelper::string::rtl_uString_alloc; pStr = rtl_uString_alloc(nL); //endian specific?, yipes! rStm.Read(pStr->buffer, nL*sizeof(sal_Unicode)); diff --git a/i18npool/source/characterclassification/cclass_unicode.cxx b/i18npool/source/characterclassification/cclass_unicode.cxx index 5e27fa50d1d6..045de399227a 100644 --- a/i18npool/source/characterclassification/cclass_unicode.cxx +++ b/i18npool/source/characterclassification/cclass_unicode.cxx @@ -88,7 +88,7 @@ cclass_Unicode::toTitle( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount, nCount = len - nPos; trans->setMappingType(MappingTypeToTitle, rLocale); - rtl_uString* pStr = comphelper::string::rtl_uString_alloc(nCount); + rtl_uString* pStr = rtl_uString_alloc(nCount); sal_Unicode* out = pStr->buffer; BreakIteratorImpl brk(m_xContext); Boundary bdy = brk.getWordBoundary(Text, nPos, rLocale, diff --git a/i18npool/source/nativenumber/nativenumbersupplier.cxx b/i18npool/source/nativenumber/nativenumbersupplier.cxx index 8632b5df7a7c..bda3f87574b3 100644 --- a/i18npool/source/nativenumber/nativenumbersupplier.cxx +++ b/i18npool/source/nativenumber/nativenumbersupplier.cxx @@ -68,7 +68,7 @@ OUString SAL_CALL AsciiToNativeChar( const OUString& inStr, sal_Int32 startPos, Sequence< sal_Int32 >& offset, sal_Bool useOffset, sal_Int16 number ) throw(RuntimeException) { const sal_Unicode *src = inStr.getStr() + startPos; - rtl_uString *newStr = comphelper::string::rtl_uString_alloc(nCount); + rtl_uString *newStr = rtl_uString_alloc(nCount); if (useOffset) offset.realloc(nCount); diff --git a/i18npool/source/textconversion/textconversion_zh.cxx b/i18npool/source/textconversion/textconversion_zh.cxx index a6d842f3809e..54ae5d3e371b 100644 --- a/i18npool/source/textconversion/textconversion_zh.cxx +++ b/i18npool/source/textconversion/textconversion_zh.cxx @@ -110,7 +110,7 @@ TextConversion_zh::getCharConversion(const OUString& aText, sal_Int32 nStartPos, } #endif - rtl_uString * newStr = comphelper::string::rtl_uString_alloc(nLength); + rtl_uString * newStr = rtl_uString_alloc(nLength); for (sal_Int32 i = 0; i < nLength; i++) newStr->buffer[i] = getOneCharConversion(aText[nStartPos+i], Data, Index); diff --git a/i18npool/source/transliteration/ignoreIandEfollowedByYa_ja_JP.cxx b/i18npool/source/transliteration/ignoreIandEfollowedByYa_ja_JP.cxx index 1bd9a55bfe2a..07d56e2648e1 100644 --- a/i18npool/source/transliteration/ignoreIandEfollowedByYa_ja_JP.cxx +++ b/i18npool/source/transliteration/ignoreIandEfollowedByYa_ja_JP.cxx @@ -76,7 +76,7 @@ ignoreIandEfollowedByYa_ja_JP::folding( const OUString& inStr, sal_Int32 startPo { // Create a string buffer which can hold nCount + 1 characters. // The reference count is 1 now. - rtl_uString * newStr = comphelper::string::rtl_uString_alloc(nCount); + rtl_uString * newStr = rtl_uString_alloc(nCount); sal_Unicode * dst = newStr->buffer; const sal_Unicode * src = inStr.getStr() + startPos; diff --git a/i18npool/source/transliteration/ignoreIterationMark_ja_JP.cxx b/i18npool/source/transliteration/ignoreIterationMark_ja_JP.cxx index e1c29538c751..57c1b1c676f8 100644 --- a/i18npool/source/transliteration/ignoreIterationMark_ja_JP.cxx +++ b/i18npool/source/transliteration/ignoreIterationMark_ja_JP.cxx @@ -91,7 +91,7 @@ ignoreIterationMark_ja_JP::folding( const OUString& inStr, sal_Int32 startPos, s // Create a string buffer which can hold nCount + 1 characters. // The reference count is 1 now. - rtl_uString * newStr = comphelper::string::rtl_uString_alloc(nCount); + rtl_uString * newStr = rtl_uString_alloc(nCount); sal_Unicode * dst = newStr->buffer; const sal_Unicode * src = inStr.getStr() + startPos; diff --git a/i18npool/source/transliteration/ignoreKiKuFollowedBySa_ja_JP.cxx b/i18npool/source/transliteration/ignoreKiKuFollowedBySa_ja_JP.cxx index 913a3cf5f4ff..977f471e4e74 100644 --- a/i18npool/source/transliteration/ignoreKiKuFollowedBySa_ja_JP.cxx +++ b/i18npool/source/transliteration/ignoreKiKuFollowedBySa_ja_JP.cxx @@ -36,7 +36,7 @@ ignoreKiKuFollowedBySa_ja_JP::folding( const OUString& inStr, sal_Int32 startPos { // Create a string buffer which can hold nCount + 1 characters. // The reference count is 1 now. - rtl_uString * newStr = comphelper::string::rtl_uString_alloc(nCount); + rtl_uString * newStr = rtl_uString_alloc(nCount); sal_Unicode * dst = newStr->buffer; const sal_Unicode * src = inStr.getStr() + startPos; diff --git a/i18npool/source/transliteration/ignoreProlongedSoundMark_ja_JP.cxx b/i18npool/source/transliteration/ignoreProlongedSoundMark_ja_JP.cxx index 6b5636a5bbbe..66f45c5bbee6 100644 --- a/i18npool/source/transliteration/ignoreProlongedSoundMark_ja_JP.cxx +++ b/i18npool/source/transliteration/ignoreProlongedSoundMark_ja_JP.cxx @@ -298,7 +298,7 @@ ignoreProlongedSoundMark_ja_JP::folding( const OUString& inStr, sal_Int32 startP { // Create a string buffer which can hold nCount + 1 characters. // The reference count is 1 now. - rtl_uString * newStr = comphelper::string::rtl_uString_alloc(nCount); + rtl_uString * newStr = rtl_uString_alloc(nCount); sal_Unicode * dst = newStr->buffer; const sal_Unicode * src = inStr.getStr() + startPos; diff --git a/i18npool/source/transliteration/transliteration_Ignore.cxx b/i18npool/source/transliteration/transliteration_Ignore.cxx index 0d7e8833da06..0300ea48f8b0 100644 --- a/i18npool/source/transliteration/transliteration_Ignore.cxx +++ b/i18npool/source/transliteration/transliteration_Ignore.cxx @@ -126,7 +126,7 @@ transliteration_Ignore::folding( const OUString& inStr, sal_Int32 startPos, { // Create a string buffer which can hold nCount + 1 characters. // The reference count is 1 now. - rtl_uString * newStr = comphelper::string::rtl_uString_alloc(nCount); + rtl_uString * newStr = rtl_uString_alloc(nCount); sal_Unicode * dst = newStr->buffer; const sal_Unicode * src = inStr.getStr() + startPos; diff --git a/i18npool/source/transliteration/transliteration_Numeric.cxx b/i18npool/source/transliteration/transliteration_Numeric.cxx index eec4236092b8..329f2d565a4b 100644 --- a/i18npool/source/transliteration/transliteration_Numeric.cxx +++ b/i18npool/source/transliteration/transliteration_Numeric.cxx @@ -68,7 +68,7 @@ transliteration_Numeric::transliterateBullet( const OUString& inStr, sal_Int32 s if (endPos > inStr.getLength()) endPos = inStr.getLength(); - rtl_uString* pStr = comphelper::string::rtl_uString_alloc(nCount); + rtl_uString* pStr = rtl_uString_alloc(nCount); sal_Unicode* out = pStr->buffer; if (useOffset) diff --git a/i18npool/source/transliteration/transliteration_OneToOne.cxx b/i18npool/source/transliteration/transliteration_OneToOne.cxx index df9916ab410d..f62a7fbc4f29 100644 --- a/i18npool/source/transliteration/transliteration_OneToOne.cxx +++ b/i18npool/source/transliteration/transliteration_OneToOne.cxx @@ -63,7 +63,7 @@ transliteration_OneToOne::transliterate( const OUString& inStr, sal_Int32 startP { // Create a string buffer which can hold nCount + 1 characters. // The reference count is 1 now. - rtl_uString * newStr = comphelper::string::rtl_uString_alloc(nCount); + rtl_uString * newStr = rtl_uString_alloc(nCount); sal_Unicode * dst = newStr->buffer; const sal_Unicode * src = inStr.getStr() + startPos; diff --git a/i18npool/source/transliteration/transliteration_body.cxx b/i18npool/source/transliteration/transliteration_body.cxx index c1ed6b860389..db3ba0a9f37d 100644 --- a/i18npool/source/transliteration/transliteration_body.cxx +++ b/i18npool/source/transliteration/transliteration_body.cxx @@ -119,7 +119,7 @@ Transliteration_body::transliterate( const Mapping &map = casefolding::getValue( in, i, nCount, aLocale, nTmpMappingType ); nOffCount += map.nmap; } - rtl_uString* pStr = comphelper::string::rtl_uString_alloc(nOffCount); + rtl_uString* pStr = rtl_uString_alloc(nOffCount); sal_Unicode* out = pStr->buffer; if ( nOffCount != offset.getLength() ) @@ -189,7 +189,7 @@ OUString SAL_CALL Transliteration_body::transliterateChar2String( sal_Unicode inChar ) throw(RuntimeException) { const Mapping &map = casefolding::getValue(&inChar, 0, 1, aLocale, nMappingType); - rtl_uString* pStr = comphelper::string::rtl_uString_alloc(map.nmap); + rtl_uString* pStr = rtl_uString_alloc(map.nmap); sal_Unicode* out = pStr->buffer; sal_Int32 i; diff --git a/i18nutil/source/utility/widthfolding.cxx b/i18nutil/source/utility/widthfolding.cxx index 628888199fb1..0777c979101f 100644 --- a/i18nutil/source/utility/widthfolding.cxx +++ b/i18nutil/source/utility/widthfolding.cxx @@ -47,7 +47,7 @@ OUString widthfolding::decompose_ja_voiced_sound_marks (const OUString& inStr, s // Create a string buffer which can hold nCount * 2 + 1 characters. // Its size may become double of nCount. // The reference count is 1 now. - rtl_uString * newStr = comphelper::string::rtl_uString_alloc(nCount * 2); + rtl_uString * newStr = rtl_uString_alloc(nCount * 2); sal_Int32 *p = NULL; sal_Int32 position = 0; @@ -109,7 +109,7 @@ OUString widthfolding::compose_ja_voiced_sound_marks (const OUString& inStr, sal // Create a string buffer which can hold nCount + 1 characters. // Its size may become equal to nCount or smaller. // The reference count is 1 now. - rtl_uString * newStr = comphelper::string::rtl_uString_alloc(nCount); + rtl_uString * newStr = rtl_uString_alloc(nCount); // Prepare pointers of unicode character arrays. const sal_Unicode* src = inStr.getStr() + startPos; diff --git a/sal/inc/rtl/string.h b/sal/inc/rtl/string.h index 13c622d4e8b3..bfeecf781e62 100644 --- a/sal/inc/rtl/string.h +++ b/sal/inc/rtl/string.h @@ -818,6 +818,30 @@ SAL_DLLPUBLIC void SAL_CALL rtl_string_new( rtl_String ** newStr ) SAL_THROW_EXT /** Allocate a new string containing space for a given number of characters. + The reference count of the new string will be 1. The length of the string + will be nLen. This function does not handle out-of-memory conditions. + + The characters of the capacity are not cleared, and the length is set to + nLen, unlike the similar method of rtl_String_new_WithLength which + zeros out the buffer, and sets the length to 0. So should be somewhat + more efficient for allocating a new string. + + call rtl_String_release to release the string + alternatively pass ownership to an OUString with + rtl::OUString(newStr, SAL_NO_ACQUIRE); + + @param newStr + pointer to the new string. + + @param len + the number of characters. + + @since LibreOffice 4.1 + */ +SAL_DLLPUBLIC rtl_String * SAL_CALL rtl_string_alloc(sal_Int32 nLen) SAL_THROW_EXTERN_C(); + +/** Allocate a new string containing space for a given number of characters. + If len is greater than zero, the reference count of the new string will be 1. The values of all characters are set to 0 and the length of the string is 0. This function does not handle out-of-memory conditions. diff --git a/sal/inc/rtl/ustring.h b/sal/inc/rtl/ustring.h index 0548033f732c..fe2f2f47607d 100644 --- a/sal/inc/rtl/ustring.h +++ b/sal/inc/rtl/ustring.h @@ -1151,6 +1151,31 @@ SAL_DLLPUBLIC void SAL_CALL rtl_uString_new( /** Allocate a new string containing space for a given number of characters. + The reference count of the new string will be 1. The length of the string + will be nLen. This function throws std::bad_alloc on out-of-memory + conditions. + + The characters of the capacity are not cleared, and the length is set to + nLen, unlike the similar method of rtl_uString_new_WithLength which + zeros out the buffer, and sets the length to 0. So should be somewhat + more efficient for allocating a new string. + + call rtl_uString_release to release the string + alternatively pass ownership to an OUString with + rtl::OUString(newStr, SAL_NO_ACQUIRE); + + @param newStr + pointer to the new string. + + @param len + the number of characters. + + @since LibreOffice 4.1 + */ +SAL_DLLPUBLIC rtl_uString * SAL_CALL rtl_uString_alloc(sal_Int32 nLen) SAL_THROW_EXTERN_C(); + +/** Allocate a new string containing space for a given number of characters. + If len is greater than zero, the reference count of the new string will be 1. The values of all characters are set to 0 and the length of the string is 0. This function does not handle out-of-memory conditions. diff --git a/sal/rtl/source/strtmpl.cxx b/sal/rtl/source/strtmpl.cxx index ffe12adf0d71..f715a581e2ce 100644 --- a/sal/rtl/source/strtmpl.cxx +++ b/sal/rtl/source/strtmpl.cxx @@ -1066,6 +1066,17 @@ void SAL_CALL IMPL_RTL_STRINGNAME( new )( IMPL_RTL_STRINGDATA** ppThis ) /* ----------------------------------------------------------------------- */ +IMPL_RTL_STRINGDATA* SAL_CALL IMPL_RTL_STRINGNAME( alloc )( sal_Int32 nLen ) + SAL_THROW_EXTERN_C() +{ + if ( nLen <= 0 ) + return (IMPL_RTL_STRINGDATA*) (&IMPL_RTL_EMPTYSTRING); + else + return IMPL_RTL_STRINGNAME( ImplAlloc )( nLen ); +} + +/* ----------------------------------------------------------------------- */ + void SAL_CALL IMPL_RTL_STRINGNAME( new_WithLength )( IMPL_RTL_STRINGDATA** ppThis, sal_Int32 nLen ) SAL_THROW_EXTERN_C() { diff --git a/sal/util/sal.map b/sal/util/sal.map index 1eef9c6c3cb7..9d3f88b44bd1 100644 --- a/sal/util/sal.map +++ b/sal/util/sal.map @@ -656,6 +656,8 @@ LIBO_UDK_4.1 { # symbols available in >= LibO 4.1 global: rtl_string_ensureCapacity; rtl_uString_ensureCapacity; + rtl_string_alloc; + rtl_uString_alloc; } LIBO_UDK_4.0; PRIVATE_1.0 { diff --git a/sw/source/core/edit/edglss.cxx b/sw/source/core/edit/edglss.cxx index 9125987b92b6..210ce3f3ee53 100644 --- a/sw/source/core/edit/edglss.cxx +++ b/sw/source/core/edit/edglss.cxx @@ -339,7 +339,6 @@ sal_Bool SwEditShell::GetSelectedText( String &rBuf, int nHndlParaBrk ) rBuf = rtl::OUString(p); else { - using comphelper::string::rtl_uString_alloc; rtl_uString *pStr = rtl_uString_alloc(lLen / sizeof( sal_Unicode )); aStream.Seek( 0 ); aStream.ResetError(); diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx index a91286aecda7..a4f8ea2db818 100644 --- a/sw/source/core/unocore/unoobj.cxx +++ b/sw/source/core/unocore/unoobj.cxx @@ -206,7 +206,7 @@ void SwUnoCursorHelper::GetTextFromPam(SwPaM & rPam, OUString & rBuffer) aStream.ResetError(); long lUniLen = (lLen / sizeof( sal_Unicode )); - rtl_uString *pStr = comphelper::string::rtl_uString_alloc(lUniLen); + rtl_uString *pStr = rtl_uString_alloc(lUniLen); aStream.Read(pStr->buffer, lUniLen * sizeof(sal_Unicode)); rBuffer = rtl::OUString(pStr, SAL_NO_ACQUIRE); } diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index 22c49fd20020..e71b6c08e9f3 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -2567,7 +2567,7 @@ bool SwWW8ImplReader::ReadPlainChars(WW8_CP& rPos, long nEnd, long nCpOfs) RTL_TEXTENCODING_MS_1252; // allocate unicode string data - rtl_uString *pStr = comphelper::string::rtl_uString_alloc(nStrLen); + rtl_uString *pStr = rtl_uString_alloc(nStrLen); sal_Unicode* pBuffer = pStr->buffer; sal_Unicode* pWork = pBuffer; diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx index 6ca4d07ff364..68c9dc9f7ac5 100644 --- a/tools/source/stream/stream.cxx +++ b/tools/source/stream/stream.cxx @@ -1970,8 +1970,6 @@ void SvDataCopyStream::Assign( const SvDataCopyStream& ) //Create a OString of nLen bytes from rStream rtl::OString read_uInt8s_ToOString(SvStream& rStrm, sal_Size nLen) { - using comphelper::string::rtl_string_alloc; - rtl_String *pStr = NULL; if (nLen) { @@ -1997,8 +1995,6 @@ rtl::OString read_uInt8s_ToOString(SvStream& rStrm, sal_Size nLen) //Create a OUString of nLen sal_Unicodes from rStream rtl::OUString read_uInt16s_ToOUString(SvStream& rStrm, sal_Size nLen) { - using comphelper::string::rtl_uString_alloc; - rtl_uString *pStr = NULL; if (nLen) { |