summaryrefslogtreecommitdiff
path: root/otk/ustring.cc
blob: be16bb1702a202bf0c0f654a34828770f47e6c37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-

#ifdef    HAVE_CONFIG_H
#  include "../config.h"
#endif // HAVE_CONFIG_H

#include "ustring.hh"

extern "C" {
#include <assert.h>
}

namespace otk {

ustring::ustring()
{
}

ustring::~ustring()
{
}

ustring::ustring(const ustring& other)
  : _string(other._string)
{
}

ustring& ustring::operator=(const ustring& other)
{
  _string = other._string;
  return *this;
}

ustring::ustring(const std::string& src)
  : _string(src)
{
}

ustring::ustring(const char* src)
  : _string(src)
{
}

static ustring::size_type find_offset(const char *str, const char *pos)
{
  ustring::size_type offset = 0;

  while (str < pos) {
    str += g_utf8_skip[*str];
    offset += g_utf8_skip[*str];
  }

  return offset;
}

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());
}

ustring::size_type ustring::bytes() const
{
  return _string.size();
}

ustring::size_type ustring::capacity() const
{
  return _string.capacity();
}

ustring::size_type ustring::max_size() const
{
  return _string.max_size();
}


const char* ustring::data() const
{
  return _string.data();
}

const char* ustring::c_str() const
{
  return _string.c_str();
}

}