00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef CASA_STRING_H
00029 #define CASA_STRING_H
00030
00031
00032 #include <casa/aips.h>
00033
00034
00035 #include <string>
00036
00037 using std::string;
00038
00039 #include <casa/iosstrfwd.h>
00040 #include <casa/sstream.h>
00041
00042 namespace casa {
00043
00044
00045 class String;
00046 class RegexBase;
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 class SubString {
00062 public:
00063
00064 friend class String;
00065
00066 operator const string() const { return string(ref_p, pos_p, len_p); }
00067
00068
00069 SubString &operator=(const SubString &str);
00070 SubString &operator=(const String &str);
00071 SubString &operator=(const Char *s);
00072 SubString &operator=(const Char c);
00073
00074
00075 const Char *chars() const;
00076
00077 string::size_type length() const { return len_p; }
00078
00079 private:
00080
00081
00082 SubString(const string &str, string::size_type pos,
00083 string::size_type len);
00084
00085
00086 const string &ref_p;
00087
00088 string::size_type pos_p;
00089
00090 string::size_type len_p;
00091 };
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 class String : public string {
00224
00225 public:
00226
00227
00228 typedef string::traits_type traits_type;
00229 typedef string::value_type value_type;
00230 typedef string::allocator_type allocator_type;
00231 typedef string::size_type size_type;
00232 typedef string::difference_type difference_type;
00233
00234 typedef string::reference reference;
00235 typedef string::const_reference const_reference;
00236 typedef string::pointer pointer;
00237 typedef string::const_pointer const_pointer;
00238
00239 typedef string::iterator iterator;
00240 typedef string::const_iterator const_iterator;
00241 typedef string::reverse_iterator reverse_iterator;
00242 typedef string::const_reverse_iterator const_reverse_iterator;
00243
00244 static const size_type npos = static_cast<size_type>(-1);
00245
00246
00247
00248 String() : string("") {}
00249
00250
00251
00252
00253
00254 String(const string& str, size_type pos=0, size_type n=npos) :
00255 string(str, pos, n) {}
00256
00257
00258
00259
00260 String(const Char* s, size_type n) : string(s, n) {}
00261
00262 String(const Char* s) : string(s) {}
00263
00264
00265
00266
00267 String(size_type n, Char c) : string(n, c) {}
00268
00269 template<class InputIterator>
00270 String(InputIterator begin, InputIterator end) : string(begin, end) {}
00271
00272
00273
00274
00275 explicit String(Char c) : string(1, c) {}
00276
00277 String(const SubString &str) : string(str.ref_p, str.pos_p, str.len_p) {}
00278
00279 String(ostringstream &os);
00280
00281
00282
00283 ~String() {}
00284
00285
00286
00287
00288 String& operator=(const string& str) {
00289 return static_cast<String&>(string::operator=(str)); }
00290 String& operator=(const SubString &str) {
00291 return (*this = String(str)); }
00292 String& operator=(const Char* s) {
00293 return static_cast<String&>(string::operator=(s)); }
00294 String& operator=(Char c) {
00295 return static_cast<String&>(string::operator=(c)); }
00296
00297
00298 SubString operator()(size_type pos, size_type len);
00299
00300
00301 String& operator+=(const string& str) {
00302 return static_cast<String&>(string::operator+=(str)); }
00303 String& operator+=(const Char* s) {
00304 return static_cast<String&>(string::operator+=(s)); }
00305 String& operator+=(Char c) {
00306 return static_cast<String&>(string::operator+=(c)); }
00307
00308
00309
00310
00311
00312
00313
00314 const_reference operator[](size_type pos) const {
00315 return string::at(pos); }
00316 reference operator[](size_type pos) {
00317 return string::operator[](pos); }
00318
00319
00320 const_reference elem(size_type pos) const {
00321 return string::at(pos); }
00322 Char firstchar() const { return at(static_cast<size_type>(0)); }
00323 Char lastchar() const { return at(length()-1); }
00324
00325
00326
00327
00328
00329
00330 iterator begin() { return string::begin(); }
00331 const_iterator begin() const { return string::begin(); }
00332 iterator end() { return string::end(); }
00333 const_iterator end() const { return string::end(); }
00334 reverse_iterator rbegin() { return string::rbegin(); }
00335 const_reverse_iterator rbegin() const { return string::rbegin(); }
00336 reverse_iterator rend() { return string::rend(); }
00337 const_reverse_iterator rend() const { return string::rend(); }
00338
00339
00340
00341
00342 size_type size() const { return string::size(); }
00343 size_type length() const { return string::length(); }
00344 size_type max_size() const { return string::max_size(); }
00345 size_type capacity() const { return string::capacity(); }
00346
00347 Int allocation() const { return string::capacity(); }
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359 String& resize(size_type n) {
00360 string::resize(n); return *this; }
00361 String& resize(size_type n, Char c) {
00362 string::resize(n, c); return *this; }
00363 String& reserve(size_type res_arg = 0) {
00364 string::reserve(res_arg); return *this; }
00365
00366 void alloc(size_type n) { string::resize(n); }
00367
00368
00369
00370
00371
00372 void clear() { string::erase(begin(), end()); }
00373
00374
00375 Bool empty() const { return string::empty(); }
00376
00377
00378
00379
00380
00381
00382 const_reference at(size_type n) const { return string::at(n); }
00383 reference at(size_type n) { return string::at(n); }
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396 String& append(const string& str) {
00397 return static_cast<String&>(string::append(str)); }
00398 String& append(const string& str, size_type pos, size_type n) {
00399 return static_cast<String&>(string::append(str, pos, n)); }
00400 String& append(const Char* s, size_type n) {
00401 return static_cast<String&>(string::append(s, n)); }
00402 String& append(const Char* s) {
00403 return static_cast<String&>(string::append(s)); }
00404 String& append(size_type n, Char c) {
00405 return static_cast<String&>(string::append(n, c)); }
00406 template<class InputIterator>
00407 String& append(InputIterator first, InputIterator last) {
00408 return static_cast<String&>(string::append(first, last)); }
00409
00410 String& append(Char c) {
00411 return static_cast<String&>(string::append(1, c)); }
00412
00413
00414
00415
00416
00417
00418
00419 String& assign(const string& str) {
00420 return static_cast<String&>(string::assign(str)); }
00421 String& assign(const string& str, size_type pos, size_type n) {
00422 return static_cast<String&>(string::assign(str, pos, n)); }
00423 String& assign(const Char* s, size_type n) {
00424 return static_cast<String&>(string::assign(s, n)); }
00425 String& assign(const Char* s) {
00426 return static_cast<String&>(string::assign(s)); }
00427 String& assign(size_type n, Char c) {
00428 return static_cast<String&>(string::assign(n, c)); }
00429 template<class InputIterator>
00430 String& assign(InputIterator first, InputIterator last) {
00431 return static_cast<String&>(string::assign(first, last)); }
00432
00433 String& assign(Char c) {
00434 return static_cast<String&>(string::assign(1, c)); }
00435
00436
00437
00438
00439
00440
00441
00442
00443 String& insert(size_type pos1, const string& str) {
00444 return static_cast<String&>(string::insert(pos1, str)); }
00445 String& insert(size_type pos1, const string& str,
00446 size_type pos2, size_type n) {
00447 return static_cast<String&>(string::insert(pos1, str, pos2, n)); }
00448 String& insert(size_type pos, const Char* s, size_type n) {
00449 return static_cast<String&>(string::insert(pos, s, n)); }
00450 String& insert(size_type pos, const Char* s) {
00451 return static_cast<String&>(string::insert(pos, s)); }
00452 String& insert(size_type pos, size_type n, Char c) {
00453 return static_cast<String&>(string::insert(pos, n, c)); }
00454
00455 String& insert(size_type pos, Char c) {
00456 return static_cast<String&>(string::insert(pos, 1, c)); }
00457
00458 iterator insert(iterator p, Char c) {
00459 return string::insert(p, c); }
00460 void insert(iterator p, size_type n, Char c) {
00461 string::insert(p, n, c); }
00462 template<class InputIterator>
00463 void insert(iterator p, InputIterator first, InputIterator last) {
00464 string::insert(p, first, last); }
00465
00466
00467 String& insert(iterator p, const string& str) {
00468 return static_cast<String&>(string::insert(p-begin(), str)); }
00469 String& insert(iterator p, const Char* s, size_type n) {
00470 return static_cast<String&>(string::insert(p-begin(), s, n)); }
00471 String& insert(iterator p, const Char* s) {
00472 return static_cast<String&>(string::insert(p-begin(), s)); }
00473
00474
00475
00476
00477
00478
00479
00480
00481 Int compare(const string& str) const {
00482 return string::compare(str); }
00483 Int compare(size_type pos1, size_type n1, const string& str) const {
00484 return String(*this, pos1, n1).compare(str); }
00485 Int compare(size_type pos1, size_type n1, const string& str,
00486 size_type pos2, size_type n2) const {
00487 return String(*this, pos1, n1).compare(String(str, pos2, n2)); }
00488 Int compare(const Char* s) const {
00489 return string::compare(s); }
00490 Int compare(size_type pos1, size_type n1, const Char* s,
00491 size_type n2=npos) const {
00492 return String(*this, pos1, n1).compare(String(s, n2)); }
00493
00494
00495
00496
00497 String& erase(size_type pos, size_type n = npos) {
00498 return static_cast<String&>(string::erase(pos, n)); }
00499 iterator erase(iterator position) {
00500 return string::erase(position); }
00501 iterator erase(iterator first, iterator last) {
00502 return string::erase(first, last); }
00503
00504
00505
00506
00507
00508
00509
00510
00511 String& replace(size_type pos1, size_type n1, const string& str) {
00512 return static_cast<String&>(string::replace(pos1, n1, str)); }
00513 String& replace(size_type pos1, size_type n1, const string& str,
00514 size_type pos2, size_type n2) {
00515 return static_cast<String&>(string::replace(pos1, n1, str, pos2, n2)); }
00516 String& replace(size_type pos, size_type n1, const Char* s, size_type n2) {
00517 return static_cast<String&>(string::replace(pos, n1, s, n2)); }
00518 String& replace(size_type pos, size_type n1, const Char* s) {
00519 return static_cast<String&>(string::replace(pos, n1, s)); }
00520 String& replace(size_type pos, size_type n1, size_type n2, Char c) {
00521 return static_cast<String&>(string::replace(pos, n1, n2, c)); }
00522
00523 String& replace(size_type pos, size_type n1, Char c) {
00524 return static_cast<String&>(string::replace(pos, n1, 1, c)); }
00525 String& replace(iterator i1, iterator i2, const string& str) {
00526 return static_cast<String&>(string::replace(i1, i2, str)); }
00527 String& replace(iterator i1, iterator i2, const Char* s, size_type n) {
00528 return static_cast<String&>(string::replace(i1, i2, s, n)); }
00529 String& replace(iterator i1, iterator i2, const Char* s) {
00530 return static_cast<String&>(string::replace(i1, i2, s)); }
00531 String& replace(iterator i1, iterator i2, size_type n, Char c) {
00532 return static_cast<String&>(string::replace(i1, i2, n, c)); }
00533
00534 String& replace(iterator i1, iterator i2, Char c) {
00535 return static_cast<String&>(string::replace(i1, i2, 1, c)); }
00536 template<class InputIterator>
00537 String& replace(iterator i1, iterator i2, InputIterator j1,
00538 InputIterator j2) {
00539 return static_cast<String&>(string::replace(i1, i2, j1, j2)); }
00540
00541
00542
00543
00544
00545
00546 size_type copy(Char* s, size_type n, size_type pos = 0) const {
00547 return string::copy(s, n, pos); }
00548
00549
00550 void swap(string& s) { string::swap(s); }
00551
00552
00553
00554
00555 const Char *c_str() const { return string::c_str(); }
00556
00557 const Char *data() const { return string::data(); }
00558
00559 const Char *chars() const { return string::c_str(); }
00560
00561
00562
00563
00564 allocator_type get_allocator() const { return string::allocator_type(); }
00565
00566
00567
00568
00569
00570 String substr(size_type pos=0, size_type n=npos) const {
00571 return String(*this, pos, n); }
00572
00573
00574
00575
00576 size_type find(const string &str, size_type pos=0) const {
00577 return string::find(str, pos); }
00578 size_type find(const Char *s, size_type pos=0) const {
00579 return string::find(s, pos); }
00580 size_type find(const Char *s, size_type pos, size_type n) const {
00581 return string::find(s, pos, n); }
00582 size_type find(Char c, size_type pos=0) const {
00583 return string::find(c, pos); }
00584 size_type find(const RegexBase &r, size_type pos=0) const;
00585 size_type rfind(const string &str, size_type pos=0) const {
00586 return string::find(str, pos); }
00587 size_type rfind(const Char *s, size_type pos=0) const {
00588 return string::rfind(s, pos); }
00589 size_type rfind(const Char *s, size_type pos, size_type n) const {
00590 return string::rfind(s, pos, n); }
00591 size_type rfind(Char c, size_type pos=0) const {
00592 return string::rfind(c, pos); }
00593 size_type rfind(const RegexBase &r, size_type pos=0) const;
00594 size_type find_first_of(const string &str, size_type pos=0) const {
00595 return string::find_first_of(str, pos); }
00596 size_type find_first_of(const Char *s, size_type pos=0) const {
00597 return string::find_first_of(s, pos); }
00598 size_type find_first_of(const Char *s, size_type pos, size_type n) const {
00599 return string::find_first_of(s, pos, n); }
00600 size_type find_first_of(Char c, size_type pos=0) const {
00601 return string::find_first_of(c, pos); }
00602 size_type find_last_of(const string &str, size_type pos=0) const {
00603 return string::find_last_of(str, pos); }
00604 size_type find_last_of(const Char *s, size_type pos=0) const {
00605 return string::find_last_of(s, pos); }
00606 size_type find_last_of(const Char *s, size_type pos, size_type n) const {
00607 return string::find_last_of(s, pos, n); }
00608 size_type find_last_of(Char c, size_type pos=0) const {
00609 return string::find_last_of(c, pos); }
00610 size_type find_first_not_of(const string &str, size_type pos=0) const {
00611 return string::find_first_not_of(str, pos); }
00612 size_type find_first_not_of(const Char *s, size_type pos=0) const {
00613 return string::find_first_not_of(s, pos); }
00614 size_type find_first_not_of(const Char *s, size_type pos, size_type n) const {
00615 return string::find_first_not_of(s, pos, n); }
00616 size_type find_first_not_of(Char c, size_type pos=0) const {
00617 return string::find_first_not_of(c, pos); }
00618 size_type find_last_not_of(const string &str, size_type pos=0) const {
00619 return string::find_last_not_of(str, pos); }
00620 size_type find_last_not_of(const Char *s, size_type pos=0) const {
00621 return string::find_last_not_of(s, pos); }
00622 size_type find_last_not_of(const Char *s, size_type pos, size_type n) const {
00623 return string::find_last_not_of(s, pos, n); }
00624 size_type find_last_not_of(Char c, size_type pos=0) const {
00625 return string::find_last_not_of(c, pos); }
00626
00627
00628
00629
00630 Bool contains(Char c) const {
00631 return (find(c) != npos); }
00632 Bool contains(const string &str) const {
00633 return (find(str) != npos); }
00634 Bool contains(const Char *s) const {
00635 return (find(s) != npos); }
00636 Bool contains(const RegexBase &r) const;
00637
00638
00639
00640 Bool contains(Char c, Int pos) const;
00641 Bool contains(const string &str, Int pos) const;
00642 Bool contains(const Char *s, Int pos) const;
00643 Bool contains(const RegexBase &r, Int pos) const;
00644
00645
00646
00647
00648
00649 Bool matches(const string &str, Int pos = 0) const;
00650 Bool matches(Char c, Int pos = 0) const {
00651 return matches(String(c), pos); };
00652 Bool matches(const Char *s, Int pos = 0) const {
00653 return matches(String(s), pos); };
00654 Bool matches(const RegexBase &r, Int pos = 0) const;
00655
00656
00657
00658
00659 void prepend(const string &str);
00660 void prepend(const Char *s);
00661 void prepend(Char c);
00662
00663
00664
00665
00666
00667 size_type index(Char c, Int startpos = 0) const {
00668 return ((startpos >= 0) ? find(c, startpos) :
00669 rfind(c, length() + startpos - 1)); }
00670 size_type index(const string &str, Int startpos = 0) const {
00671 return ((startpos >= 0) ? find(str, startpos) :
00672 rfind(str, length() + startpos - str.length())); }
00673 size_type index(const Char *s, Int startpos = 0) const {
00674 return ((startpos >= 0) ? find(s, startpos) :
00675 rfind(s, length() + startpos - traits_type::length(s))); }
00676 size_type index(const RegexBase &r, Int startpos = 0) const;
00677
00678
00679
00680
00681 Int freq(Char c) const;
00682 Int freq(const string &str) const;
00683 Int freq(const Char *s) const;
00684
00685
00686
00687
00688 SubString at(size_type pos, size_type len);
00689 String at(size_type pos, size_type len) const {
00690 return String(*this, pos, len); }
00691 SubString at(const string &str, Int startpos = 0);
00692 String at(const string &str, Int startpos = 0) const;
00693 SubString at(const Char *s, Int startpos = 0);
00694 String at(const Char *s, Int startpos = 0) const;
00695 SubString at(Char c, Int startpos = 0);
00696 String at(Char c, Int startpos = 0) const;
00697 SubString at(const RegexBase &r, Int startpos = 0);
00698 String at(const RegexBase &r, Int startpos = 0) const;
00699
00700
00701
00702
00703 SubString at(Int pos, Int len) {
00704 return at(static_cast<size_type>(pos), static_cast<size_type>(len));
00705 };
00706 String at(Int pos, Int len) const {
00707 return at(static_cast<size_type>(pos), static_cast<size_type>(len));
00708 };
00709 SubString at(Int pos, size_type len) {
00710 return at(static_cast<size_type>(pos), len);
00711 };
00712 String at(Int pos, size_type len) const {
00713 return at(static_cast<size_type>(pos), len);
00714 };
00715
00716
00717
00718
00719
00720
00721 SubString before(size_type pos);
00722 SubString before(const string &str, Int startpos = 0);
00723 SubString before(const Char *s, Int startpos = 0);
00724 SubString before(Char c, Int startpos = 0);
00725 SubString before(const RegexBase &r, Int startpos = 0);
00726
00727 SubString before(Int pos) {
00728 return before(static_cast<size_type>(pos)); };
00729
00730
00731
00732
00733
00734 SubString through(size_type pos);
00735 SubString through(const string &str, Int startpos = 0);
00736 SubString through(const Char *s, Int startpos = 0);
00737 SubString through(Char c, Int startpos = 0);
00738 SubString through(const RegexBase &r, Int startpos = 0);
00739
00740 SubString through(Int pos) {
00741 return through(static_cast<size_type>(pos)); }
00742
00743
00744
00745
00746
00747 SubString from(size_type pos);
00748 SubString from(const string &str, Int startpos = 0);
00749 SubString from(const Char *s, Int startpos = 0);
00750 SubString from(Char c, Int startpos = 0);
00751 SubString from(const RegexBase &r, Int startpos = 0);
00752
00753 SubString from(Int pos) {
00754 return from(static_cast<size_type>(pos));
00755 };
00756
00757
00758
00759
00760
00761 SubString after(size_type pos);
00762 SubString after(const string &str, Int startpos = 0);
00763 SubString after(const Char *s, Int startpos = 0);
00764 SubString after(Char c, Int startpos = 0);
00765 SubString after(const RegexBase &r, Int startpos = 0);
00766
00767 SubString after(Int pos) {
00768 return after(static_cast<size_type>(pos));
00769 };
00770
00771
00772
00773
00774
00775 void reverse();
00776
00777 void capitalize();
00778
00779 void upcase();
00780
00781 void downcase();
00782
00783
00784
00785 void del(size_type pos, size_type len);
00786
00787
00788
00789 void del(const string &str, size_type startpos = 0);
00790 void del(const Char *s, size_type startpos = 0);
00791 void del(Char c, size_type startpos = 0);
00792 void del(const RegexBase &r, size_type startpos = 0);
00793
00794 void del(Int pos, Int len) {
00795 del(static_cast<size_type>(pos), static_cast<size_type>(len)); }
00796
00797
00798
00799
00800
00801
00802 Int gsub(const string &pat, const string &repl);
00803 Int gsub(const Char *pat, const string &repl);
00804 Int gsub(const Char *pat, const Char *repl);
00805 Int gsub(const RegexBase &pat, const string &repl);
00806
00807
00808
00809
00810
00811
00812 static String toString(Int value);
00813 static String toString(uInt value);
00814 static String toString(Double value);
00815
00816
00817 private:
00818
00819
00820 SubString _substr(size_type first, size_type l) {
00821 return SubString(*this, first, l); }
00822
00823 };
00824
00825
00826
00827
00828
00829
00830
00831 inline String operator+(const String &lhs, const String &rhs) {
00832 String str(lhs); str.append(rhs); return str; }
00833 inline String operator+(const Char *lhs, const String &rhs) {
00834 String str(lhs); str.append(rhs); return str; }
00835 inline String operator+(Char lhs, const String &rhs) {
00836 String str(lhs); str.append(rhs); return str; }
00837 inline String operator+(const String &lhs, const Char *rhs) {
00838 String str(lhs); str.append(rhs); return str; }
00839 inline String operator+(const String &lhs, Char rhs) {
00840 String str(lhs); str.append(rhs); return str; }
00841
00842
00843
00844
00845
00846
00847
00848
00849 inline Bool operator==(const String &x, const String &y) {
00850 return x.compare(y) == 0; }
00851 inline Bool operator!=(const String &x, const String &y) {
00852 return x.compare(y) != 0; }
00853 inline Bool operator>(const String &x, const String &y) {
00854 return x.compare(y) > 0; }
00855 inline Bool operator>=(const String &x, const String &y) {
00856 return x.compare(y) >= 0; }
00857 inline Bool operator<(const String &x, const String &y) {
00858 return x.compare(y) < 0; }
00859 inline Bool operator<=(const String &x, const String &y) {
00860 return x.compare(y) <= 0; }
00861 inline Bool operator==(const String &x, const Char *t) {
00862 return x.compare(t) == 0; }
00863 inline Bool operator!=(const String &x, const Char *t) {
00864 return x.compare(t) != 0; }
00865 inline Bool operator>(const String &x, const Char *t) {
00866 return x.compare(t) > 0; }
00867 inline Bool operator>=(const String &x, const Char *t) {
00868 return x.compare(t) >= 0; }
00869 inline Bool operator<(const String &x, const Char *t) {
00870 return x.compare(t) < 0; }
00871 inline Bool operator<=(const String &x, const Char *t) {
00872 return x.compare(t) <= 0; }
00873 inline Bool operator==(const String &x, const Char t) {
00874 return x.compare(String(t)) == 0; }
00875 inline Bool operator!=(const String &x, const Char t) {
00876 return x.compare(String(t)) != 0; }
00877 inline Bool operator>(const String &x, const Char t) {
00878 return x.compare(String(t)) > 0; }
00879 inline Bool operator>=(const String &x, const Char t) {
00880 return x.compare(String(t)) >= 0; }
00881 inline Bool operator<(const String &x, const Char t) {
00882 return x.compare(String(t)) < 0; }
00883 inline Bool operator<=(const String &x, const Char t) {
00884 return x.compare(String(t)) <= 0; }
00885
00886
00887
00888 inline Int compare(const string &x, const string &y) {
00889 return x.compare(y); }
00890 inline Int compare(const string &x, const Char *y) {
00891 return x.compare(y); }
00892 inline Int compare(const string &x, const Char y) {
00893 return x.compare(String(y)); }
00894
00895
00896 Int fcompare(String x, String y);
00897
00898
00899
00900
00901
00902
00903
00904 Int split(const string &str, string res[], Int maxn,
00905 const string &sep);
00906 Int split(const string &str, string res[], Int maxn,
00907 const Char sep);
00908 Int split(const string &str, string res[], Int maxn,
00909 const RegexBase &sep);
00910
00911
00912
00913
00914
00915 String common_prefix(const string &x, const string &y,
00916 Int startpos = 0);
00917 String common_suffix(const string &x, const string &y,
00918 Int startpos = -1);
00919 String replicate(Char c, String::size_type n);
00920 String replicate(const string &str, String::size_type n);
00921 String join(string src[], Int n, const string &sep);
00922
00923
00924
00925
00926
00927
00928 String reverse(string str);
00929
00930 String upcase(string str);
00931
00932 String downcase(string str);
00933
00934
00935 String capitalize(string str);
00936
00937
00938
00939
00940
00941 ostream &operator<<(ostream &s, const String &x);
00942
00943
00944
00945 inline SubString::SubString(const string &str, string::size_type pos,
00946 string::size_type len) :
00947 ref_p(str), pos_p((pos > str.length()) ? str.length() : pos),
00948 len_p((len == string::npos || pos_p+len > str.length()) ?
00949 str.length()-pos_p : len) {}
00950
00951 inline SubString String::operator()(size_type pos, size_type len) {
00952 return at(pos, len); }
00953 inline const Char *SubString::chars() const {
00954 return String(*this).c_str(); }
00955
00956 inline Bool String::contains(Char c, Int pos) const {
00957 return (index(c, pos) != npos); }
00958 inline Bool String::contains(const string &str, Int pos) const {
00959 return (index(str, pos) != npos); }
00960 inline Bool String::contains(const Char *s, Int pos) const {
00961 return (index(s, pos) != npos); }
00962 inline Bool String::contains(const RegexBase &r, Int pos) const {
00963 return (index(r, pos) != npos); }
00964
00965 inline Bool String::matches(const string &str, Int pos) const {
00966 return ((pos < 0) ? index(str, pos) == 0 :
00967 length() != 0 && str.length() != 0 &&
00968 length() == pos+str.length() &&
00969 static_cast<size_type>(pos) < length() &&
00970 index(str, pos) == static_cast<size_type>(pos)) ; }
00971 inline ostream &operator<<(ostream &s, const String &x) {
00972 s << x.c_str(); return s; }
00973
00974
00975 }
00976
00977 #ifndef AIPS_NO_TEMPLATE_SRC
00978 #include <casa/BasicSL/String.cc>
00979 #endif //# AIPS_NO_TEMPLATE_SRC
00980 #endif