Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include/internal/catch_stringdata.cpp
diff options
context:
space:
mode:
authorPhil Nash2017-06-29 11:18:14 +0100
committerPhil Nash2017-06-29 11:18:14 +0100
commit78e799443531a84c5f337109d462af53249ed49c (patch)
treea7dffa857b65d022145b258a7b7a3b110f902409 /include/internal/catch_stringdata.cpp
parentcb0a5194af7e092fde6f1f7deffb2758e28e65fe (diff)
downloadcatch3-78e799443531a84c5f337109d462af53249ed49c.tar.gz
Added string classes
Diffstat (limited to 'include/internal/catch_stringdata.cpp')
-rw-r--r--include/internal/catch_stringdata.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/include/internal/catch_stringdata.cpp b/include/internal/catch_stringdata.cpp
new file mode 100644
index 00000000..9f1625a8
--- /dev/null
+++ b/include/internal/catch_stringdata.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2016 Two Blue Cubes Ltd. All rights reserved.
+ *
+ * Distributed under the Boost Software License, Version 1.0. (See accompanying
+ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+
+
+#include "catch_stringdata.h"
+#include "catch_stringref.h"
+
+#include <new>
+#include <cstring>
+#include <cassert>
+
+namespace Catch {
+
+ auto StringData::getEmpty() -> StringData* {
+ static StringData s_empty( 0 );
+ return &s_empty;
+ }
+ auto StringData::create( StringRef const& stringRef ) -> StringData* {
+ return create( stringRef, stringRef.size() );
+ }
+ auto StringData::create( StringRef const& stringRef, unsigned long capacity ) -> StringData* {
+ if( capacity == 0 ) {
+ return getEmpty();
+ }
+ else {
+ assert( stringRef.size() <= capacity );
+ auto bufferLen = sizeof(StringData)+capacity;
+ void* buffer = new char[bufferLen];
+
+ return new(buffer) StringData( stringRef, capacity );
+ }
+ }
+ StringData::StringData( unsigned int initialRef )
+ : m_refs( initialRef ),
+ size( 0 )
+ {}
+ StringData::StringData( StringRef const& stringRef, unsigned long capacity )
+ : m_refs( 1 ),
+ size( capacity)
+ {
+ std::memcpy( chars, stringRef.data(), stringRef.size() );
+ chars[stringRef.size() ] = 0;
+ }
+
+} // namespace Catch \ No newline at end of file