diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2014-01-19 21:46:02 -0800 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2014-01-20 14:03:52 -0800 |
commit | 9c1799033d0c17fbefb52a9b2695922f5a715133 (patch) | |
tree | f2859d02f87081a9166e3253c4e7c4973b82fcea /src/strings/fstring.tcc | |
parent | b9ac1c6033a0b32ca9984f23223d9fc167415b10 (diff) | |
download | tmwa-9c1799033d0c17fbefb52a9b2695922f5a715133.tar.gz tmwa-9c1799033d0c17fbefb52a9b2695922f5a715133.tar.bz2 tmwa-9c1799033d0c17fbefb52a9b2695922f5a715133.tar.xz tmwa-9c1799033d0c17fbefb52a9b2695922f5a715133.zip |
Implement FString from scratch instead of hackishly
Diffstat (limited to 'src/strings/fstring.tcc')
-rw-r--r-- | src/strings/fstring.tcc | 20 |
1 files changed, 12 insertions, 8 deletions
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 <http://www.gnu.org/licenses/>. +#include "mstring.hpp" + namespace strings { template<class It> @@ -24,22 +26,24 @@ namespace strings { if (b == e) { - // TODO use a special empty object - // return; + *this = FString(); + return; } if (!std::is_base_of<std::forward_iterator_tag, typename std::iterator_traits<It>::iterator_category>::value) { // can't use std::distance - _hack2 = std::make_shared<std::vector<char>>(); + 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<std::vector<char>>(diff + 1, '\0'); - std::copy(b, e, _hack2->begin()); + owned = static_cast<Rep *>(::operator new(sizeof(Rep) + diff + 1)); + owned->count = 0; + owned->size = diff; + std::copy(b, e, owned->body); + owned->body[diff] = '\0'; } template<size_t n> |