| 1 | // String.H -*- C++ -*- |
| 2 | // Copyright (c) 1997, 1998 Etienne BERNARD |
| 3 | // Copyright (c) 2002.2003,2005 Clinton Ebadi |
| 4 | |
| 5 | // This program is free software; you can redistribute it and/or modify |
| 6 | // it under the terms of the GNU General Public License as published by |
| 7 | // the Free Software Foundation; either version 2 of the License, or |
| 8 | // any later version. |
| 9 | |
| 10 | // This program is distributed in the hope that it will be useful, |
| 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | // GNU General Public License for more details. |
| 14 | |
| 15 | // You should have received a copy of the GNU General Public License |
| 16 | // along with this program; if not, write to the Free Software |
| 17 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
| 18 | |
| 19 | #ifndef BSTRING_H |
| 20 | #define BSTRING_H |
| 21 | |
| 22 | #include <iostream> |
| 23 | #include <string> |
| 24 | |
| 25 | class String { |
| 26 | |
| 27 | struct srep { |
| 28 | char *s; // pointer on the data |
| 29 | int n; // reference counter |
| 30 | srep() |
| 31 | { n = 1; } |
| 32 | }; |
| 33 | srep *p; |
| 34 | int len; |
| 35 | |
| 36 | public: |
| 37 | String(); |
| 38 | String(const char *); |
| 39 | String(const String &); |
| 40 | String(const std::string &); |
| 41 | String(long); |
| 42 | String(char); |
| 43 | |
| 44 | String & operator=(const char *); |
| 45 | String & operator=(const String &); |
| 46 | String & operator=(const std::string &); |
| 47 | |
| 48 | ~String(); |
| 49 | |
| 50 | int length() const; |
| 51 | int find(char); |
| 52 | void fill(char); |
| 53 | String pad(int); |
| 54 | |
| 55 | String subString(int); |
| 56 | String subString(int, int); |
| 57 | |
| 58 | String substr(int); |
| 59 | String substr(int, int); |
| 60 | |
| 61 | String toLower(); |
| 62 | String toUpper(); |
| 63 | String trim(); |
| 64 | int indexOf(char); |
| 65 | |
| 66 | char & operator[](int); |
| 67 | const char & operator[](int) const; |
| 68 | |
| 69 | bool operator==(const char *) const; |
| 70 | bool operator==(const String &) const; |
| 71 | bool operator==(const std::string &) const; |
| 72 | |
| 73 | bool operator!=(const char *) const; |
| 74 | bool operator!=(const String &) const; |
| 75 | bool operator!=(const std::string &) const; |
| 76 | |
| 77 | bool operator<(const String &) const; |
| 78 | bool operator>(const String &) const; |
| 79 | bool operator<(const std::string &) const; |
| 80 | |
| 81 | bool operator<=(const String &) const; |
| 82 | bool operator<=(const std::string &) const; |
| 83 | bool operator>=(const String &) const; |
| 84 | bool operator>=(const std::string &) const; |
| 85 | |
| 86 | String operator+(const char *); |
| 87 | String operator+(const String &); |
| 88 | String operator+(const std::string &); |
| 89 | |
| 90 | friend std::string operator+(const std::string &, const String &); |
| 91 | |
| 92 | operator const char *() const; |
| 93 | operator std::string () const; |
| 94 | |
| 95 | friend std::ostream & operator<<(std::ostream &, const String &); |
| 96 | friend std::istream & operator>>(std::istream &, String &); |
| 97 | }; |
| 98 | |
| 99 | bool operator==(const std::string &, const String &); |
| 100 | bool operator!=(const std::string &, const String &); |
| 101 | bool operator>(const std::string &, const String &); |
| 102 | bool operator<(const std::string &, const String &); |
| 103 | bool operator<=(const std::string &, const String &); |
| 104 | bool operator>=(const std::string &, const String &); |
| 105 | |
| 106 | #endif |