summaryrefslogtreecommitdiff
path: root/src/common/dumb_ptr.hpp
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2013-06-29 23:23:43 -0700
committerBen Longbons <b.r.longbons@gmail.com>2013-08-01 15:19:45 -0700
commit3b98f3439e33b15bba2036c402f9925340fdb2b9 (patch)
treef6a59330bb747d9cc64f5f83d06e7f76dc01d540 /src/common/dumb_ptr.hpp
parent8d1480c1be7c9741876d89008277a2b3629a4d01 (diff)
downloadtmwa-3b98f3439e33b15bba2036c402f9925340fdb2b9.tar.gz
tmwa-3b98f3439e33b15bba2036c402f9925340fdb2b9.tar.bz2
tmwa-3b98f3439e33b15bba2036c402f9925340fdb2b9.tar.xz
tmwa-3b98f3439e33b15bba2036c402f9925340fdb2b9.zip
Poison std::string and use the various string classes
Diffstat (limited to 'src/common/dumb_ptr.hpp')
-rw-r--r--src/common/dumb_ptr.hpp137
1 files changed, 14 insertions, 123 deletions
diff --git a/src/common/dumb_ptr.hpp b/src/common/dumb_ptr.hpp
index 8863ef2..fe5031a 100644
--- a/src/common/dumb_ptr.hpp
+++ b/src/common/dumb_ptr.hpp
@@ -202,25 +202,25 @@ struct dumb_string
{
return dumb_string::copy(sz, sz + strlen(sz));
}
- static dumb_string copys(const std::string& s)
+ static dumb_string copys(XString s)
{
return dumb_string::copy(&*s.begin(), &*s.end());
}
- static dumb_string copyn(const char *sn, size_t n)
+ static
+#ifndef __clang__
+ __attribute__((warning("shouldn't use this - slice instead")))
+#endif
+ dumb_string copyn(const char *sn, size_t n)
{
return dumb_string::copy(sn, sn + strnlen(sn, n));
}
- static dumb_string copyc(const_string s)
- {
- return dumb_string::copy(s.begin(), s.end());
- }
static
- dumb_string fake(const char *p)
+ dumb_string fake(ZString p)
{
dumb_string rv;
- size_t len = p ? strlen(p) : 0;
- rv.impl = dumb_ptr<char[]>(const_cast<char *>(p), len);
+ size_t len = p.size();
+ rv.impl = dumb_ptr<char[]>(const_cast<char *>(p.c_str()), len);
return rv;
}
@@ -235,17 +235,17 @@ struct dumb_string
const char *c_str() const
{
- return impl ? &impl[0] : "";
+ return &impl[0];
}
- std::string str() const
+ operator ZString() const
{
- return c_str();
+ return ZString(ZString::really_construct_from_a_pointer, c_str(), nullptr);
}
- operator const_string() const
+ FString str() const
{
- return const_string(c_str());
+ return ZString(*this);
}
char& operator[](size_t i) const
@@ -262,117 +262,8 @@ struct dumb_string
{
return !impl;
}
-
- operator ZString() { return ZString(ZString::really_construct_from_a_pointer, c_str()); }
-
-#if 0
- friend bool operator == (dumb_string l, dumb_string r)
- {
- return l.impl == r.impl;
- }
- friend bool operator != (dumb_string l, dumb_string r)
- {
- return !(l == r);
- }
-#endif
};
-namespace operators
-{
- inline
- bool operator == (dumb_string l, dumb_string r)
- {
- return strcmp(l.c_str(), r.c_str()) == 0;
- }
- inline
- bool operator != (dumb_string l, dumb_string r)
- {
- return strcmp(l.c_str(), r.c_str()) != 0;
- }
- inline
- bool operator < (dumb_string l, dumb_string r)
- {
- return strcmp(l.c_str(), r.c_str()) < 0;
- }
- inline
- bool operator <= (dumb_string l, dumb_string r)
- {
- return strcmp(l.c_str(), r.c_str()) <= 0;
- }
- inline
- bool operator > (dumb_string l, dumb_string r)
- {
- return strcmp(l.c_str(), r.c_str()) > 0;
- }
- inline
- bool operator >= (dumb_string l, dumb_string r)
- {
- return strcmp(l.c_str(), r.c_str()) >= 0;
- }
-
- inline
- bool operator == (const char *l, dumb_string r)
- {
- return strcmp(l, r.c_str()) == 0;
- }
- inline
- bool operator != (const char *l, dumb_string r)
- {
- return strcmp(l, r.c_str()) != 0;
- }
- inline
- bool operator < (const char *l, dumb_string r)
- {
- return strcmp(l, r.c_str()) < 0;
- }
- inline
- bool operator <= (const char *l, dumb_string r)
- {
- return strcmp(l, r.c_str()) <= 0;
- }
- inline
- bool operator > (const char *l, dumb_string r)
- {
- return strcmp(l, r.c_str()) > 0;
- }
- inline
- bool operator >= (const char *l, dumb_string r)
- {
- return strcmp(l, r.c_str()) >= 0;
- }
-
- inline
- bool operator == (dumb_string l, const char *r)
- {
- return strcmp(l.c_str(), r) == 0;
- }
- inline
- bool operator != (dumb_string l, const char *r)
- {
- return strcmp(l.c_str(), r) != 0;
- }
- inline
- bool operator < (dumb_string l, const char *r)
- {
- return strcmp(l.c_str(), r) < 0;
- }
- inline
- bool operator <= (dumb_string l, const char *r)
- {
- return strcmp(l.c_str(), r) <= 0;
- }
- inline
- bool operator > (dumb_string l, const char *r)
- {
- return strcmp(l.c_str(), r) > 0;
- }
- inline
- bool operator >= (dumb_string l, const char *r)
- {
- return strcmp(l.c_str(), r) >= 0;
- }
-}
-
inline
const char *convert_for_printf(dumb_string ds)
{