Kaydet (Commit) 53294e81 authored tarafından Caolán McNamara's avatar Caolán McNamara

move template out of header

üst 60f97f3c
...@@ -46,22 +46,6 @@ ...@@ -46,22 +46,6 @@
// go into the stable URE API: // go into the stable URE API:
namespace comphelper { namespace string { 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. /** 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 The reference count of the new string will be 1. The length of the string
...@@ -82,10 +66,7 @@ namespace detail ...@@ -82,10 +66,7 @@ namespace detail
@param len @param len
the number of characters. the number of characters.
*/ */
COMPHELPER_DLLPUBLIC inline rtl_uString * SAL_CALL rtl_uString_alloc(sal_Int32 nLen) COMPHELPER_DLLPUBLIC 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. /** 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 ...@@ -107,10 +88,7 @@ COMPHELPER_DLLPUBLIC inline rtl_uString * SAL_CALL rtl_uString_alloc(sal_Int32 n
@param len @param len
the number of characters. the number of characters.
*/ */
COMPHELPER_DLLPUBLIC inline rtl_String * SAL_CALL rtl_string_alloc(sal_Int32 nLen) COMPHELPER_DLLPUBLIC rtl_String * SAL_CALL rtl_string_alloc(sal_Int32 nLen);
{
return detail::string_alloc<rtl_String, sal_Char>(nLen);
}
/** Removes all occurrences of a character from within the source string /** Removes all occurrences of a character from within the source string
......
...@@ -401,6 +401,43 @@ bool isdigitAsciiString(const rtl::OUString &rString) ...@@ -401,6 +401,43 @@ bool isdigitAsciiString(const rtl::OUString &rString)
return tmpl_is_OPER_AsciiString<isdigitAscii>(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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment