summaryrefslogtreecommitdiff
path: root/otk/ustring.hh
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2003-01-13 07:12:08 +0000
committerDana Jansens <danakj@orodu.net>2003-01-13 07:12:08 +0000
commit55f138186097931f3bf81618e36d2ad53e0c07fd (patch)
tree6eb2cd1018b8647a3c75cd97439f5e5bfb902b29 /otk/ustring.hh
parentef02a0c8ae65f169157c90064a335303e964a4c1 (diff)
ustring seems to be working! yay!
Diffstat (limited to 'otk/ustring.hh')
-rw-r--r--otk/ustring.hh46
1 files changed, 18 insertions, 28 deletions
diff --git a/otk/ustring.hh b/otk/ustring.hh
index 647bee86..d156528c 100644
--- a/otk/ustring.hh
+++ b/otk/ustring.hh
@@ -7,7 +7,7 @@
*/
extern "C" {
-/*
+
#ifdef HAVE_STDINT_H
# include <stdint.h>
#else
@@ -15,25 +15,25 @@ extern "C" {
# include <sys/types.h>
# endif
#endif
-*/
+
}
#include <string>
namespace otk {
-/*
+
#ifdef HAVE_STDINT_H
typedef uint32_t unichar;
#else
typedef u_int32_t unichar;
#endif
-*/
+
#ifndef DOXYGEN_IGNORE
//! The number of bytes to skip to find the next character in the string
-const char g_utf8_skip[256] = {
+const char utf8_skip[256] = {
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
@@ -44,6 +44,8 @@ const char g_utf8_skip[256] = {
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1
};
+unichar utf8_get_char(const char *p);
+
#endif // DOXYGEN_IGNORE
//! The iterator type for ustring
@@ -57,43 +59,26 @@ const char g_utf8_skip[256] = {
write operation would invalidate all other iterators pointing into the same
string.
*/
-/*
+
template <class T>
class ustring_Iterator
{
public:
typedef std::bidirectional_iterator_tag iterator_category;
- //typedef unichar value_type;
+ typedef unichar value_type;
typedef std::string::difference_type difference_type;
//typedef value_type reference;
typedef void pointer;
-
+
inline ustring_Iterator() {}
inline ustring_Iterator(const ustring_Iterator<std::string::iterator>&
other) : _pos(other.base()) {}
inline value_type operator*() const {
- // get a unicode character from the iterator's position
-
// get an iterator to the internal string
std::string::const_iterator pos = _pos;
-
- unichar result = static_cast<unsigned char>(*pos);
-
- // if its not a 7-bit ascii character
- if((result & 0x80) != 0) {
- // len is the number of bytes this character takes up in the string
- unsigned char len = g_utf8_skip[result];
- result &= 0x7F >> len;
-
- while(--len != 0) {
- result <<= 6;
- result |= static_cast<unsigned char>(*++pos) & 0x3F;
- }
- }
-
- return result;
+ return utf8_get_char(&(*pos));
}
@@ -112,7 +97,7 @@ public:
private:
T _pos;
};
-*/
+
//! This class provides a simple wrapper to a std::string that can be encoded
//! as UTF-8. The ustring::utf() member specifies if the given string is UTF-8
@@ -135,7 +120,7 @@ public:
typedef std::string::size_type size_type;
typedef std::string::difference_type difference_type;
- //typedef unichar value_type;
+ typedef unichar value_type;
//typedef unichar & reference;
//typedef const unichar & const_reference;
@@ -176,7 +161,12 @@ public:
// change the string's size
void resize(size_type n, char c='\0');
+
+ // extract characters
+ // No reference return; use replace() to write characters.
+ value_type operator[](size_type i) const;
+
// internal data
const char* data() const;