Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 1 | // Copyright (C) 2001 Open Source Telecom Corporation. |
| 2 | // |
| 3 | // This program is free software; you can redistribute it and/or modify |
| 4 | // it under the terms of the GNU General Public License as published by |
| 5 | // the Free Software Foundation; either version 2 of the License, or |
| 6 | // (at your option) any later version. |
| 7 | // |
| 8 | // This program is distributed in the hope that it will be useful, |
| 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | // GNU General Public License for more details. |
| 12 | // |
| 13 | // You should have received a copy of the GNU General Public License |
| 14 | // along with this program; if not, write to the Free Software |
| 15 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 16 | // |
| 17 | // As a special exception to the GNU General Public License, permission is |
| 18 | // granted for additional uses of the text contained in its release |
| 19 | // of Common C++. |
| 20 | // |
| 21 | // The exception is that, if you link the Common C++ library with other |
| 22 | // files to produce an executable, this does not by itself cause the |
| 23 | // resulting executable to be covered by the GNU General Public License. |
| 24 | // Your use of that executable is in no way restricted on account of |
| 25 | // linking the Common C++ library code into it. |
| 26 | // |
| 27 | // This exception does not however invalidate any other reasons why |
| 28 | // the executable file might be covered by the GNU General Public License. |
| 29 | // |
| 30 | // This exception applies only to the code released under the |
| 31 | // name Common C++. If you copy code from other releases into a copy of |
| 32 | // Common C++, as the General Public License permits, the exception does |
| 33 | // not apply to the code that you add in this way. To avoid misleading |
| 34 | // anyone as to the status of such modified files, you must delete |
| 35 | // this exception notice from them. |
| 36 | // |
| 37 | // If you write modifications of your own for Common C++, it is your choice |
| 38 | // whether to permit this exception to apply to your modifications. |
| 39 | // If you do not wish that, delete this exception notice. |
| 40 | |
| 41 | #include <cc++/common.h> |
| 42 | #include <iostream> |
| 43 | #include <cstdlib> |
| 44 | |
| 45 | #ifdef CCXX_NAMESPACES |
| 46 | using namespace std; |
| 47 | using namespace ost; |
| 48 | #endif |
| 49 | |
| 50 | String x; |
| 51 | |
| 52 | int main(int argc, char **argv) |
| 53 | { |
| 54 | String a("abc"); |
| 55 | String b(40, "abcdefghixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); |
| 56 | |
| 57 | printf("B %p\n", b.getText()); |
| 58 | |
| 59 | String mystring(65); |
| 60 | String *pstr; |
| 61 | |
| 62 | for(int i = 1; i < 20; ++i) { |
| 63 | pstr = new String(i, "abcdefg"); |
| 64 | String zstr(i, "abc"); |
| 65 | zstr = *pstr + zstr; |
| 66 | delete pstr; |
| 67 | zstr.clear(); |
| 68 | } |
| 69 | |
| 70 | const char *cp = a.index(1); |
| 71 | |
| 72 | printf("part of A %ld is %s\n", a.length(), cp); |
| 73 | |
| 74 | x = b; |
| 75 | printf("X %p %ld %s\n", x.getText(), x.getLength(), x.getText()); |
| 76 | |
| 77 | x = a; |
| 78 | printf("X %p %ld %ld %s\n", x.getText(), x.size(), x.length(), x.getText()); |
| 79 | x += b; |
| 80 | |
| 81 | printf("X %p %ld %ld %s\n", x.getText(), x.capacity(), x.length(), x.getText()); |
| 82 | x += a; |
| 83 | |
| 84 | printf("X %p %ld %ld %s\n", x.getText(), x.capacity(), x.length(), x.getText()); |
| 85 | x += "0123456789abcdefg"; |
| 86 | printf("X %p %ld %ld %s\n", x.getText(), x.capacity(), x.length(), x.getText()); |
| 87 | |
| 88 | |
| 89 | cout << "A = " << a << endl; |
| 90 | cout << "B = " << b << endl; |
| 91 | |
| 92 | |
| 93 | if(a > b) |
| 94 | printf("a > b\n"); |
| 95 | else |
| 96 | printf("a <= b\n"); |
| 97 | |
| 98 | if(a > "123") |
| 99 | printf("a > 123\n"); |
| 100 | else |
| 101 | printf("a < 123\n"); |
| 102 | |
| 103 | if(x *= "def") |
| 104 | printf("def contained in X\n"); |
| 105 | |
| 106 | if(!(x *= "zebra")) |
| 107 | printf("zebra not in X\n"); |
| 108 | |
| 109 | printf("X IS %p\n", x.getText()); |
| 110 | |
| 111 | b.erase(10,20); |
| 112 | cout << b.length() << " " << b << endl; |
| 113 | |
| 114 | printf("B IS %p\n", b.getText()); |
| 115 | |
| 116 | b.insert(3, "123456"); |
| 117 | cout << b << endl; |
| 118 | |
| 119 | cout << b.substr(5, 3) << endl; |
| 120 | |
| 121 | printf("find x %ld\n", b.find("x")); |
| 122 | printf("find 3rd x %ld\n", b.find(3, "x")); |
| 123 | |
| 124 | String l(",1,2222222222222222222222222222222,3"); |
| 125 | |
| 126 | cout << "list is " << l << endl; |
| 127 | cout << "first is empty" << l.token(",") << endl; |
| 128 | cout << l.token(",") << endl; |
| 129 | cout << l.token(",") << endl; |
| 130 | cout << "remaining " << l << endl; |
| 131 | cout << l.token(",") << endl; |
| 132 | cout << "final " << l << " size=" << l.capacity() << endl; |
| 133 | |
| 134 | String f; |
| 135 | |
| 136 | snprintf(f, 80, "testing %f done", 1.03); |
| 137 | cout << f << endl; |
| 138 | |
| 139 | String p1(20, "hello"); |
| 140 | String p2(20, "Count %d words", 10); |
| 141 | cout << p1 << endl; |
| 142 | cout << p2 << endl; |
| 143 | |
| 144 | SString ss; |
| 145 | |
| 146 | ss << "Counting " << 10 << " words"; |
| 147 | ss << " and more"; |
| 148 | cout << ss << endl; |
| 149 | ss << " and more"; |
| 150 | cout << ss << endl; |
| 151 | |
| 152 | String zip; |
| 153 | zip = ss; |
| 154 | cout << zip << endl; |
| 155 | String num; |
| 156 | #ifdef HAVE_SNPRINTF |
| 157 | num = 17; |
| 158 | num += 23; |
| 159 | cout << "number " << num << " should be 1723" << endl; |
| 160 | #endif |
| 161 | } |
| 162 | |