summaryrefslogtreecommitdiff
path: root/comphelper/source
diff options
context:
space:
mode:
Diffstat (limited to 'comphelper/source')
-rw-r--r--comphelper/source/misc/string.cxx37
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: */