#At file:///home/jonas/src/telco-7.0/ based on revid:jonas@stripped
4058 jonas oreland 2010-12-14
ndb - add constructor to BaseString for non null-terminated strings
modified:
storage/ndb/include/util/BaseString.hpp
storage/ndb/src/common/util/BaseString.cpp
=== modified file 'storage/ndb/include/util/BaseString.hpp'
--- a/storage/ndb/include/util/BaseString.hpp 2010-09-21 07:36:08 +0000
+++ b/storage/ndb/include/util/BaseString.hpp 2010-12-14 12:53:32 +0000
@@ -35,6 +35,9 @@ public:
/** @brief Constructs a copy of a char * */
BaseString(const char* s);
+ /** @brief Constructs a copy of a char * with length */
+ BaseString(const char* s, size_t len);
+
/** @brief Constructs a copy of another BaseString */
BaseString(const BaseString& str);
=== modified file 'storage/ndb/src/common/util/BaseString.cpp'
--- a/storage/ndb/src/common/util/BaseString.cpp 2010-11-28 11:34:01 +0000
+++ b/storage/ndb/src/common/util/BaseString.cpp 2010-12-14 12:53:32 +0000
@@ -54,6 +54,26 @@ BaseString::BaseString(const char* s)
m_len = n;
}
+BaseString::BaseString(const char * s, size_t n)
+{
+ if (s == NULL || n == 0)
+ {
+ m_chr = NULL;
+ m_len = 0;
+ return;
+ }
+ m_chr = new char[n + 1];
+ if (m_chr == NULL)
+ {
+ errno = ENOMEM;
+ m_len = 0;
+ return;
+ }
+ memcpy(m_chr, s, n);
+ m_chr[n] = 0;
+ m_len = n;
+}
+
BaseString::BaseString(const BaseString& str)
{
const char* const s = str.m_chr;
Attachment: [text/bzr-bundle] bzr/jonas@mysql.com-20101214125332-17momt1expemdmd9.bundle