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/source/misc | |
parent | 60f97f3ceb670a310e89cd1be948e04b469539f2 (diff) |
move template out of header
Diffstat (limited to 'comphelper/source/misc')
-rw-r--r-- | comphelper/source/misc/string.cxx | 37 |
1 files changed, 37 insertions, 0 deletions
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: */ |