mirror of
https://github.com/catchorg/Catch2.git
synced 2025-05-24 21:49:24 +00:00
Added string classes
This commit is contained in:
parent
cb0a5194af
commit
78e7994435
13 changed files with 908 additions and 0 deletions
49
include/internal/catch_stringdata.cpp
Normal file
49
include/internal/catch_stringdata.cpp
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue