diff options
17 files changed, 93 insertions, 34 deletions
diff --git a/comphelper/inc/comphelper/string.hxx b/comphelper/inc/comphelper/string.hxx index 0fadc73d16e7..c7f29f6d9a9e 100644 --- a/comphelper/inc/comphelper/string.hxx +++ b/comphelper/inc/comphelper/string.hxx @@ -46,6 +46,72 @@ namespace rtl { class OUString; } // go into the stable URE API: namespace comphelper { namespace string { +namespace detail +{ + 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 = (T*)rtl_allocateMemory(sizeof(T) + sizeof(U) * nLen); + newStr->refCount = 1; + newStr->length = nLen; + newStr->buffer[nLen]=0; + return newStr; + } +} + +/** 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_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 inline rtl_uString * SAL_CALL rtl_uString_alloc(sal_Int32 nLen) +{ + return detail::string_alloc<rtl_uString, sal_Unicode>(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 inline rtl_String * SAL_CALL rtl_string_alloc(sal_Int32 nLen) +{ + return detail::string_alloc<rtl_String, sal_Char>(nLen); +} + /** Replace the first occurrence of a substring with another string. diff --git a/i18npool/inc/transliteration_commonclass.hxx b/i18npool/inc/transliteration_commonclass.hxx index af5d189e6038..826e7366b297 100644 --- a/i18npool/inc/transliteration_commonclass.hxx +++ b/i18npool/inc/transliteration_commonclass.hxx @@ -33,7 +33,6 @@ #include <cppuhelper/implbase1.hxx> #include <rtl/ustrbuf.h> #include <rtl/ustring.hxx> -#include <i18nutil/x_rtl_ustring.h> namespace com { namespace sun { namespace star { namespace i18n { diff --git a/i18npool/source/characterclassification/cclass_unicode.cxx b/i18npool/source/characterclassification/cclass_unicode.cxx index 9acdd9b66d87..f0fde593c0ae 100644 --- a/i18npool/source/characterclassification/cclass_unicode.cxx +++ b/i18npool/source/characterclassification/cclass_unicode.cxx @@ -34,7 +34,7 @@ #include <com/sun/star/i18n/UnicodeType.hpp> #include <com/sun/star/i18n/KCharacterType.hpp> #include <unicode/uchar.h> -#include <i18nutil/x_rtl_ustring.h> +#include <comphelper/string.hxx> #include <breakiteratorImpl.hxx> using namespace ::com::sun::star::uno; @@ -99,7 +99,7 @@ cclass_Unicode::toTitle( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount, nCount = len - nPos; trans->setMappingType(MappingTypeToTitle, rLocale); - rtl_uString* pStr = x_rtl_uString_new_WithLength(nCount); + rtl_uString* pStr = comphelper::string::rtl_uString_alloc(nCount); sal_Unicode* out = pStr->buffer; BreakIteratorImpl brk(xMSF); Boundary bdy = brk.getWordBoundary(Text, nPos, rLocale, diff --git a/i18npool/source/nativenumber/nativenumbersupplier.cxx b/i18npool/source/nativenumber/nativenumbersupplier.cxx index 6d0a1d4efec6..8dbefdc7889f 100644 --- a/i18npool/source/nativenumber/nativenumbersupplier.cxx +++ b/i18npool/source/nativenumber/nativenumbersupplier.cxx @@ -34,7 +34,7 @@ #include <nativenumbersupplier.hxx> #include <localedata.hxx> #include <data/numberchar.h> -#include <i18nutil/x_rtl_ustring.h> +#include <comphelper/string.hxx> using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; @@ -79,7 +79,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 = x_rtl_uString_new_WithLength(nCount); + rtl_uString *newStr = comphelper::string::rtl_uString_alloc(nCount); if (useOffset) offset.realloc(nCount); diff --git a/i18npool/source/textconversion/textconversion_ko.cxx b/i18npool/source/textconversion/textconversion_ko.cxx index 9cdc070ff6bf..9a743e829506 100644 --- a/i18npool/source/textconversion/textconversion_ko.cxx +++ b/i18npool/source/textconversion/textconversion_ko.cxx @@ -35,7 +35,6 @@ #include <com/sun/star/linguistic2/ConversionDirection.hpp> #include <com/sun/star/linguistic2/ConversionDictionaryType.hpp> #include <rtl/ustrbuf.hxx> -#include <i18nutil/x_rtl_ustring.h> #include <unicode/uchar.h> using namespace com::sun::star::lang; diff --git a/i18npool/source/textconversion/textconversion_zh.cxx b/i18npool/source/textconversion/textconversion_zh.cxx index 507f10221e33..bbe6b5d92b5f 100644 --- a/i18npool/source/textconversion/textconversion_zh.cxx +++ b/i18npool/source/textconversion/textconversion_zh.cxx @@ -35,7 +35,7 @@ #include <com/sun/star/i18n/TextConversionOption.hpp> #include <com/sun/star/linguistic2/ConversionDirection.hpp> #include <com/sun/star/linguistic2/ConversionDictionaryType.hpp> -#include <i18nutil/x_rtl_ustring.h> +#include <comphelper/string.hxx> using namespace com::sun::star::lang; using namespace com::sun::star::i18n; @@ -86,7 +86,7 @@ TextConversion_zh::getCharConversion(const OUString& aText, sal_Int32 nStartPos, Index = ((const sal_uInt16* (*)())getFunctionBySymbol("getSTC_CharIndex_S2T"))(); } - rtl_uString * newStr = x_rtl_uString_new_WithLength(nLength); + rtl_uString * newStr = comphelper::string::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 15395d4a0b7b..bcc25f84de3c 100644 --- a/i18npool/source/transliteration/ignoreIandEfollowedByYa_ja_JP.cxx +++ b/i18npool/source/transliteration/ignoreIandEfollowedByYa_ja_JP.cxx @@ -29,9 +29,8 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_i18npool.hxx" -// prevent internal compiler error with MSVC6SP3 #include <utility> - +#include <comphelper/string.hxx> #include <i18nutil/oneToOneMapping.hxx> #define TRANSLITERATION_IandEfollowedByYa_ja_JP #include <transliteration_Ignore.hxx> @@ -88,7 +87,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 = x_rtl_uString_new_WithLength(nCount); + rtl_uString * newStr = comphelper::string::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 cc79da1dc528..8d28c82e553f 100644 --- a/i18npool/source/transliteration/ignoreIterationMark_ja_JP.cxx +++ b/i18npool/source/transliteration/ignoreIterationMark_ja_JP.cxx @@ -29,9 +29,8 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_i18npool.hxx" -// prevent internal compiler error with MSVC6SP3 #include <utility> - +#include <comphelper/string.hxx> #include <i18nutil/oneToOneMapping.hxx> #define TRANSLITERATION_IterationMark_ja_JP #include <transliteration_Ignore.hxx> @@ -103,7 +102,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 = x_rtl_uString_new_WithLength(nCount); + rtl_uString * newStr = comphelper::string::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 57abcff573aa..f27e02e49a37 100644 --- a/i18npool/source/transliteration/ignoreKiKuFollowedBySa_ja_JP.cxx +++ b/i18npool/source/transliteration/ignoreKiKuFollowedBySa_ja_JP.cxx @@ -29,9 +29,8 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_i18npool.hxx" -// prevent internal compiler error with MSVC6SP3 #include <utility> - +#include <comphelper/string.hxx> #define TRANSLITERATION_KiKuFollowedBySa_ja_JP #include <transliteration_Ignore.hxx> @@ -48,7 +47,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 = x_rtl_uString_new_WithLength(nCount); + rtl_uString * newStr = comphelper::string::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 fd309ec6527b..85dcdb418bc9 100644 --- a/i18npool/source/transliteration/ignoreProlongedSoundMark_ja_JP.cxx +++ b/i18npool/source/transliteration/ignoreProlongedSoundMark_ja_JP.cxx @@ -29,9 +29,8 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_i18npool.hxx" -// prevent internal compiler error with MSVC6SP3 #include <utility> - +#include <comphelper/string.hxx> #define TRANSLITERATION_ProlongedSoundMark_ja_JP #include <transliteration_Ignore.hxx> @@ -310,7 +309,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 = x_rtl_uString_new_WithLength(nCount); + rtl_uString * newStr = comphelper::string::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 3d812722df65..0d60b2894735 100644 --- a/i18npool/source/transliteration/transliteration_Ignore.cxx +++ b/i18npool/source/transliteration/transliteration_Ignore.cxx @@ -29,9 +29,8 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_i18npool.hxx" -// prevent internal compiler error with MSVC6SP3 #include <utility> - +#include <comphelper/string.hxx> #include <transliteration_Ignore.hxx> using namespace com::sun::star::uno; @@ -138,7 +137,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 = x_rtl_uString_new_WithLength(nCount); + rtl_uString * newStr = comphelper::string::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 f2250fb0b4e4..9ef5cd51370f 100644 --- a/i18npool/source/transliteration/transliteration_Numeric.cxx +++ b/i18npool/source/transliteration/transliteration_Numeric.cxx @@ -32,6 +32,7 @@ #include <transliteration_Numeric.hxx> #include <nativenumbersupplier.hxx> #include <defaultnumberingprovider.hxx> +#include <comphelper/string.hxx> using namespace com::sun::star::uno; @@ -78,7 +79,7 @@ transliteration_Numeric::transliterateBullet( const OUString& inStr, sal_Int32 s if (endPos > inStr.getLength()) endPos = inStr.getLength(); - rtl_uString* pStr = x_rtl_uString_new_WithLength(nCount); + rtl_uString* pStr = comphelper::string::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 26f0732d514c..95c73189dd29 100644 --- a/i18npool/source/transliteration/transliteration_OneToOne.cxx +++ b/i18npool/source/transliteration/transliteration_OneToOne.cxx @@ -29,9 +29,8 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_i18npool.hxx" -// prevent internal compiler error with MSVC6SP3 #include <utility> - +#include <comphelper/string.hxx> #include <transliteration_OneToOne.hxx> using namespace com::sun::star::uno; @@ -75,7 +74,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 = x_rtl_uString_new_WithLength(nCount); + rtl_uString * newStr = comphelper::string::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 294f0a1f89a9..dcc659a07e12 100644 --- a/i18npool/source/transliteration/transliteration_body.cxx +++ b/i18npool/source/transliteration/transliteration_body.cxx @@ -34,6 +34,7 @@ #include <i18nutil/unicode.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/string.hxx> #include <osl/diagnose.h> #include <string.h> @@ -129,7 +130,7 @@ Transliteration_body::transliterate( const Mapping &map = casefolding::getValue( in, i, nCount, aLocale, nTmpMappingType ); nOffCount += map.nmap; } - rtl_uString* pStr = x_rtl_uString_new_WithLength(nOffCount); + rtl_uString* pStr = comphelper::string::rtl_uString_alloc(nOffCount); sal_Unicode* out = pStr->buffer; if ( nOffCount != offset.getLength() ) @@ -199,7 +200,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 = x_rtl_uString_new_WithLength(map.nmap); + rtl_uString* pStr = comphelper::string::rtl_uString_alloc(map.nmap); sal_Unicode* out = pStr->buffer; sal_Int32 i; diff --git a/i18nutil/Package_inc.mk b/i18nutil/Package_inc.mk index 05425d7892b7..92a9e71de50c 100644 --- a/i18nutil/Package_inc.mk +++ b/i18nutil/Package_inc.mk @@ -32,6 +32,5 @@ $(eval $(call gb_Package_add_file,i18nutil_inc,inc/i18nutil/casefolding.hxx,i18n $(eval $(call gb_Package_add_file,i18nutil_inc,inc/i18nutil/oneToOneMapping.hxx,i18nutil/oneToOneMapping.hxx)) $(eval $(call gb_Package_add_file,i18nutil_inc,inc/i18nutil/unicode.hxx,i18nutil/unicode.hxx)) $(eval $(call gb_Package_add_file,i18nutil_inc,inc/i18nutil/widthfolding.hxx,i18nutil/widthfolding.hxx)) -$(eval $(call gb_Package_add_file,i18nutil_inc,inc/i18nutil/x_rtl_ustring.h,i18nutil/x_rtl_ustring.h)) # vim: set noet sw=4: diff --git a/i18nutil/prj/build.lst b/i18nutil/prj/build.lst index 67296ade20d6..29a5aed88162 100644 --- a/i18nutil/prj/build.lst +++ b/i18nutil/prj/build.lst @@ -1,2 +1,2 @@ -inu i18nutil : sal cppu offapi NULL +inu i18nutil : sal cppu comphelper offapi NULL inu i18nutil\prj nmake - all inu_prj NULL diff --git a/i18nutil/source/utility/widthfolding.cxx b/i18nutil/source/utility/widthfolding.cxx index edfe573e70be..ebcd4c2043b7 100644 --- a/i18nutil/source/utility/widthfolding.cxx +++ b/i18nutil/source/utility/widthfolding.cxx @@ -29,7 +29,7 @@ // prevent internal compiler error with MSVC6SP3 #include <utility> #include <i18nutil/widthfolding.hxx> -#include <i18nutil/x_rtl_ustring.h> +#include <comphelper/string.hxx> #include "widthfolding_data.h" using namespace com::sun::star::uno; @@ -56,7 +56,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 = x_rtl_uString_new_WithLength(nCount * 2); + rtl_uString * newStr = comphelper::string::rtl_uString_alloc(nCount * 2); sal_Int32 *p = NULL; sal_Int32 position = 0; @@ -118,7 +118,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 = x_rtl_uString_new_WithLength(nCount); + rtl_uString * newStr = comphelper::string::rtl_uString_alloc(nCount); // Prepare pointers of unicode character arrays. const sal_Unicode* src = inStr.getStr() + startPos; |