From 9c1799033d0c17fbefb52a9b2695922f5a715133 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Sun, 19 Jan 2014 21:46:02 -0800 Subject: Implement FString from scratch instead of hackishly --- src/strings/fstring.tcc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/strings/fstring.tcc') diff --git a/src/strings/fstring.tcc b/src/strings/fstring.tcc index 388aef1..9c5f37b 100644 --- a/src/strings/fstring.tcc +++ b/src/strings/fstring.tcc @@ -17,6 +17,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include "mstring.hpp" + namespace strings { template @@ -24,22 +26,24 @@ namespace strings { if (b == e) { - // TODO use a special empty object - // return; + *this = FString(); + return; } if (!std::is_base_of::iterator_category>::value) { // can't use std::distance - _hack2 = std::make_shared>(); + MString m; for (; b != e; ++b) - _hack2->push_back(*b); - _hack2->push_back('\0'); - _hack2->shrink_to_fit(); + m += *b; + *this = FString(m); // will recurse return; } size_t diff = std::distance(b, e); - _hack2 = std::make_shared>(diff + 1, '\0'); - std::copy(b, e, _hack2->begin()); + owned = static_cast(::operator new(sizeof(Rep) + diff + 1)); + owned->count = 0; + owned->size = diff; + std::copy(b, e, owned->body); + owned->body[diff] = '\0'; } template -- cgit v1.2.3-70-g09d2