diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-02-28 21:07:40 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-02-29 10:09:44 +0000 |
commit | 53294e814bb8ac5f28a57f1f325311fa05112d12 (patch) | |
tree | 9a21433b71d063865659575a14eb5512391d05f8 /comphelper | |
parent | 60f97f3ceb670a310e89cd1be948e04b469539f2 (diff) |
move template out of header
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/inc/comphelper/string.hxx | 26 | ||||
-rw-r--r-- | comphelper/source/misc/string.cxx | 37 |
2 files changed, 39 insertions, 24 deletions
diff --git a/comphelper/inc/comphelper/string.hxx b/comphelper/inc/comphelper/string.hxx index f52021d9b68f..a64bad2cf4e8 100644 --- a/comphelper/inc/comphelper/string.hxx +++ b/comphelper/inc/comphelper/string.hxx @@ -46,22 +46,6 @@ // 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 @@ -82,10 +66,7 @@ namespace detail @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); -} +COMPHELPER_DLLPUBLIC rtl_uString * SAL_CALL rtl_uString_alloc(sal_Int32 nLen); /** Allocate a new string containing space for a given number of characters. @@ -107,10 +88,7 @@ COMPHELPER_DLLPUBLIC inline rtl_uString * SAL_CALL rtl_uString_alloc(sal_Int32 n @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); -} +COMPHELPER_DLLPUBLIC rtl_String * SAL_CALL rtl_string_alloc(sal_Int32 nLen); /** Removes all occurrences of a character from within the source string diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx index 3547de626318..6eb744fc3bdf 100644 --- a/comphelper/source/misc/string.cxx +++ b/comphelper/source/misc/string.cxx @@ -401,6 +401,43 @@ bool isdigitAsciiString(const rtl::OUString &rString) return tmpl_is_OPER_AsciiString<isdigitAscii>(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); +} + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |