Reference Manual

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

# utf-string.h

Go to the documentation of this file.

    00001 /*  Inti: Integrated Foundation Classes
    00002  *  Copyright (C) 2002 The Inti Development Team.
    00003  *
    00004  *  This program is free software; you can redistribute it and/or modify
    00005  *  it under the terms of the GNU General Public License as published by
    00006  *  the Free Software Foundation; either version 2 of the License, or
    00007  *  (at your option) any later version.
    00008  *
    00009  *  This program is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012  *  GNU Library General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU Library General Public License
    00015  *  along with this program; if not, write to the Free Software
    00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    00017  */
    00018
    00024
    00025 #ifndef INTI_UTF_STRING_H
    00026 #define INTI_UTF_STRING_H
    00027
    00028 #ifndef INTI_G_UNICODE_H
    00029 #include <inti/glib/unicode.h>
    00030 #endif
    00031
    00032 #ifndef _CPP_STRING
    00033 #include <string>
    00034 #endif
    00035
    00036 #ifndef _CPP_IOSFWD
    00037 #include <iosfwd>
    00038 #endif
    00039
    00040 namespace Inti {
    00041
    00042 namespace G {
    00043 class Error;
    00044 }
    00045
    00048
    00049 class StringIterator
    00050 {
    00051         StringIterator(const StringIterator&);
    00052         StringIterator& operator=(const StringIterator&);
    00053
    00054 protected:
    00055         char* pos_;
    00057
    00058         StringIterator();
    00060
    00061         StringIterator(const char *pos);
    00064
    00065 public:
    00066         G::Unichar operator*() const;
    00069
    00070         const char* base() const { return pos_; }
    00072 };
    00073
    00076
    00077 class Forward_StringIterator : public StringIterator
    00078 {
    00079 public:
    00082
    00083         Forward_StringIterator();
    00085
    00086         Forward_StringIterator(const char *pos);
    00089
    00090         Forward_StringIterator(const Forward_StringIterator& src);
    00093
    00094         Forward_StringIterator& operator=(const Forward_StringIterator& src);
    00097
    00101
    00102         Forward_StringIterator& operator++();
    00105
    00106         Forward_StringIterator operator++(int);
    00109
    00113
    00114         Forward_StringIterator& operator--();
    00117
    00118         Forward_StringIterator operator--(int);
    00121
    00123 };
    00124
    00127
    00128 class Reverse_StringIterator : public StringIterator
    00129 {
    00130 public:
    00133
    00134         Reverse_StringIterator();
    00136
    00137         Reverse_StringIterator(const char *pos);
    00140
    00141         Reverse_StringIterator(const Reverse_StringIterator& src);
    00144
    00145         Reverse_StringIterator& operator=(const Reverse_StringIterator& src);
    00148
    00152
    00153         Reverse_StringIterator& operator++();
    00156
    00157         Reverse_StringIterator operator++(int);
    00160
    00164
    00165         Reverse_StringIterator& operator--();
    00168
    00169         Reverse_StringIterator operator--(int);
    00172
    00174 };
    00175
    00190
    00191 class String
    00192 {
    00193         std::string string_;
    00194         mutable bool is_null;
    00195
    00196 public:
    00197         static const size_t npos = static_cast<size_t>(-1);
    00199
    00200         typedef const char* const_pointer;
    00202
    00203         typedef Forward_StringIterator iterator;
    00205
    00206         typedef Reverse_StringIterator reverse_iterator;
    00208
    00211
    00212         String();
    00216
    00217         String(const String& str);
    00222
    00223         String(const String& str, size_t char_pos, size_t n_chars = npos);
    00233
    00234         String(const std::string& str);
    00239
    00240         String(const std::string& str, size_t n_chars);
    00249
    00250         String(const char *s, size_t n_chars);
    00259
    00260         String(const char *s);
    00274
    00275         String(size_t n, char c);
    00282
    00283         String(size_t n, gunichar c);
    00290
    00291         String(const gunichar *s, int n_chars, G::Error *error = 0);
    00301
    00302         String(iterator first, iterator last);
    00309
    00313
    00314         const char* data() const { return string_.data(); }
    00316
    00317         G::Unichar get_char(size_t char_pos) const;
    00321
    00322         G::Unichar get_char_validated(size_t char_pos, size_t n_bytes = npos) const;
    00332
    00333         size_t index(size_t char_pos) const;
    00337
    00338         size_t offset(const_pointer p) const;
    00342
    00343         const_pointer pointer(size_t char_pos) const;
    00347
    00348         size_t length() const;
    00352
    00353         size_t size() const { return string_.size(); }
    00357
    00358         size_t max_size() const { return string_.max_size(); }
    00360
    00361         size_t capacity() const { return string_.capacity(); }
    00363
    00364         bool empty() const { return string_.empty(); }
    00366
    00367         bool null() const { return is_null ? (is_null = size() == 0) : false; }
    00369
    00370         const char* c_str() const { return null() ? (char*)0 : string_.c_str(); }
    00372
    00373         const std::string& str() const { return string_; }
    00376
    00377         G::Unichar at(size_t char_pos) const;
    00381
    00382         G::Unichar operator[](size_t char_pos) const;
    00386
    00390
    00391         static G::Unichar get_char(const_pointer p);
    00395
    00396         static G::Unichar get_char_validated(const_pointer p, size_t n_bytes);
    00406
    00410
    00411         iterator begin() const;
    00413
    00414         iterator end() const;
    00416
    00420
    00421         reverse_iterator rbegin() const;
    00423
    00424         reverse_iterator rend() const;
    00426
    00430
    00431         String& append(const String& str);
    00433
    00434         String& append(const String& str, size_t char_pos, size_t n_chars = npos);
    00436
    00437         String& append(const char *s, size_t n_chars);
    00439
    00440         String& append(const char *s);
    00442
    00443         String& append(size_t n, char c);
    00445
    00446         String& append(size_t n, gunichar c);
    00448
    00449         String& append(const gunichar *s, int n_chars, G::Error *error = 0);
    00452
    00453         String& append(iterator first, iterator last);
    00455
    00456         void push_back(char c);
    00458
    00459         void push_back(gunichar c);
    00461
    00462         String& operator+=(const String& str);
    00464
    00465         String& operator+=(const char *s);
    00467
    00468         String& operator+=(char c);
    00470
    00471         String& operator+=(gunichar c);
    00473
    00474         String& operator+=(const gunichar *s);
    00477
    00481
    00482         String& assign(const String& str);
    00484
    00485         String& assign(const String& str, size_t char_pos, size_t n_chars = npos);
    00487
    00488         String& assign(const char *s, size_t n_chars);
    00490
    00491         String& assign(const char *s);
    00493
    00494         String& assign(size_t n, char c);
    00496
    00497         String& assign(size_t n, gunichar c);
    00499
    00500         String& assign(const gunichar *s, int n_chars, G::Error *error = 0);
    00503
    00504         String& assign(iterator first, iterator last);
    00506
    00507         String& operator=(const String& str);
    00509
    00510         String& operator=(const char *s);
    00512
    00513         String& operator=(char c);
    00515
    00516         String& operator=(gunichar c);
    00518
    00525
    00526         int compare(const String& str) const;
    00528
    00529         int compare(size_t char_pos, size_t n_chars, const String& str) const;
    00531
    00532         int compare(size_t char_pos1, size_t n_chars1, const String& str, size_t char_pos2, size_t n_chars2) const;
    00535
    00536         int compare(const char *s) const;
    00538
    00539         int compare(size_t char_pos, size_t n_chars, const char *s) const;
    00542
    00543         int compare(size_t char_pos, size_t n_chars1, const char *s, size_t n_chars2) const;
    00546
    00551
    00552         size_t copy(char *s, size_t n_chars, size_t char_pos) const;
    00554
    00555         size_t copy(char *s, size_t n_chars) const;
    00557
    00558         size_t copy(gunichar **s, size_t n_bytes, iterator i, G::Error *error = 0) const;
    00561
    00562         size_t copy(gunichar2 **s, size_t n_bytes, iterator i, G::Error *error = 0) const;
    00565
    00570
    00571         String& erase();
    00573
    00574         String& erase(size_t char_pos, size_t n_chars = npos);
    00576
    00577         iterator erase(iterator i);
    00579
    00580         iterator erase(iterator first, iterator last);
    00582
    00586
    00587         static String format(const char *message_format, ...);
    00597
    00601
    00602         void insert(iterator i, size_t n, char c);
    00604
    00605         void insert(iterator i, size_t n, gunichar c);
    00608
    00609         void insert(iterator i, iterator first, iterator last);
    00611
    00612         String& insert(size_t char_pos, const String& str);
    00614
    00615         String& insert(size_t char_pos1, const String& str, size_t char_pos2, size_t n_chars = npos);
    00617
    00618         String& insert(size_t char_pos, const char *s, size_t n_chars);
    00620
    00621         String& insert(size_t char_pos, const char *s);
    00623
    00624         String& insert(size_t char_pos, size_t n, char c);
    00626
    00627         String& insert(size_t char_pos, size_t n, gunichar c);
    00629
    00630         String& insert(size_t char_pos, const gunichar *s, int n_chars, G::Error *error = 0);
    00633
    00634         String& insert(size_t char_pos, gunichar c);
    00636
    00637         iterator insert(iterator i, char c);
    00639
    00640         iterator insert(iterator i, gunichar c);
    00642
    00646
    00647         String& replace(size_t char_pos, size_t n_chars, const String& str);
    00649
    00650         String& replace(size_t char_pos1, size_t n_chars1, const String& str, size_t char_pos2, size_t n_chars2 = npos);
    00653
    00654         String& replace(size_t char_pos, size_t n_chars1, const char *s, size_t n_chars2);
    00657
    00658         String& replace(size_t char_pos, size_t n_chars, const char *s);
    00661
    00662         String& replace(size_t char_pos, size_t n_chars, size_t n, char c);
    00665
    00666         String& replace(size_t char_pos, size_t n_chars, size_t n, gunichar c);
    00669
    00670         String& replace(size_t char_pos, size_t n_chars, gunichar c);
    00673
    00674         String& replace(size_t char_pos, size_t n_chars1, const gunichar *s, int n_chars2, G::Error *error = 0);
    00677
    00678         String& replace(iterator first, iterator last, const String& str);
    00680
    00681         String& replace(iterator first, iterator last, const char *s, size_t n_chars);
    00683
    00684         String& replace(iterator first, iterator last, const char *s);
    00686
    00687         String& replace(iterator first, iterator last, size_t n, char c);
    00689
    00690         String& replace(iterator first, iterator last, gunichar c);
    00693
    00694         String& replace(iterator first1, iterator last1, iterator first2, iterator last2);
    00697
    00701
    00702         void resize(size_t n_bytes);
    00704
    00705         void reserve(size_t n_bytes = 0);
    00707
    00708         void clear();
    00710
    00716
    00717         size_t find(const char *s, size_t byte_pos, size_t n_chars) const;
    00719
    00720         size_t find(const String& str, size_t byte_pos = 0) const;
    00722
    00723         size_t find(const char *s, size_t byte_pos = 0) const;
    00725
    00726         size_t find(char c, size_t byte_pos = 0) const;
    00728
    00729         size_t find(gunichar c, size_t byte_pos = 0) const;
    00731
    00732         size_t rfind(const String& str, size_t byte_pos = npos) const;
    00734
    00735         size_t rfind(const char *s, size_t byte_pos, size_t n_chars) const;
    00738
    00739         size_t rfind(const char *s, size_t byte_pos = npos) const;
    00741
    00742         size_t rfind(char c, size_t byte_pos = npos) const;
    00744
    00745         size_t rfind(gunichar c, size_t byte_pos = npos) const;
    00747
    00748         size_t find_first_of(const String& str, size_t byte_pos = 0) const;
    00750
    00751         size_t find_first_of(const char *s, size_t byte_pos, size_t n_chars) const;
    00754
    00755         size_t find_first_of(const char *s, size_t byte_pos = 0) const;
    00757
    00758         size_t find_first_of(char c, size_t byte_pos = 0) const;
    00760
    00761         size_t find_first_of(gunichar c, size_t byte_pos = 0) const;
    00763
    00764         size_t find_last_of(const String& str, size_t byte_pos = npos) const;
    00766
    00767         size_t find_last_of(const char *s, size_t byte_pos, size_t n_chars) const;
    00770
    00771         size_t find_last_of(const char *s, size_t byte_pos = npos) const;
    00773
    00774         size_t find_last_of(char c, size_t byte_pos = npos) const;
    00777
    00778         size_t find_last_of(gunichar c, size_t byte_pos = npos) const;
    00781
    00782         size_t find_first_not_of(const String& str, size_t byte_pos = 0) const;
    00784
    00785         size_t find_first_not_of(const char *s, size_t byte_pos, size_t n_chars) const;
    00788
    00789         size_t find_first_not_of(const char *s, size_t byte_pos = 0) const;
    00791
    00792         size_t find_first_not_of(char c, size_t byte_pos = 0) const;
    00794
    00795         size_t find_first_not_of(gunichar c, size_t byte_pos = 0) const;
    00797
    00798         size_t find_last_not_of(const String& str, size_t byte_pos = npos) const;
    00800
    00801         size_t find_last_not_of(const char *s, size_t byte_pos, size_t n_chars) const;
    00804
    00805         size_t find_last_not_of(const char *s, size_t byte_pos = npos) const;
    00807
    00808         size_t find_last_not_of(char c, size_t byte_pos = npos) const;
    00811
    00812         size_t find_last_not_of(gunichar c, size_t byte_pos = npos) const;
    00815
    00819
    00820         String substr(size_t char_pos = 0, size_t n_chars = npos) const;
    00822
    00826
    00827         void swap(String& str);
    00829
    00833
    00834         String upper();
    00836
    00837         String upper(size_t char_pos, size_t n_bytes = npos);
    00839
    00840         String lower();
    00842
    00843         String lower(size_t char_pos, size_t n_bytes = npos);
    00845
    00846         String casefold(size_t n_bytes = npos);
    00857
    00861
    00862         String normalize(GNormalizeMode mode, size_t n_bytes = npos);
    00880
    00881         int collate(const String& str);
    00888
    00889         int collate_key(const String& str, size_t n_bytes = npos);
    00897
    00898         std::string convert(const char *to_codeset, G::Error *error = 0);
    00905
    00906         std::string convert_with_fallback(const char *to_codeset, G::Error *error = 0);
    00921
    00922         std::string convert_with_fallback(const char *to_codeset, const char *fallback, G::Error *error = 0);
    00938
    00939         std::string to_locale(G::Error *error = 0) const;
    00945
    00946         std::string to_filename(G::Error *error = 0) const;
    00952
    00956
    00957         static String from_locale(const std::string& opsysstring, G::Error *error = 0);
    00964
    00965         static String from_filename(const std::string& opsysstring, G::Error *error = 0);
    00972
    00976
    00977         static String convert(const std::string& str, const char *from_codeset, G::Error *error = 0);
    00985
    00986         static String convert_with_fallback(const std::string& str, const char *from_codeset, G::Error *error = 0);
    01002
    01003         static String convert_with_fallback(const std::string& str, const char *from_codeset, const char *fallback, G::Error *error = 0);
    01020
    01024
    01025         bool validate(size_t& byte_pos) const;
    01032
    01033         bool validate(const_pointer *end = 0) const;
    01040
    01042 };
    01043
    01046
    01047 std::istream& operator>>(std::istream& is, String& str);
    01049
    01050 std::ostream& operator<<(std::ostream& os, const String& str);
    01052
    01056
    01057 inline bool
    01058 operator==(const StringIterator& lhs, const StringIterator& rhs)
    01059 {
    01060         return lhs.base() == rhs.base();
    01061 }
    01063
    01064 inline bool
    01065 operator!=(const StringIterator& lhs, const StringIterator& rhs)
    01066 {
    01067         return !(lhs == rhs);
    01068 }
    01070
    01071 inline bool
    01072 operator<(const StringIterator& lhs, const StringIterator& rhs)
    01073 {
    01074         return lhs.base() < rhs.base();
    01075 }
    01077
    01078 inline bool
    01079 operator>(const StringIterator& lhs, const StringIterator& rhs)
    01080 {
    01081         return rhs < lhs;
    01082 }
    01084
    01085 inline bool
    01086 operator<=(const StringIterator& lhs, const StringIterator& rhs)
    01087 {
    01088         return !(rhs < lhs);
    01089 }
    01092
    01093 inline bool
    01094 operator>=(const StringIterator& lhs, const StringIterator& rhs)
    01095 {
    01096         return !(lhs < rhs);
    01097 }
    01100
    01104
    01105 inline String
    01106 operator+(const String& lhs, const String& rhs)
    01107 {
    01108         String str(lhs);
    01109         str.append(rhs);
    01110         return str;
    01111 }
    01113
    01114 inline String
    01115 operator+(const char *lhs, const String& rhs)
    01116 {
    01117         String str(lhs);
    01118         str.append(rhs);
    01119         return str;
    01120 }
    01122
    01123 inline String
    01124 operator+(char c, const String& rhs)
    01125 {
    01126         String str(1, c);
    01127         str.append(rhs);
    01128         return str;
    01129 }
    01131
    01132 inline String
    01133 operator+(const String& lhs, const char *rhs)
    01134 {
    01135         String str(lhs);
    01136         str.append(rhs);
    01137         return str;
    01138 }
    01140
    01141 inline String
    01142 operator+(const String& lhs, char c)
    01143 {
    01144         String str(lhs);
    01145         str.append(1, c);
    01146         return str;
    01147 }
    01149
    01153
    01154 inline bool
    01155 operator==(const String& lhs, const String& rhs)
    01156 {
    01157         return lhs.compare(rhs) == 0;
    01158 }
    01160
    01161 inline bool
    01162 operator==(const char *lhs, const String& rhs)
    01163 {
    01164         return rhs.compare(lhs) == 0;
    01165 }
    01167
    01168 inline bool
    01169 operator==(const String& lhs, const char *rhs)
    01170 {
    01171         return lhs.compare(rhs) == 0;
    01172 }
    01174
    01175 inline bool
    01176 operator!= (const char *lhs, const String& rhs)
    01177 {
    01178         return rhs.compare(lhs) != 0;
    01179 }
    01181
    01182 inline bool
    01183 operator!=(const String& lhs, const char *rhs)
    01184 {
    01185         return lhs.compare(rhs) != 0;
    01186 }
    01188
    01189 inline bool
    01190 operator<(const String& lhs, const String& rhs)
    01191 {
    01192         return lhs.compare(rhs) < 0;
    01193 }
    01195
    01196 inline bool
    01197 operator<(const char *lhs, const String& rhs)
    01198 {
    01199         return rhs.compare(lhs) > 0;
    01200 }
    01202
    01203 inline bool
    01204 operator<(const String& lhs, const char *rhs)
    01205 {
    01206         return lhs.compare (rhs) < 0;
    01207 }
    01209
    01210 inline bool
    01211 operator>(const char *lhs, const String& rhs)
    01212 {
    01213         return rhs.compare (lhs) < 0;
    01214 }
    01216
    01217 inline bool
    01218 operator>(const String& lhs, const char *rhs)
    01219 {
    01220         return lhs.compare(rhs) > 0;
    01221 }
    01223
    01224 inline bool
    01225 operator<=(const char *lhs, const String& rhs)
    01226 {
    01227         return rhs.compare(lhs) >= 0;
    01228 }
    01230
    01231 inline bool
    01232 operator<=(const String& lhs, const char *rhs)
    01233 {
    01234         return lhs.compare(rhs) <= 0;
    01235 }
    01237
    01238 inline bool
    01239 operator>=(const char *lhs, const String& rhs)
    01240 {
    01241         return rhs.compare(lhs) <= 0;
    01242 }
    01244
    01245 inline bool
    01246 operator>=(const String& lhs, const char *rhs)
    01247 {
    01248         return lhs.compare(rhs) >= 0;
    01249 }
    01251
    01252 inline bool
    01253 operator!=(const String& lhs, const String& rhs)
    01254 {
    01255         return lhs.compare(rhs) != 0;
    01256 }
    01258
    01259 inline bool
    01260 operator>(const String& lhs, const String& rhs)
    01261 {
    01262         return lhs.compare(rhs) > 0;
    01263 }
    01265
    01266 inline bool
    01267 operator<=(const String& lhs, const String& rhs)
    01268 {
    01269         return lhs.compare(rhs) <= 0;
    01270 }
    01272
    01273 inline bool
    01274 operator>=(const String& lhs, const String& rhs)
    01275 {
    01276         return lhs.compare(rhs) >= 0;
    01277 }
    01279
    01281
    01282 } // namespace Inti
    01283
    01284 #endif // INTI_UTF_STRING_H
    01285

Main Page - Footer