summaryrefslogtreecommitdiff
path: root/otk/ustring.cc
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2003-01-13 03:51:48 +0000
committerDana Jansens <danakj@orodu.net>2003-01-13 03:51:48 +0000
commit4947902d269213edee40f3f31f97721fa0dd3877 (patch)
treed8e2af6c768a7e62ebdc7ff55029d6f25ca88acb /otk/ustring.cc
parent2aff07a250930db7e0eb69dd6cd776333fcb8b9a (diff)
more conversion to ustring. added more members
Diffstat (limited to 'otk/ustring.cc')
-rw-r--r--otk/ustring.cc51
1 files changed, 39 insertions, 12 deletions
diff --git a/otk/ustring.cc b/otk/ustring.cc
index be16bb17..a04c08cf 100644
--- a/otk/ustring.cc
+++ b/otk/ustring.cc
@@ -21,27 +21,47 @@ ustring::~ustring()
}
ustring::ustring(const ustring& other)
- : _string(other._string)
+ : _string(other._string), _utf8(other._utf8)
{
}
ustring& ustring::operator=(const ustring& other)
{
_string = other._string;
+ _utf8 = other._utf8;
return *this;
}
ustring::ustring(const std::string& src)
- : _string(src)
+ : _string(src), _utf8(true)
{
}
ustring::ustring(const char* src)
- : _string(src)
+ : _string(src), _utf8(true)
{
}
-static ustring::size_type find_offset(const char *str, const char *pos)
+ustring& ustring::operator+=(const ustring& src)
+{
+ assert(_utf8 == src._utf8);
+ _string += src._string;
+ return *this;
+}
+
+ustring& ustring::operator+=(const char* src)
+{
+ _string += src;
+ return *this;
+}
+
+ustring& ustring::operator+=(char c)
+{
+ _string += c;
+ return *this;
+}
+
+static ustring::size_type find_utf8_offset(const char *str, const char *pos)
{
ustring::size_type offset = 0;
@@ -55,14 +75,11 @@ static ustring::size_type find_offset(const char *str, const char *pos)
ustring::size_type ustring::size() const
{
- const char *const pdata = _string.data();
- return find_offset(pdata, pdata + _string.size());
-}
-
-ustring::size_type ustring::length() const
-{
- const char *const pdata = _string.data();
- return find_offset(pdata, pdata + _string.size());
+ if (_utf8) {
+ const char *const pdata = _string.data();
+ return find_utf8_offset(pdata, pdata + _string.size());
+ } else
+ return _string.size();
}
ustring::size_type ustring::bytes() const
@@ -91,4 +108,14 @@ const char* ustring::c_str() const
return _string.c_str();
}
+bool ustring::utf8() const
+{
+ return _utf8;
+}
+
+void ustring::setUtf8(bool utf8)
+{
+ _utf8 = utf8;
+}
+
}