File: shstring.cxx

package info (click to toggle)
latte 2.1-9
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,064 kB
  • ctags: 1,223
  • sloc: sh: 7,506; cpp: 5,831; ansic: 662; perl: 628; makefile: 350; yacc: 196; lisp: 114
file content (165 lines) | stat: -rw-r--r-- 3,314 bytes parent folder | download
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Copyright 1998 Zanshin Inc.                       <http://www.zanshin.com/>

// The contents of this file are subject to the Zanshin Public License Version
// 1.0 (the "License"); you may not use this file except in compliance with the
// License.  You should have received a copy of the License with Latte; see
// the file COPYING.  You may also obtain a copy of the License at
// <http://www.zanshin.com/ZPL.html>.
// 
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
// for the specific language governing rights and limitations under the
// License.
// 
// The Original Code is Latte.
// 
// The Initial Developer of the Original Code is Zanshin, Inc.

#include <shstring.h>
#include <iostream>
#include <cstring>

using namespace std;

shstring::shstring() : rep(0)
{
}

shstring::shstring(const char *str) : rep(new Rep(str))
{
  rep->inc_refcount();
}

shstring::shstring(const char *str, size_t n) : rep(new Rep(str, n))
{
  rep->inc_refcount();
}

shstring::shstring(const string &str) : rep(new Rep(str))
{
  rep->inc_refcount();
}

shstring::shstring(const shstring &other) : rep(other.rep)
{
  if (rep.get())
    rep->inc_refcount();
}

shstring::shstring(const shstring::const_iterator &b,
		   const shstring::const_iterator &e) : rep(new Rep(b, e))
{
  rep->inc_refcount();
}

shstring::~shstring()
{
  if (rep.get())
    rep->dec_refcount();
}

shstring &
shstring::operator = (const shstring &other)
{
  if (this != &other) {
    if (other.rep.get())
      other.rep->inc_refcount();
    if (rep.get())
      rep->dec_refcount();
    rep = other.rep;
  }
  return *this;
}

shstring::Rep::Rep(const char *s) : latte_string(s)
{
}

shstring::Rep::Rep(const char *s, size_t n) : latte_string(s, n)
{
}

shstring::Rep::Rep(const string &s) : latte_string(s)
{
}

shstring::Rep::Rep(const latte_string::const_iterator &b,
		   const latte_string::const_iterator &e) : latte_string(b, e)
{
}

ostream &
operator << (ostream &out, const shstring &s)
{
  if (s.rep.get())
    out << s.rep->str();
  return out;
}

bool
shstring::operator < (const shstring &other) const
{
  if (rep.get()) {
    if (other.rep.get())
      return rep->str() < other.rep->str();
    return 0;
  } else if (other.rep.get())
    return 1;
  else
    return 0;
}

bool
shstring::operator <= (const shstring &other) const
{
  if (rep.get()) {
    if (other.rep.get())
      return rep->str() <= other.rep->str();
    return 0;
  } else if (other.rep.get())
    return 1;
  else
    return 0;
}

bool
shstring::operator > (const shstring &other) const
{
  if (rep.get()) {
    if (other.rep.get())
      return rep->str() > other.rep->str();
    return 0;
  } else if (other.rep.get())
    return 0;
  else
    return 1;
}

bool
shstring::operator >= (const shstring &other) const
{
  if (rep.get()) {
    if (other.rep.get())
      return rep->str() >= other.rep->str();
    return 0;
  } else if (other.rep.get())
    return 0;
  else
    return 1;
}

bool
shstring::operator == (const shstring &other) const
{
  if (this == &other)
    return 1;

  if (rep.get()) {
    if (other.rep.get())
      return rep->str() == other.rep->str();
    return 0;
  } else if (other.rep.get())
    return 0;
  else
    return 1;
}