Update of /cvsroot/pclasses/pclasses2/src/Unicode
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25449/src/Unicode
Modified Files:
String.cpp
Log Message:
- Added generic StringList implementation
- Added more operations to Unicode::String
Index: String.cpp
===================================================================
RCS file: /cvsroot/pclasses/pclasses2/src/Unicode/String.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- String.cpp 26 Apr 2005 12:16:02 -0000 1.4
+++ String.cpp 28 Apr 2005 10:15:02 -0000 1.5
@@ -64,26 +64,27 @@
std::swap(b._str, _str);
}
+bool String::empty() const throw()
+{
+ return _str.empty();
+}
+
size_t String::size() const throw()
{
return _str.size();
}
String String::substr(size_t offset, size_t length) const
- throw(OutOfBounds)
{
- if(offset + length > _str.size())
- throw OutOfBounds("Offset and/or length is out of bounds", P_SOURCEINFO);
-
return _str.substr(offset, length);
}
-String String::left(size_t length) const throw(OutOfBounds)
+String String::left(size_t length) const
{
return substr(0, length);
}
-String String::right(size_t length) const throw(OutOfBounds)
+String String::right(size_t length) const
{
return substr(_str.size() - length, length);
}
@@ -94,14 +95,80 @@
return *this;
}
-const Char& String::at(size_t pos) const throw(OutOfBounds)
+String& String::append(const Char& ch)
{
- return operator[](pos);
+ _str.append(1, ch);
+ return *this;
}
-Char& String::at(size_t pos) throw(OutOfBounds)
+size_t String::find(const String& str, size_t pos) const
{
- return operator[](pos);
+ return _str.find(str._str, pos);
+}
+
+size_t String::find(const Char& ch, size_t pos) const
+{
+ return _str.find(ch, pos);
+}
+
+size_t String::rfind(const String& str, size_t pos) const
+{
+ return _str.rfind(str._str, pos);
+}
+
+size_t String::rfind(const Char& ch, size_t pos) const
+{
+ return _str.rfind(ch, pos);
+}
+
+size_t String::find_first_of(const String& str, size_t pos) const
+{
+ return _str.find_first_of(str._str, pos);
+}
+
+size_t String::find_first_of(const Char& ch, size_t pos) const
+{
+ return _str.find_first_of(ch, pos);
+}
+
+size_t String::find_first_not_of(const String& str, size_t pos) const
+{
+ return _str.find_first_not_of(str._str, pos);
+}
+
+size_t String::find_first_not_of(const Char& ch, size_t pos) const
+{
+ return _str.find_first_not_of(ch, pos);
+}
+
+size_t String::find_last_of(const String& str, size_t pos) const
+{
+ return _str.find_last_of(str._str, pos);
+}
+
+size_t String::find_last_of(const Char& ch, size_t pos) const
+{
+ return _str.find_last_of(ch, pos);
+}
+
+size_t String::find_last_not_of(const String& str, size_t pos) const
+{
+ return _str.find_last_not_of(str._str, pos);
+}
+
+size_t String::find_last_not_of(const Char& ch, size_t pos) const
+{
+ return _str.find_last_not_of(ch, pos);
+}
+
+const Char& String::at(size_t pos) const
+{
+ return at(pos);
+}
+
+Char& String::at(size_t pos)
+{
+ return at(pos);
}
std::string String::local() const
@@ -119,19 +186,13 @@
return toCharset("UTF8");
}
-const Char& String::operator[](size_t pos) const throw(OutOfBounds)
+const Char& String::operator[](size_t pos) const
{
- if(pos >= _str.size())
- throw OutOfBounds("Index is out of bounds", P_SOURCEINFO);
-
return (Char&)_str.operator[](pos);
}
-Char& String::operator[](size_t pos) throw(OutOfBounds)
+Char& String::operator[](size_t pos)
{
- if(pos >= _str.size())
- throw OutOfBounds("Index is out of bounds", P_SOURCEINFO);
-
return (Char&)_str.operator[](pos);
}
@@ -165,6 +226,12 @@
return *this;
}
+String& String::operator+=(const Char& ch)
+{
+ append(ch);
+ return *this;
+}
+
bool String::operator==(const String& str) const throw()
{
return _str == str._str;
@@ -310,6 +377,22 @@
return outstr;
}
+String operator+(const String& lhs, const String& rhs)
+{
+ return String(lhs).append(rhs);
+}
+
+String operator+(const String& lhs, const Char& rhs)
+{
+ return String(lhs).append(rhs);
+}
+
+std::ostream& operator<<(std::ostream& os, const String& str)
+{
+ os << str.utf8();
+ return os;
+}
+
} // !namespace Unicode
|