summaryrefslogtreecommitdiff
path: root/src/strings
diff options
context:
space:
mode:
Diffstat (limited to 'src/strings')
-rw-r--r--src/strings/all.hpp29
-rw-r--r--src/strings/astring.cpp43
-rw-r--r--src/strings/astring.hpp40
-rw-r--r--src/strings/astring.py2
-rw-r--r--src/strings/astring.tcc21
-rw-r--r--src/strings/base.hpp19
-rw-r--r--src/strings/base.tcc6
-rw-r--r--src/strings/base_test.cpp11
-rw-r--r--src/strings/fwd.hpp25
-rw-r--r--src/strings/literal.cpp56
-rw-r--r--src/strings/literal.hpp79
-rw-r--r--src/strings/mstring.cpp4
-rw-r--r--src/strings/mstring.hpp13
-rw-r--r--src/strings/pair.hpp34
-rw-r--r--src/strings/rstring.cpp17
-rw-r--r--src/strings/rstring.hpp25
-rw-r--r--src/strings/rstring.py2
-rw-r--r--src/strings/rstring.tcc10
-rw-r--r--src/strings/sstring.cpp11
-rw-r--r--src/strings/sstring.hpp22
-rw-r--r--src/strings/sstring.tcc9
-rw-r--r--src/strings/strings2_test.cpp94
-rw-r--r--src/strings/strings_test.cpp67
-rw-r--r--src/strings/tstring.cpp11
-rw-r--r--src/strings/tstring.hpp22
-rw-r--r--src/strings/tstring.tcc8
-rw-r--r--src/strings/vstring.cpp4
-rw-r--r--src/strings/vstring.hpp22
-rw-r--r--src/strings/vstring.py2
-rw-r--r--src/strings/vstring.tcc17
-rw-r--r--src/strings/xstring.cpp14
-rw-r--r--src/strings/xstring.hpp20
-rw-r--r--src/strings/xstring.py2
-rw-r--r--src/strings/xstring.tcc8
-rw-r--r--src/strings/zstring.cpp23
-rw-r--r--src/strings/zstring.hpp23
-rw-r--r--src/strings/zstring.py2
-rw-r--r--src/strings/zstring.tcc11
38 files changed, 500 insertions, 328 deletions
diff --git a/src/strings/all.hpp b/src/strings/all.hpp
index 26079ed..8e13b92 100644
--- a/src/strings/all.hpp
+++ b/src/strings/all.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_STRINGS_ALL_HPP
-#define TMWA_STRINGS_ALL_HPP
+#pragma once
// strings/all.hpp - All the string classes you'll ever need.
//
// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,16 +18,20 @@
// 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 "../sanity.hpp"
+#include "fwd.hpp"
-# include "base.hpp"
-# include "mstring.hpp"
-# include "rstring.hpp"
-# include "astring.hpp"
-# include "tstring.hpp"
-# include "sstring.hpp"
-# include "zstring.hpp"
-# include "xstring.hpp"
-# include "vstring.hpp"
+#include "base.hpp"
+#include "mstring.hpp"
+#include "rstring.hpp"
+#include "astring.hpp"
+#include "tstring.hpp"
+#include "sstring.hpp"
+#include "zstring.hpp"
+#include "xstring.hpp"
+#include "literal.hpp"
+#include "vstring.hpp"
-#endif // TMWA_STRINGS_ALL_HPP
+
+namespace tmwa
+{
+} // namespace tmwa
diff --git a/src/strings/astring.cpp b/src/strings/astring.cpp
index f1e9030..f1f12c3 100644
--- a/src/strings/astring.cpp
+++ b/src/strings/astring.cpp
@@ -18,15 +18,25 @@
// 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 <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+
+#include <algorithm>
+
#include "mstring.hpp"
#include "tstring.hpp"
#include "sstring.hpp"
#include "zstring.hpp"
#include "xstring.hpp"
-#include "vstring.hpp"
+#include "literal.hpp"
+// doing sneaky tricks here
//#include "../poison.hpp"
+
+namespace tmwa
+{
namespace strings
{
static_assert(sizeof(AString) == 256, "AString");
@@ -156,6 +166,13 @@ namespace strings
special = 255 - x.size();
}
}
+ AString::AString(LString l)
+ : data{}, special()
+ {
+ new(r_ptr()) RString();
+ special = 255;
+ *this = XString(l);
+ }
AString::iterator AString::begin() const
{
@@ -205,27 +222,5 @@ namespace strings
out = AString(buffer, buffer + len);
return len;
}
-
- AStringConverter::AStringConverter(AString& s)
- : out(s), mid(nullptr)
- {}
-
- AStringConverter::~AStringConverter()
- {
- if (mid)
- {
- out = ZString(really_construct_from_a_pointer, mid, nullptr);
- free(mid);
- }
- }
-
- char **AStringConverter::operator &()
- {
- return &mid;
- }
-
- AStringConverter convert_for_scanf(AString& s)
- {
- return AStringConverter(s);
- }
} // namespace strings
+} // namespace tmwa
diff --git a/src/strings/astring.hpp b/src/strings/astring.hpp
index aab14cf..83399f0 100644
--- a/src/strings/astring.hpp
+++ b/src/strings/astring.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_STRINGS_ASTRING_HPP
-#define TMWA_STRINGS_ASTRING_HPP
+#pragma once
// strings/astring.hpp - An owned, reference-counted immutable string.
//
// Copyright © 2013-2014 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,20 +18,23 @@
// 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 "../sanity.hpp"
+#include "fwd.hpp"
-# include <cstdarg>
-# include <cstring>
+#include "base.hpp"
+#include "rstring.hpp"
-# include "base.hpp"
-# include "rstring.hpp"
+namespace tmwa
+{
namespace strings
{
/// An owning string that has reached its final contents.
/// The storage is NUL-terminated
class AString : public _crtp_string<AString, AString, ZPair>
{
+#ifdef __clang__
+ __attribute__((unused))
+#endif
RString *align[0];
char data[255];
unsigned char special;
@@ -49,12 +51,6 @@ namespace strings
explicit AString(const MString& s);
- template<size_t n>
- AString(char (&s)[n]) = delete;
-
- template<size_t n>
- AString(const char (&s)[n]);
-
template<class It>
AString(It b, It e);
@@ -66,6 +62,7 @@ namespace strings
AString(XString);
template<uint8_t n>
AString(const VString<n>& v);
+ AString(LString s);
iterator begin() const;
iterator end() const;
@@ -81,20 +78,7 @@ namespace strings
__attribute__((format(printf, 2, 0)))
int do_vprint(AString& out, const char *fmt, va_list ap);
-
- class AStringConverter
- {
- AString& out;
- char *mid;
- public:
- AStringConverter(AString& s);
- ~AStringConverter();
- char **operator &();
- };
-
- AStringConverter convert_for_scanf(AString& s);
} // namespace strings
+} // namespace tmwa
-# include "astring.tcc"
-
-#endif // TMWA_STRINGS_ASTRING_HPP
+#include "astring.tcc"
diff --git a/src/strings/astring.py b/src/strings/astring.py
index ec1dafe..063e721 100644
--- a/src/strings/astring.py
+++ b/src/strings/astring.py
@@ -2,7 +2,7 @@ class AString(object):
''' print an AString
'''
__slots__ = ('_value')
- name = 'strings::AString'
+ name = 'tmwa::strings::AString'
enabled = True
def __init__(self, value):
diff --git a/src/strings/astring.tcc b/src/strings/astring.tcc
index ed07bd9..f2d0dc9 100644
--- a/src/strings/astring.tcc
+++ b/src/strings/astring.tcc
@@ -19,25 +19,11 @@
#include "mstring.hpp"
+
+namespace tmwa
+{
namespace strings
{
- template<size_t n>
- AString::AString(const char (&s)[n])
- : data{}, special()
- {
- XPair x = s;
- if (x.size() > 255 || x.size() == 0)
- {
- new(r_ptr()) RString(x);
- special = 255;
- }
- else
- {
- *std::copy(x.begin(), x.end(), data) = '\0';
- special = 255 - x.size();
- }
- }
-
template<class It>
AString::AString(It b, It e)
: data{}, special()
@@ -74,3 +60,4 @@ namespace strings
new(r_ptr()) RString();
}
} // namespace strings
+} // namespace tmwa
diff --git a/src/strings/base.hpp b/src/strings/base.hpp
index ee7480b..b6b3df0 100644
--- a/src/strings/base.hpp
+++ b/src/strings/base.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_STRINGS_BASE_HPP
-#define TMWA_STRINGS_BASE_HPP
+#pragma once
// strings/base.hpp - CRTP base for string implementations.
//
// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,15 +18,16 @@
// 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 "../sanity.hpp"
+#include "fwd.hpp"
+#include "pair.hpp"
-# include "fwd.hpp"
-# include "pair.hpp"
+#include <cstddef>
-# include <cstddef>
+#include <iterator>
-# include <iterator>
+namespace tmwa
+{
// It is a common mistake to assume that one string class for everything.
// Because C++ and TMWA have a C legacy, there are a few more here
// than would probably be necessary in an ideal language.
@@ -197,7 +197,6 @@ namespace strings
template<class L, class R, typename=typename std::enable_if<string_comparison_allowed<L, R>::value>::type>
auto operator >= (const L& l, const R& r) -> decltype((pair_compare(l, r), true));
} // namespace strings
+} // namespace tmwa
-# include "base.tcc"
-
-#endif // TMWA_STRINGS_BASE_HPP
+#include "base.tcc"
diff --git a/src/strings/base.tcc b/src/strings/base.tcc
index a5a57d0..83dff70 100644
--- a/src/strings/base.tcc
+++ b/src/strings/base.tcc
@@ -17,10 +17,15 @@
// 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 <cstddef>
+
#include <algorithm>
#include "pair.hpp"
+
+namespace tmwa
+{
namespace strings
{
namespace detail
@@ -440,3 +445,4 @@ namespace strings
return pair_compare(l, r) >= 0;
}
} // namespace strings
+} // namespace tmwa
diff --git a/src/strings/base_test.cpp b/src/strings/base_test.cpp
index 52c44dc..f9b9ca6 100644
--- a/src/strings/base_test.cpp
+++ b/src/strings/base_test.cpp
@@ -23,9 +23,13 @@
#include "vstring.hpp"
#include "xstring.hpp"
#include "rstring.hpp"
+#include "literal.hpp"
#include "../poison.hpp"
+
+namespace tmwa
+{
using namespace strings;
struct _test : VString<1> {};
@@ -42,7 +46,8 @@ static_assert(string_comparison_allowed<XString, RString>::value, "xf");
TEST(strings, contains)
{
- XString hi = "Hello";
- EXPECT_TRUE(hi.contains_any("Hi"));
- EXPECT_FALSE(hi.contains_any("hi"));
+ XString hi = "Hello"_s;
+ EXPECT_TRUE(hi.contains_any("Hi"_s));
+ EXPECT_FALSE(hi.contains_any("hi"_s));
}
+} // namespace tmwa
diff --git a/src/strings/fwd.hpp b/src/strings/fwd.hpp
index 4c58e03..b1b8266 100644
--- a/src/strings/fwd.hpp
+++ b/src/strings/fwd.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_STRINGS_FWD_HPP
-#define TMWA_STRINGS_FWD_HPP
+#pragma once
// strings/fwd.hpp - Forward declarations for all the string classes.
//
// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,10 +18,14 @@
// 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 "../sanity.hpp"
+#include "../sanity.hpp"
-# include <cstdint>
+#include <cstddef>
+#include <cstdint>
+
+namespace tmwa
+{
// It is a common mistake to assume that one string class for everything.
// Because C++ and TMWA have a C legacy, there are a few more here
// than would probably be necessary in an ideal language.
@@ -40,12 +43,18 @@ namespace strings
class XString;
// semi-owning
+ class LString;
+ class FormatString;
template<uint8_t len>
class VString;
- // refactor this into a function?
+ // TODO refactor this into a function?
enum _type_that_just_has_a_name_to_fix_linkage
{ really_construct_from_a_pointer };
+
+ LString operator "" _s(const char *, size_t);
+ constexpr
+ FormatString operator "" _fmt(const char *, size_t);
} // namespace strings
using strings::MString;
@@ -57,6 +66,10 @@ using strings::SString;
using strings::ZString;
using strings::XString;
+using strings::LString;
+using strings::FormatString;
using strings::VString;
-#endif // TMWA_STRINGS_FWD_HPP
+using strings::operator "" _s;
+using strings::operator "" _fmt;
+} // namespace tmwa
diff --git a/src/strings/literal.cpp b/src/strings/literal.cpp
new file mode 100644
index 0000000..252bfcb
--- /dev/null
+++ b/src/strings/literal.cpp
@@ -0,0 +1,56 @@
+#include "literal.hpp"
+// strings/literal.cpp - A string stored in the readonly data segment.
+//
+// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// 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 <cstdio>
+
+#include "../poison.hpp"
+
+
+namespace tmwa
+{
+namespace strings
+{
+ LString::LString(const char *b, const char *e)
+ : _b(b), _e(e)
+ {}
+
+ LString::iterator LString::begin() const
+ {
+ return _b;
+ }
+ LString::iterator LString::end() const
+ {
+ return _e;
+ }
+ const RString *LString::base() const
+ {
+ return nullptr;
+ }
+ const char *LString::c_str() const
+ {
+ return &*begin();
+ }
+
+ const char *decay_for_printf(const LString& zs)
+ {
+ return zs.c_str();
+ }
+} // namespace strings
+} // namespace tmwa
diff --git a/src/strings/literal.hpp b/src/strings/literal.hpp
new file mode 100644
index 0000000..67bd317
--- /dev/null
+++ b/src/strings/literal.hpp
@@ -0,0 +1,79 @@
+#pragma once
+// strings/literal.hpp - A string stored in the readonly data segment.
+//
+// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// 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 "fwd.hpp"
+
+#include "base.hpp"
+
+
+namespace tmwa
+{
+namespace strings
+{
+ /// A statically owned string that is guaranteed to be NUL-terminated.
+ /// This is a more permissive lifetime than anybody else has.
+ class LString : public _crtp_string<LString, AString, LPair>
+ {
+ iterator _b, _e;
+ private:
+ LString(const char *b, const char *e);
+ friend LString operator "" _s(const char *, size_t);
+ // for tail slicing
+ LString(const char *b, const char *e, const RString *) : LString(b, e) {}
+ friend class _crtp_string<LString, AString, LPair>;
+ public:
+
+ iterator begin() const;
+ iterator end() const;
+ const RString *base() const;
+ const char *c_str() const;
+ };
+
+ class FormatString
+ {
+ const char *_format;
+
+ friend constexpr FormatString operator "" _fmt(const char *, size_t);
+ constexpr explicit
+ FormatString(const char *f) : _format(f) {}
+ public:
+ constexpr
+ const char *format_string() const { return _format; }
+ };
+
+
+ // cxxstdio helpers
+ // I think the conversion will happen automatically. TODO test this.
+ // Nope, it doesn't, since there's a template
+ // Actually, it might now.
+ const char *decay_for_printf(const LString& zs);
+
+ inline
+ LString operator "" _s(const char *s, size_t)
+ {
+ return LString(s, s + __builtin_strlen(s));
+ }
+ constexpr
+ FormatString operator "" _fmt(const char *s, size_t)
+ {
+ return FormatString(s);
+ }
+} // namespace strings
+} // namespace tmwa
diff --git a/src/strings/mstring.cpp b/src/strings/mstring.cpp
index 2a1ca62..d48bff2 100644
--- a/src/strings/mstring.cpp
+++ b/src/strings/mstring.cpp
@@ -22,6 +22,9 @@
#include "../poison.hpp"
+
+namespace tmwa
+{
namespace strings
{
MString::iterator MString::begin()
@@ -100,3 +103,4 @@ namespace strings
return _hack.back();
}
} // namespace strings
+} // namespace tmwa
diff --git a/src/strings/mstring.hpp b/src/strings/mstring.hpp
index 8225d9e..4f40919 100644
--- a/src/strings/mstring.hpp
+++ b/src/strings/mstring.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_STRINGS_MSTRING_HPP
-#define TMWA_STRINGS_MSTRING_HPP
+#pragma once
// strings/mstring.hpp - A mutable string.
//
// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,12 +18,13 @@
// 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 "../sanity.hpp"
+#include "fwd.hpp"
-# include <deque>
+#include <deque>
-# include "base.hpp"
+namespace tmwa
+{
namespace strings
{
/// An owning string that is still expected to change.
@@ -64,5 +64,4 @@ namespace strings
char& back();
};
} // namespace strings
-
-#endif // TMWA_STRINGS_MSTRING_HPP
+} // namespace tmwa
diff --git a/src/strings/pair.hpp b/src/strings/pair.hpp
index a592a91..9c1cd9f 100644
--- a/src/strings/pair.hpp
+++ b/src/strings/pair.hpp
@@ -1,8 +1,7 @@
-#ifndef TMWA_STRINGS_PAIR_HPP
-#define TMWA_STRINGS_PAIR_HPP
+#pragma once
// strings/pair.hpp - Internal contiguous range.
//
-// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
+// Copyright © 2013-2014 Ben Longbons <b.r.longbons@gmail.com>
//
// This file is part of The Mana World (Athena server)
//
@@ -19,12 +18,11 @@
// 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 "../sanity.hpp"
+#include "fwd.hpp"
-# include <cstring>
-
-# include "fwd.hpp"
+namespace tmwa
+{
namespace strings
{
// TODO instead typedef ranges::Contiguous<const char>
@@ -40,12 +38,6 @@ namespace strings
XPair(const char *b, const char *e)
: _begin(b), _end(e)
{}
- template<size_t n>
- XPair(char (&arr)[n]) = delete;
- template<size_t n>
- XPair(const char (&arr)[n])
- : _begin(arr), _end(arr + strlen(arr))
- {}
const char *begin() const { return _begin; }
const char *end() const { return _end; }
@@ -59,13 +51,15 @@ namespace strings
ZPair(const char *b, const char *e)
: XPair(b, e)
{}
- template<size_t n>
- ZPair(char (&arr)[n]) = delete;
- template<size_t n>
- ZPair(const char (&arr)[n])
- : XPair(arr)
+ };
+ struct LPair : ZPair
+ {
+ typedef LString TailSlice;
+ typedef XString FullSlice;
+
+ LPair(const char *b, const char *e)
+ : ZPair(b, e)
{}
};
} // namespace strings
-
-#endif // TMWA_STRINGS_PAIR_HPP
+} // namespace tmwa
diff --git a/src/strings/rstring.cpp b/src/strings/rstring.cpp
index c0e231e..3e5a46d 100644
--- a/src/strings/rstring.cpp
+++ b/src/strings/rstring.cpp
@@ -18,15 +18,22 @@
// 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 <cstdio>
+
#include "mstring.hpp"
+#include "astring.hpp"
#include "tstring.hpp"
#include "sstring.hpp"
#include "zstring.hpp"
#include "xstring.hpp"
-#include "vstring.hpp"
+#include "literal.hpp"
+// doing sneaky tricks here
//#include "../poison.hpp"
+
+namespace tmwa
+{
namespace strings
{
static_assert(sizeof(RString) == sizeof(const char *), "RString");
@@ -54,7 +61,7 @@ namespace strings
{
// order important for self-assign
r.owned->count++;
- // owned can be NULL from ctors
+ // owned can be nullptr from ctors
// TODO do ctors *properly* (requires gcc 4.7 to stay sane)
if (owned && !owned->count--)
::operator delete(owned);
@@ -125,6 +132,11 @@ namespace strings
else
_assign(x.begin(), x.end());
}
+ RString::RString(LString l)
+ : owned(nullptr)
+ {
+ *this = XString(l);
+ }
RString::iterator RString::begin() const
{
@@ -164,3 +176,4 @@ namespace strings
return len;
}
} // namespace strings
+} // namespace tmwa
diff --git a/src/strings/rstring.hpp b/src/strings/rstring.hpp
index 7cb19d6..fd3ee65 100644
--- a/src/strings/rstring.hpp
+++ b/src/strings/rstring.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_STRINGS_RSTRING_HPP
-#define TMWA_STRINGS_RSTRING_HPP
+#pragma once
// strings/rstring.hpp - An owned, reference-counted immutable string.
//
// Copyright © 2013-2014 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,13 +18,15 @@
// 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 "../sanity.hpp"
+#include "fwd.hpp"
-# include <cstdarg>
-# include <cstring>
+#include <cstdarg>
-# include "base.hpp"
+#include "base.hpp"
+
+namespace tmwa
+{
namespace strings
{
/// An owning string that has reached its final contents.
@@ -56,12 +57,6 @@ namespace strings
explicit RString(const MString& s);
- template<size_t n>
- RString(char (&s)[n]) = delete;
-
- template<size_t n>
- RString(const char (&s)[n]);
-
template<class It>
RString(It b, It e);
@@ -73,6 +68,7 @@ namespace strings
RString(XString);
template<uint8_t n>
RString(const VString<n>& v);
+ RString(LString s);
iterator begin() const;
iterator end() const;
@@ -89,7 +85,6 @@ namespace strings
__attribute__((format(printf, 2, 0)))
int do_vprint(RString& out, const char *fmt, va_list ap);
} // namespace strings
+} // namespace tmwa
-# include "rstring.tcc"
-
-#endif // TMWA_STRINGS_RSTRING_HPP
+#include "rstring.tcc"
diff --git a/src/strings/rstring.py b/src/strings/rstring.py
index f0618d6..8021ec2 100644
--- a/src/strings/rstring.py
+++ b/src/strings/rstring.py
@@ -2,7 +2,7 @@ class RString(object):
''' print a RString
'''
__slots__ = ('_value')
- name = 'strings::RString'
+ name = 'tmwa::strings::RString'
enabled = True
def __init__(self, value):
diff --git a/src/strings/rstring.tcc b/src/strings/rstring.tcc
index 8b4c0c0..c247b8f 100644
--- a/src/strings/rstring.tcc
+++ b/src/strings/rstring.tcc
@@ -19,6 +19,9 @@
#include "mstring.hpp"
+
+namespace tmwa
+{
namespace strings
{
template<class It>
@@ -47,12 +50,6 @@ namespace strings
owned->body[diff] = '\0';
}
- template<size_t n>
- RString::RString(const char (&s)[n])
- {
- _assign(s, s + strlen(s));
- }
-
template<class It>
RString::RString(It b, It e)
{
@@ -65,3 +62,4 @@ namespace strings
_assign(v.begin(), v.end());
}
} // namespace strings
+} // namespace tmwa
diff --git a/src/strings/sstring.cpp b/src/strings/sstring.cpp
index 76f0994..0500129 100644
--- a/src/strings/sstring.cpp
+++ b/src/strings/sstring.cpp
@@ -18,12 +18,18 @@
// 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 "rstring.hpp"
+#include "astring.hpp"
#include "tstring.hpp"
#include "zstring.hpp"
#include "xstring.hpp"
+#include "literal.hpp"
#include "../poison.hpp"
+
+namespace tmwa
+{
namespace strings
{
SString::SString()
@@ -54,6 +60,10 @@ namespace strings
else
*this = RString(x);
}
+ SString::SString(const LString& l)
+ {
+ *this = XString(l);
+ }
SString::SString(RString r, size_t b, size_t e)
: _s(std::move(r)), _b(b), _e(e)
@@ -95,3 +105,4 @@ namespace strings
return &_s;
}
} // namespace strings
+} // namespace tmwa
diff --git a/src/strings/sstring.hpp b/src/strings/sstring.hpp
index 7166e94..a65616d 100644
--- a/src/strings/sstring.hpp
+++ b/src/strings/sstring.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_STRINGS_SSTRING_HPP
-#define TMWA_STRINGS_SSTRING_HPP
+#pragma once
// strings/sstring.hpp - A full slice of an RString.
//
// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,11 +18,14 @@
// 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 "../sanity.hpp"
+#include "fwd.hpp"
-# include "base.hpp"
-# include "rstring.hpp"
+#include "base.hpp"
+#include "rstring.hpp"
+
+namespace tmwa
+{
namespace strings
{
/// An owning string that represents a arbitrary slice of an RString.
@@ -42,10 +44,7 @@ namespace strings
SString(const XString&);
template<uint8_t n>
SString(const VString<n>& v);
- template<size_t n>
- SString(char (&s)[n]) = delete;
- template<size_t n>
- SString(const char (&s)[n]);
+ SString(const LString&);
//template<class It>
//SString(It b, It e) : _s(b, e), _b(0), _e(_s.size()) {}
SString(RString f, size_t b, size_t e);
@@ -57,7 +56,6 @@ namespace strings
const RString *base() const;
};
} // namespace strings
+} // namespace tmwa
-# include "sstring.tcc"
-
-#endif // TMWA_STRINGS_SSTRING_HPP
+#include "sstring.tcc"
diff --git a/src/strings/sstring.tcc b/src/strings/sstring.tcc
index 4be33dd..315e19a 100644
--- a/src/strings/sstring.tcc
+++ b/src/strings/sstring.tcc
@@ -19,15 +19,14 @@
#include "vstring.hpp"
+
+namespace tmwa
+{
namespace strings
{
template<uint8_t n>
SString::SString(const VString<n>& v)
: _s(v), _b(0), _e(_s.size())
{}
-
- template<size_t n>
- SString::SString(const char (&s)[n])
- : _s(s), _b(0), _e(_s.size())
- {}
} // namespace strings
+} // namespace tmwa
diff --git a/src/strings/strings2_test.cpp b/src/strings/strings2_test.cpp
index e5d5281..18c7db4 100644
--- a/src/strings/strings2_test.cpp
+++ b/src/strings/strings2_test.cpp
@@ -1,4 +1,3 @@
-#include "all.hpp"
// strings2_test.cpp - Testsuite part 2 for strings.
//
// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
@@ -18,30 +17,34 @@
// 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 <gtest/gtest.h>
+#include "all.hpp"
+
#include "../poison.hpp"
+
+namespace tmwa
+{
TEST(StringTests, traits2)
{
- ZString print_non = "\t\e";
- ZString print_mix = "n\t";
- RString print_all = "n ";
+ ZString print_non = "\t\e"_s;
+ ZString print_mix = "n\t"_s;
+ RString print_all = "n "_s;
EXPECT_FALSE(print_non.has_print());
EXPECT_TRUE(print_mix.has_print());
EXPECT_TRUE(print_all.has_print());
EXPECT_FALSE(print_non.is_print());
EXPECT_FALSE(print_mix.is_print());
EXPECT_TRUE(print_all.is_print());
- EXPECT_EQ("__", print_non.to_print());
- EXPECT_EQ("n_", print_mix.to_print());
- EXPECT_EQ("n ", print_all.to_print());
+ EXPECT_EQ("__"_s, print_non.to_print());
+ EXPECT_EQ("n_"_s, print_mix.to_print());
+ EXPECT_EQ("n "_s, print_all.to_print());
EXPECT_EQ(print_all.begin(), print_all.to_print().begin());
- ZString graph_non = " \e";
- ZString graph_mix = "n ";
- RString graph_all = "n.";
+ ZString graph_non = " \e"_s;
+ ZString graph_mix = "n "_s;
+ RString graph_all = "n."_s;
EXPECT_FALSE(graph_non.has_graph());
EXPECT_TRUE(graph_mix.has_graph());
EXPECT_TRUE(graph_all.has_graph());
@@ -49,37 +52,37 @@ TEST(StringTests, traits2)
EXPECT_FALSE(graph_mix.is_graph());
EXPECT_TRUE(graph_all.is_graph());
- ZString lower_non = "0A";
- ZString lower_mix = "Oa";
- RString lower_all = "oa";
+ ZString lower_non = "0A"_s;
+ ZString lower_mix = "Oa"_s;
+ RString lower_all = "oa"_s;
EXPECT_FALSE(lower_non.has_lower());
EXPECT_TRUE(lower_mix.has_lower());
EXPECT_TRUE(lower_all.has_lower());
EXPECT_FALSE(lower_non.is_lower());
EXPECT_FALSE(lower_mix.is_lower());
EXPECT_TRUE(lower_all.is_lower());
- EXPECT_EQ("0a", lower_non.to_lower());
- EXPECT_EQ("oa", lower_mix.to_lower());
- EXPECT_EQ("oa", lower_all.to_lower());
+ EXPECT_EQ("0a"_s, lower_non.to_lower());
+ EXPECT_EQ("oa"_s, lower_mix.to_lower());
+ EXPECT_EQ("oa"_s, lower_all.to_lower());
EXPECT_EQ(lower_all.begin(), lower_all.to_lower().begin());
- ZString upper_non = "0a";
- ZString upper_mix = "oA";
- RString upper_all = "OA";
+ ZString upper_non = "0a"_s;
+ ZString upper_mix = "oA"_s;
+ RString upper_all = "OA"_s;
EXPECT_FALSE(upper_non.has_upper());
EXPECT_TRUE(upper_mix.has_upper());
EXPECT_TRUE(upper_all.has_upper());
EXPECT_FALSE(upper_non.is_upper());
EXPECT_FALSE(upper_mix.is_upper());
EXPECT_TRUE(upper_all.is_upper());
- EXPECT_EQ("0A", upper_non.to_upper());
- EXPECT_EQ("OA", upper_mix.to_upper());
- EXPECT_EQ("OA", upper_all.to_upper());
+ EXPECT_EQ("0A"_s, upper_non.to_upper());
+ EXPECT_EQ("OA"_s, upper_mix.to_upper());
+ EXPECT_EQ("OA"_s, upper_all.to_upper());
EXPECT_EQ(upper_all.begin(), upper_all.to_upper().begin());
- ZString alpha_non = " 0";
- ZString alpha_mix = "n ";
- RString alpha_all = "nA";
+ ZString alpha_non = " 0"_s;
+ ZString alpha_mix = "n "_s;
+ RString alpha_all = "nA"_s;
EXPECT_FALSE(alpha_non.has_alpha());
EXPECT_TRUE(alpha_mix.has_alpha());
EXPECT_TRUE(alpha_all.has_alpha());
@@ -87,9 +90,9 @@ TEST(StringTests, traits2)
EXPECT_FALSE(alpha_mix.is_alpha());
EXPECT_TRUE(alpha_all.is_alpha());
- ZString digit2_non = "a9";
- ZString digit2_mix = "20";
- RString digit2_all = "01";
+ ZString digit2_non = "a9"_s;
+ ZString digit2_mix = "20"_s;
+ RString digit2_all = "01"_s;
EXPECT_FALSE(digit2_non.has_digit2());
EXPECT_TRUE(digit2_mix.has_digit2());
EXPECT_TRUE(digit2_all.has_digit2());
@@ -97,9 +100,9 @@ TEST(StringTests, traits2)
EXPECT_FALSE(digit2_mix.is_digit2());
EXPECT_TRUE(digit2_all.is_digit2());
- ZString digit8_non = "a9";
- ZString digit8_mix = "80";
- RString digit8_all = "37";
+ ZString digit8_non = "a9"_s;
+ ZString digit8_mix = "80"_s;
+ RString digit8_all = "37"_s;
EXPECT_FALSE(digit8_non.has_digit8());
EXPECT_TRUE(digit8_mix.has_digit8());
EXPECT_TRUE(digit8_all.has_digit8());
@@ -107,9 +110,9 @@ TEST(StringTests, traits2)
EXPECT_FALSE(digit8_mix.is_digit8());
EXPECT_TRUE(digit8_all.is_digit8());
- ZString digit10_non = "az";
- ZString digit10_mix = "a9";
- RString digit10_all = "42";
+ ZString digit10_non = "az"_s;
+ ZString digit10_mix = "a9"_s;
+ RString digit10_all = "42"_s;
EXPECT_FALSE(digit10_non.has_digit10());
EXPECT_TRUE(digit10_mix.has_digit10());
EXPECT_TRUE(digit10_all.has_digit10());
@@ -117,9 +120,9 @@ TEST(StringTests, traits2)
EXPECT_FALSE(digit10_mix.is_digit10());
EXPECT_TRUE(digit10_all.is_digit10());
- ZString digit16_non = "gz";
- ZString digit16_mix = "ao";
- RString digit16_all = "be";
+ ZString digit16_non = "gz"_s;
+ ZString digit16_mix = "ao"_s;
+ RString digit16_all = "be"_s;
EXPECT_FALSE(digit16_non.has_digit16());
EXPECT_TRUE(digit16_mix.has_digit16());
EXPECT_TRUE(digit16_all.has_digit16());
@@ -127,9 +130,9 @@ TEST(StringTests, traits2)
EXPECT_FALSE(digit16_mix.is_digit16());
EXPECT_TRUE(digit16_all.is_digit16());
- ZString alnum_non = " .";
- ZString alnum_mix = "n ";
- RString alnum_all = "n0";
+ ZString alnum_non = " ."_s;
+ ZString alnum_mix = "n "_s;
+ RString alnum_all = "n0"_s;
EXPECT_FALSE(alnum_non.has_alnum());
EXPECT_TRUE(alnum_mix.has_alnum());
EXPECT_TRUE(alnum_all.has_alnum());
@@ -140,7 +143,7 @@ TEST(StringTests, traits2)
TEST(StringTests, rempty)
{
- const char empty_text[] = "";
+ LString empty_text = ""_s;
RString r = empty_text;
EXPECT_EQ(r.size(), 0);
AString a = empty_text;
@@ -166,7 +169,7 @@ TEST(StringTests, rempty)
}
TEST(StringTests, rshort)
{
- const char short_text[] = "0123456789";
+ LString short_text = "0123456789"_s;
RString r = short_text;
EXPECT_EQ(r.size(), 10);
AString a = short_text;
@@ -193,13 +196,13 @@ TEST(StringTests, rshort)
TEST(StringTests, rlong)
{
- const char long_text[] =
+ LString long_text =
"01234567890123456789012345678901234567890123456789"
"0123456789012345678901234567890123456789012345 100"
"01234567890123456789012345678901234567890123456789"
"0123456789012345678901234567890123456789012345 200"
"01234567890123456789012345678901234567890123456789"
- "0123456789012345678901234567890123456789012345 300";
+ "0123456789012345678901234567890123456789012345 300"_s;
RString r = long_text;
EXPECT_EQ(r.size(), 300);
AString a = long_text;
@@ -223,3 +226,4 @@ TEST(StringTests, rlong)
EXPECT_EQ(&*r.begin(), &*r3.begin());
EXPECT_EQ(&*a.begin(), &*a3.begin());
}
+} // namespace tmwa
diff --git a/src/strings/strings_test.cpp b/src/strings/strings_test.cpp
index dca463d..a95499d 100644
--- a/src/strings/strings_test.cpp
+++ b/src/strings/strings_test.cpp
@@ -1,4 +1,3 @@
-#include "all.hpp"
// strings_test.cpp - Testsuite part 1 for strings.
//
// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
@@ -22,8 +21,13 @@
#include <gtest/gtest.h>
+#include "all.hpp"
+
#include "../poison.hpp"
+
+namespace tmwa
+{
template<typename T>
class StringTest : public ::testing::Test
{
@@ -32,10 +36,10 @@ TYPED_TEST_CASE_P(StringTest);
TYPED_TEST_P(StringTest, basic)
{
- TypeParam hi("Hello");
+ TypeParam hi("Hello"_s);
EXPECT_EQ(5, hi.size());
EXPECT_EQ(hi, hi);
- const char hi2[] = "Hello\0random garbage";
+ LString hi2 = "Hello\0random garbage"_s;
EXPECT_EQ(hi, hi2);
TypeParam hi0;
EXPECT_EQ(0, hi0.size());
@@ -47,9 +51,9 @@ TYPED_TEST_P(StringTest, basic)
TYPED_TEST_P(StringTest, order)
{
TypeParam a;
- TypeParam b("Hello");
- TypeParam c("Hello,");
- TypeParam d("World!");
+ TypeParam b("Hello"_s);
+ TypeParam c("Hello,"_s);
+ TypeParam d("World!"_s);
// not using EXPECT_LT, etc. for better visibility
@@ -158,7 +162,7 @@ TYPED_TEST_P(StringTest, order)
TYPED_TEST_P(StringTest, iterators)
{
- TypeParam hi("Hello");
+ TypeParam hi("Hello"_s);
EXPECT_EQ(hi.begin(), hi.begin());
EXPECT_NE(hi.begin(), hi.end());
EXPECT_EQ(5, std::distance(hi.begin(), hi.end()));
@@ -168,19 +172,19 @@ TYPED_TEST_P(StringTest, iterators)
TYPED_TEST_P(StringTest, xslice)
{
- TypeParam hi("Hello, World!");
- EXPECT_EQ(" World!", hi.xslice_t(6));
- EXPECT_EQ("Hello,", hi.xslice_h(6));
- EXPECT_EQ("World!", hi.xrslice_t(6));
- EXPECT_EQ("Hello, ", hi.xrslice_h(6));
+ TypeParam hi("Hello, World!"_s);
+ EXPECT_EQ(" World!"_s, hi.xslice_t(6));
+ EXPECT_EQ("Hello,"_s, hi.xslice_h(6));
+ EXPECT_EQ("World!"_s, hi.xrslice_t(6));
+ EXPECT_EQ("Hello, "_s, hi.xrslice_h(6));
typename TypeParam::iterator it = std::find(hi.begin(), hi.end(), ' ');
- EXPECT_EQ(" World!", hi.xislice_t(it));
- EXPECT_EQ("Hello,", hi.xislice_h(it));
- EXPECT_EQ("World", hi.xlslice(7, 5));
- EXPECT_EQ("World", hi.xpslice(7, 12));
- EXPECT_EQ("World", hi.xislice(hi.begin() + 7, hi.begin() + 12));
- EXPECT_TRUE(hi.startswith("Hello"));
- EXPECT_TRUE(hi.endswith("World!"));
+ EXPECT_EQ(" World!"_s, hi.xislice_t(it));
+ EXPECT_EQ("Hello,"_s, hi.xislice_h(it));
+ EXPECT_EQ("World"_s, hi.xlslice(7, 5));
+ EXPECT_EQ("World"_s, hi.xpslice(7, 12));
+ EXPECT_EQ("World"_s, hi.xislice(hi.begin() + 7, hi.begin() + 12));
+ EXPECT_TRUE(hi.startswith("Hello"_s));
+ EXPECT_TRUE(hi.endswith("World!"_s));
}
TYPED_TEST_P(StringTest, convert)
@@ -188,15 +192,15 @@ TYPED_TEST_P(StringTest, convert)
constexpr bool is_zstring = std::is_same<TypeParam, ZString>::value;
typedef typename std::conditional<is_zstring, TString, SString>::type Sstring;
typedef typename std::conditional<is_zstring, ZString, XString>::type Xstring;
- RString r = "r";
- AString a = "a";
- TString t = "t";
- Sstring s = "s";
- ZString z = "z";
- Xstring x = "x";
- VString<255> v = "v";
- const char l[] = "l";
- VString<5> hi = "hello";
+ RString r = "r"_s;
+ AString a = "a"_s;
+ TString t = "t"_s;
+ Sstring s = "s"_s;
+ ZString z = "z"_s;
+ Xstring x = "x"_s;
+ VString<255> v = "v"_s;
+ LString l = "l"_s;
+ VString<5> hi = "hello"_s;
TypeParam r2 = r;
TypeParam a2 = a;
@@ -270,7 +274,7 @@ INSTANTIATE_TYPED_TEST_CASE_P(StringStuff, StringTest, MostStringTypes);
TEST(VStringTest, basic)
{
- VString<5> hi = "Hello";
+ VString<5> hi = "Hello"_s;
EXPECT_EQ(5, hi.size());
EXPECT_EQ(hi, hi);
// truncation
@@ -278,7 +282,7 @@ TEST(VStringTest, basic)
EXPECT_EQ(5, hi2.size());
EXPECT_EQ(hi, hi2);
// short
- hi = "hi";
+ hi = "hi"_s;
EXPECT_EQ(2, hi.size());
VString<5> hi0;
EXPECT_EQ(0, hi0.size());
@@ -292,7 +296,7 @@ TYPED_TEST_CASE_P(NulStringTest);
TYPED_TEST_P(NulStringTest, basic)
{
- TypeParam hi("hello");
+ TypeParam hi("hello"_s);
EXPECT_EQ(hi.size(), strlen(hi.c_str()));
EXPECT_STREQ("hello", hi.c_str());
}
@@ -304,3 +308,4 @@ typedef ::testing::Types<
RString, AString, TString, ZString, VString<255>
> NulStringTypes;
INSTANTIATE_TYPED_TEST_CASE_P(NulStringStuff, NulStringTest, NulStringTypes);
+} // namespace tmwa
diff --git a/src/strings/tstring.cpp b/src/strings/tstring.cpp
index 5f463ca..b0bd74a 100644
--- a/src/strings/tstring.cpp
+++ b/src/strings/tstring.cpp
@@ -18,12 +18,18 @@
// 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 "rstring.hpp"
+#include "astring.hpp"
#include "sstring.hpp"
#include "zstring.hpp"
#include "xstring.hpp"
+#include "literal.hpp"
#include "../poison.hpp"
+
+namespace tmwa
+{
namespace strings
{
TString::TString()
@@ -67,6 +73,10 @@ namespace strings
else
*this = RString(x);
}
+ TString::TString(const LString& l)
+ {
+ *this = XString(l);
+ }
TString::TString(XPair p)
: _s(p), _o(0)
@@ -94,3 +104,4 @@ namespace strings
return ts.c_str();
}
} // namespace strings
+} // namespace tmwa
diff --git a/src/strings/tstring.hpp b/src/strings/tstring.hpp
index 7003d37..b0da566 100644
--- a/src/strings/tstring.hpp
+++ b/src/strings/tstring.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_STRINGS_TSTRING_HPP
-#define TMWA_STRINGS_TSTRING_HPP
+#pragma once
// strings/tstring.hpp - A tail slice of a string.
//
// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,11 +18,14 @@
// 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 "../sanity.hpp"
+#include "fwd.hpp"
-# include "base.hpp"
-# include "rstring.hpp"
+#include "base.hpp"
+#include "rstring.hpp"
+
+namespace tmwa
+{
namespace strings
{
/// An owning string that represents a tail slice of an RString.
@@ -43,10 +45,7 @@ namespace strings
TString(const XString&);
template<uint8_t n>
TString(const VString<n>& v);
- template<size_t n>
- TString(char (&s)[n]) = delete;
- template<size_t n>
- TString(const char (&s)[n]);
+ TString(const LString&);
//template<class It>
//TString(It b, It e) : _s(b, e), _o(0) {}
TString(XPair p);
@@ -63,7 +62,6 @@ namespace strings
// Actually, it might now.
const char *decay_for_printf(const TString& ts);
} // namespace strings
+} // namespace tmwa
-# include "tstring.tcc"
-
-#endif // TMWA_STRINGS_TSTRING_HPP
+#include "tstring.tcc"
diff --git a/src/strings/tstring.tcc b/src/strings/tstring.tcc
index 4eba13f..2641fb7 100644
--- a/src/strings/tstring.tcc
+++ b/src/strings/tstring.tcc
@@ -19,14 +19,14 @@
#include "vstring.hpp"
+
+namespace tmwa
+{
namespace strings
{
template<uint8_t n>
TString::TString(const VString<n>& v)
: _s(v), _o(0)
{}
- template<size_t n>
- TString::TString(const char (&s)[n])
- : _s(s), _o(0)
- {}
} // namespace strings
+} // namespace tmwa
diff --git a/src/strings/vstring.cpp b/src/strings/vstring.cpp
index 0ef8f3d..1cb313a 100644
--- a/src/strings/vstring.cpp
+++ b/src/strings/vstring.cpp
@@ -20,6 +20,10 @@
#include "../poison.hpp"
+
+namespace tmwa
+{
namespace strings
{
} // namespace strings
+} // namespace tmwa
diff --git a/src/strings/vstring.hpp b/src/strings/vstring.hpp
index 9952ff9..f3437a5 100644
--- a/src/strings/vstring.hpp
+++ b/src/strings/vstring.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_STRINGS_VSTRING_HPP
-#define TMWA_STRINGS_VSTRING_HPP
+#pragma once
// strings/vstring.hpp - A small string that stores its own value.
//
// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,10 +18,15 @@
// 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 "../sanity.hpp"
+#include "fwd.hpp"
-# include "base.hpp"
+#include <cstdio>
+#include "base.hpp"
+
+
+namespace tmwa
+{
namespace strings
{
template<uint8_t n>
@@ -40,10 +44,7 @@ namespace strings
VString(ZString z);
template<uint8_t m>
VString(VString<m> v);
- template<size_t m>
- VString(char (&s)[m]) = delete;
- template<size_t m>
- VString(const char (&s)[m]);
+ VString(LString l);
VString(decltype(really_construct_from_a_pointer) e, const char *s);
VString(char c);
VString();
@@ -74,7 +75,6 @@ T stringish(VString<sizeof(T) - 1> iv)
static_cast<VString<sizeof(T) - 1>&>(rv) = iv;
return rv;
}
+} // namespace tmwa
-# include "vstring.tcc"
-
-#endif // TMWA_STRINGS_VSTRING_HPP
+#include "vstring.tcc"
diff --git a/src/strings/vstring.py b/src/strings/vstring.py
index 39e657b..fa975b2 100644
--- a/src/strings/vstring.py
+++ b/src/strings/vstring.py
@@ -2,7 +2,7 @@ class VString(object):
''' print a VString
'''
__slots__ = ('_value')
- name = 'strings::VString'
+ name = 'tmwa::strings::VString'
enabled = True
def __init__(self, value):
diff --git a/src/strings/vstring.tcc b/src/strings/vstring.tcc
index 1aa163d..4f24a20 100644
--- a/src/strings/vstring.tcc
+++ b/src/strings/vstring.tcc
@@ -18,8 +18,8 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <cassert>
-
-#include "../compat/cast.hpp"
+#include <cstdarg>
+#include <cstdio>
#include "rstring.hpp"
#include "astring.hpp"
@@ -27,7 +27,11 @@
#include "sstring.hpp"
#include "zstring.hpp"
#include "xstring.hpp"
+#include "literal.hpp"
+
+namespace tmwa
+{
namespace strings
{
template<uint8_t n>
@@ -76,11 +80,9 @@ namespace strings
*this = XString(v);
}
template<uint8_t n>
- template<size_t m>
- VString<n>::VString(const char (&s)[m])
+ VString<n>::VString(LString l)
{
- static_assert(m <= n + 1, "string would truncate");
- *this = XString(s);
+ *this = XString(l);
}
template<uint8_t n>
VString<n>::VString(decltype(really_construct_from_a_pointer) e, const char *s)
@@ -143,7 +145,8 @@ namespace strings
char buffer[len + 1];
vsnprintf(buffer, len + 1, fmt, ap);
- out = const_(buffer);
+ out = VString<len>(strings::really_construct_from_a_pointer, buffer);
return len;
}
} // namespace strings
+} // namespace tmwa
diff --git a/src/strings/xstring.cpp b/src/strings/xstring.cpp
index 0808104..4635a90 100644
--- a/src/strings/xstring.cpp
+++ b/src/strings/xstring.cpp
@@ -18,8 +18,18 @@
// 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 "rstring.hpp"
+#include "astring.hpp"
+#include "tstring.hpp"
+#include "sstring.hpp"
+#include "zstring.hpp"
+#include "literal.hpp"
+
#include "../poison.hpp"
+
+namespace tmwa
+{
namespace strings
{
XString::XString()
@@ -40,6 +50,9 @@ namespace strings
XString::XString(const ZString& s)
: _b(&*s.begin()), _e(&*s.end()), _base(s.base())
{}
+ XString::XString(const LString& s)
+ : _b(&*s.begin()), _e(&*s.end()), _base(s.base())
+ {}
XString::XString(const char *b, const char *e, const RString *base_)
: _b(b), _e(e), _base(base_)
@@ -65,3 +78,4 @@ namespace strings
return _base;
}
} // namespace strings
+} // namespace tmwa
diff --git a/src/strings/xstring.hpp b/src/strings/xstring.hpp
index 8f6eac5..2b000c4 100644
--- a/src/strings/xstring.hpp
+++ b/src/strings/xstring.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_STRINGS_XSTRING_HPP
-#define TMWA_STRINGS_XSTRING_HPP
+#pragma once
// strings/xstring.hpp - A full borrowed slice.
//
// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,10 +18,13 @@
// 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 "../sanity.hpp"
+#include "fwd.hpp"
-# include "base.hpp"
+#include "base.hpp"
+
+namespace tmwa
+{
namespace strings
{
/// A non-owning string that is not guaranteed to be NUL-terminated.
@@ -44,10 +46,7 @@ namespace strings
XString(const ZString& s);
template<uint8_t n>
XString(const VString<n>& s);
- template<size_t n>
- XString(char (&s)[n]) = delete;
- template<size_t n>
- XString(const char (&s)[n]);
+ XString(const LString& s);
// mostly internal
XString(const char *b, const char *e, const RString *base_);
XString(decltype(really_construct_from_a_pointer) e, const char *s, const RString *base_);
@@ -58,7 +57,6 @@ namespace strings
const RString *base() const;
};
} // namespace strings
+} // namespace tmwa
-# include "xstring.tcc"
-
-#endif // TMWA_STRINGS_XSTRING_HPP
+#include "xstring.tcc"
diff --git a/src/strings/xstring.py b/src/strings/xstring.py
index 92cb78b..fa0abcb 100644
--- a/src/strings/xstring.py
+++ b/src/strings/xstring.py
@@ -2,7 +2,7 @@ class XString(object):
''' print a XString
'''
__slots__ = ('_value')
- name = 'strings::XString'
+ name = 'tmwa::strings::XString'
enabled = True
def __init__(self, value):
diff --git a/src/strings/xstring.tcc b/src/strings/xstring.tcc
index aee87f8..e9f0f1e 100644
--- a/src/strings/xstring.tcc
+++ b/src/strings/xstring.tcc
@@ -19,14 +19,14 @@
#include "vstring.hpp"
+
+namespace tmwa
+{
namespace strings
{
template<uint8_t n>
XString::XString(const VString<n>& s)
: _b(&*s.begin()), _e(&*s.end()), _base(nullptr)
{}
- template<size_t n>
- XString::XString(const char (&s)[n])
- : _b(s), _e(s + strlen(s)), _base(nullptr)
- {}
} // namespace strings
+} // namespace tmwa
diff --git a/src/strings/zstring.cpp b/src/strings/zstring.cpp
index e2a763f..01e9c2b 100644
--- a/src/strings/zstring.cpp
+++ b/src/strings/zstring.cpp
@@ -18,15 +18,24 @@
// 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 "xstring.hpp"
+#include <cstdio>
+#include <cstring>
+
+#include "rstring.hpp"
+#include "astring.hpp"
+#include "tstring.hpp"
+#include "literal.hpp"
#include "../poison.hpp"
+
+namespace tmwa
+{
namespace strings
{
ZString::ZString()
{
- *this = ZString("");
+ *this = ZString(""_s);
}
ZString::ZString(const RString& s)
: _b(&*s.begin()), _e(&*s.end()), _base(s.base())
@@ -37,6 +46,9 @@ namespace strings
ZString::ZString(const TString& s)
: _b(&*s.begin()), _e(&*s.end()), _base(s.base())
{}
+ ZString::ZString(const LString& s)
+ : _b(&*s.begin()), _e(&*s.end()), _base(s.base())
+ {}
ZString::ZString(const char *b, const char *e, const RString *base_)
: _b(b), _e(e), _base(base_)
{}
@@ -65,10 +77,5 @@ namespace strings
{
return zs.c_str();
}
-
- __attribute__((format(scanf, 2, 0)))
- int do_vscan(ZString in, const char *fmt, va_list ap)
- {
- return vsscanf(in.c_str(), fmt, ap);
- }
} // namespace strings
+} // namespace tmwa
diff --git a/src/strings/zstring.hpp b/src/strings/zstring.hpp
index 717da88..1e38662 100644
--- a/src/strings/zstring.hpp
+++ b/src/strings/zstring.hpp
@@ -1,5 +1,4 @@
-#ifndef TMWA_STRINGS_ZSTRING_HPP
-#define TMWA_STRINGS_ZSTRING_HPP
+#pragma once
// strings/zstring.hpp - A borrowed tail slice of a string.
//
// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
@@ -19,12 +18,13 @@
// 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 "../sanity.hpp"
+#include "fwd.hpp"
-# include <cstring>
+#include "base.hpp"
-# include "base.hpp"
+namespace tmwa
+{
namespace strings
{
/// A non-owning string that is guaranteed to be NUL-terminated.
@@ -45,13 +45,10 @@ namespace strings
ZString(const XString&) = delete;
template<uint8_t n>
ZString(const VString<n>& s);
+ ZString(const LString& s);
// dangerous
ZString(const char *b, const char *e, const RString *base_);
ZString(decltype(really_construct_from_a_pointer), const char *s, const RString *base_);
- template<size_t n>
- ZString(char (&s)[n]) = delete;
- template<size_t n>
- ZString(const char (&s)[n], const RString *base_=nullptr);
iterator begin() const;
iterator end() const;
@@ -64,11 +61,7 @@ namespace strings
// Nope, it doesn't, since there's a template
// Actually, it might now.
const char *decay_for_printf(const ZString& zs);
-
- __attribute__((format(scanf, 2, 0)))
- int do_vscan(ZString in, const char *fmt, va_list ap);
} // namespace strings
+} // namespace tmwa
-# include "zstring.tcc"
-
-#endif // TMWA_STRINGS_ZSTRING_HPP
+#include "zstring.tcc"
diff --git a/src/strings/zstring.py b/src/strings/zstring.py
index 5021e1c..dca5f4e 100644
--- a/src/strings/zstring.py
+++ b/src/strings/zstring.py
@@ -2,7 +2,7 @@ class ZString(object):
''' print a ZString
'''
__slots__ = ('_value')
- name = 'strings::ZString'
+ name = 'tmwa::strings::ZString'
enabled = True
def __init__(self, value):
diff --git a/src/strings/zstring.tcc b/src/strings/zstring.tcc
index fe0e9f3..2eaa8c0 100644
--- a/src/strings/zstring.tcc
+++ b/src/strings/zstring.tcc
@@ -17,19 +17,16 @@
// 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 <cstring>
-
#include "vstring.hpp"
+
+namespace tmwa
+{
namespace strings
{
template<uint8_t n>
ZString::ZString(const VString<n>& s)
: _b(&*s.begin()), _e(&*s.end()), _base(nullptr)
{}
-
- template<size_t n>
- ZString::ZString(const char (&s)[n], const RString *base_)
- : _b(s), _e(s + strlen(s)), _base(base_)
- {}
} // namespace strings
+} // namespace tmwa