diff options
author | Luboš Luňák <l.lunak@suse.cz> | 2012-12-05 00:37:01 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2012-12-06 13:35:18 +0100 |
commit | 81e16cea9a11185c209894973db8d1990fa9cce6 (patch) | |
tree | 6b784ddae1e873ba282ca1a961a8dc4a32f83e16 /sal | |
parent | acquire on the shared empty string does nothing (diff) | |
download | core-81e16cea9a11185c209894973db8d1990fa9cce6.tar.gz core-81e16cea9a11185c209894973db8d1990fa9cce6.zip |
mvoe rtl_(u)string_alloc to sal
No point in hidding something useful like this in some helper lib.
Change-Id: I7332d7f6bd428378cd19e7e95ad130771a541140
Diffstat (limited to 'sal')
-rw-r--r-- | sal/inc/rtl/string.h | 24 | ||||
-rw-r--r-- | sal/inc/rtl/ustring.h | 25 | ||||
-rw-r--r-- | sal/rtl/source/strtmpl.cxx | 11 | ||||
-rw-r--r-- | sal/util/sal.map | 2 |
4 files changed, 62 insertions, 0 deletions
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 { |