casacore
Loading...
Searching...
No Matches
String.h
Go to the documentation of this file.
1//# String.h: String class
2//# Copyright (C) 2001,2002,2003
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_STRING_H
27#define CASA_STRING_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31
32//# Includes
33#include <string>
34
35using std::string;
36
37#include <casacore/casa/iosstrfwd.h>
38#include <casacore/casa/sstream.h>
39
40namespace casacore { //# NAMESPACE CASACORE - BEGIN
41
42//# Forward Declarations
43class String;
44class Regex;
45
46// <summary> SubString help class to be used in at, before, ... </summary>
47// <synopsis>
48// The SubString class can only be used by the String class to be able to
49// operate the Casacore defined replacement operators at, before, after,
50// through, from. The class is used transparently in operations like:
51// <srcblock>
52// string.at(2,3) = "five";
53// </srcblock>
54// If the SubString starts at a position outside the length of the
55// original string (like e.g. in after(1000000)), a zero length string is
56// created (not an exception thrown like in standard string operations).
57// </synopsis>
58
59class SubString {
60public:
61 //# Friends
62 friend class String;
63 // Make a string
64 operator const string() const { return string(ref_p, pos_p, len_p); }
65 // Default copy constructor.
66 SubString (const SubString&) = default;
67 // Assignment
68 // <group>
73 // </group>
74 // Get as (const) C array
75 const Char *chars() const;
76 // Obtain length
77 string::size_type length() const { return len_p; }
78
79private:
80 //# Constructors
81 // Constructor (there are no public constructors)
82 SubString(const string &str, string::size_type pos,
83 string::size_type len);
84 //# Data
85 // Referenced string
86 const string &ref_p;
87 // Start of sub-string
88 string::size_type pos_p;
89 // Length of sub-string
90 string::size_type len_p;
91};
92
93// <summary>
94// String: the storage and methods of handling collections of characters.
95// </summary>
96
97// <use visibility=export>
98
99// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tString.cc" demos="">
100// </reviewed>
101
102// <prerequisite>
103// <li> Regex - the regular expressions class
104// <li> the std string class
105// </prerequisite>
106//
107// <etymology>
108// The String class name is a continuation of the "C" language custom of
109// refering to collections of characters as "strings of characters".
110// </etymology>
111//
112// <synopsis>
113// The String class is the Casacore implementation of a string class. It is
114// from the standard library string class, and all operations
115// and behaviour of strings as defined in the standard are available for
116// a String. The only difference is the extension with additional functions
117// in the Casacore String class as compared to the standard string class.
118//
119// The String class may be instantiated in many ways:
120// <ol>
121// <li> A single character - <src>String myChar('C');</src>
122// <li> A Char* argument - <src>String myWord("Yowza");</src>
123// <li> The first n chararcters of a pre-existing string -
124// <src>String myFoo("fooey", 3);</src>
125// </ol> As well as the copy and default constructors and iterator based ones.
126//
127// A String may be concatinated with another object (String, or
128// char*) with either prepending or postpending. A search for the position
129// of a character within a String may return its position, a Bool that it
130// is contained within or a Bool confirming your guess at the character's
131// position is correct. A check of the frequency of occurance of a string
132// within a String will return the number of occurances.
133//
134// Strings may be extracted from Strings at, before, through, from and
135// after a starting position within the String. Deletion of characters is
136// possible after a given position within the String. Global substitution
137// of characters within a String is provided, as well. Splitting of Strings
138// into a carray of Strings is possible, based upon a given separator
139// character, with a return value of the number of elements split. The joining
140// together of the elements of an array of Strings into one String is possible.
141//
142// Finally, transformations of case and conversions of type are provided.
143//
144// The standard string class provides the following functionality:
145// <ol>
146// <li> Construction from (part of) String, (part of) Char*,
147// (repeating) Char, iterator pair.
148// <li> Assignment from String, Char*, Char
149// <li> Iterators: begin() and end(); rbegin() and rend() (Note: gcc reverse
150// iterators still weak)
151// <li> Capacity: size, length, max_size, resize, capacity, reserve, clear,
152// empty
153// <li> Special size: String::size_type, with indicator: String::npos
154// <li> Element access: [pos] and at(pos) (both const and non-const)
155// <li> Modifiers: += of String, Char*, Char; append of (part of) String,
156// Char*, Char and iterator defined; assign() of (part of)
157// String, Char* and (repeating) Char and iterator;
158// insertion of same; replacing of same; erase of part of
159// String; a copy and a swap.
160// <li> C-string: get Char* with c_str() or data() and get the relevant
161// Allocator used (Note: not fully supported in gcc)
162// <li> Operations: find, rfind, find_first_of, find_last_of, find_first_not_of,
163// find_last_not_of; substr (Note only readable substring);
164// compare with (part of) String, Char*
165// <li> Globals: Addition operators for String, Char*, Char; all comparison
166// operators for String and Char*; getline; input and output
167// stream operators
168// <li> Typedef: All relevant typedefs for standard containers and iterator
169// handling
170// </ol>
171// The Casacore additions are:
172// <ol>
173// <li> To standard: some Char function arguments where appropriate; Regex
174// arguments in search like methods.
175// <li> Substring additions: at, before, after, from, through functions taking
176// search String, Char* as arguments can give (hidden) substrings
177// which can be assigned (as in <src> at(1,2) = ";"</src>)
178// <li> Methods: prepend (in addition to standard append); del (as erase);
179// global substitution of String and patterns;
180// freq (count of occurance); split/join of strings at separator
181// or pattern; upcase, downcase, reverse;
182// common_suffix and _prefix; replicate; case insensitive
183// compare; creation from stream
184// </ol>
185
186// </synopsis>
187//
188// <example>
189// <srcblock>
190// // Let's start with a simple string.
191// String myString("the time");
192// // add some more on the end...
193// myString += " for all good men";
194// // prepend some on the front...
195// myString.prepend("Now is ");
196// // do some concatination...
197// String evenMore;
198// evenMore += myString + " to come to";
199// // do some three way concatination
200// String allKeys, finishIt(" their country.");
201// allKeys = evenMore + "the aid of" + finishIt;
202// // find the spot where we put something earlier
203// String::size_type position = allKeys.index(finishIt);
204// // find if the word is in the String...
205// Bool query = myString.contains("good men");
206// // ask if the position we think is true is correct...
207// Bool answer = allKeys.matches(finishIt, position);
208// // How many spaces are in our phrase?
209// Int spacesCount = allKeys.freq(" ");
210// </srcblock>
211// </example>
212//
213// <motivation>
214// The String class eases the handling of characters within the Casacore
215// environment.
216// </motivation>
217//
218// <todo asof=2000/12/05">
219// <li> if old string disappeared; remove the alloc() call.
220// <li> add more tests (for string methods) when old String disappears
221// </todo>
222
223class String : public string {
224
225 public:
226
227 //# Basic container typedefs
228 typedef string::traits_type traits_type;
229 typedef string::value_type value_type;
230 typedef string::allocator_type allocator_type;
231 typedef string::size_type size_type;
232 typedef string::difference_type difference_type;
233
234 typedef string::reference reference;
235 typedef string::const_reference const_reference;
236 typedef string::pointer pointer;
237 typedef string::const_pointer const_pointer;
238
239 typedef string::iterator iterator;
240 typedef string::const_iterator const_iterator;
241 typedef string::reverse_iterator reverse_iterator;
242 typedef string::const_reverse_iterator const_reverse_iterator;
243 //# Next cast necessary to stop warning in gcc
244 static const size_type npos = static_cast<size_type>(-1);
245
246 //# Constructors
247 // Default constructor
248 String() : string("") {}
249 // Construct from std string
250 // Construct from (part of) other string: acts as copy constructor
251 // <thrown>
252 // <li> out_of_range if pos > str.size()
253 // </thrown>
254 String(const string& str, size_type pos=0, size_type n=npos) :
255 string(str, pos, n) {}
256 // Construct from char* with given length
257 // <thrown>
258 // <li> length_error if n == npos
259 // </thrown>
260 String(const Char* s, size_type n) : string(s, n) {}
261 // Construct from char array
262 String(const Char* s) : string(s) {}
263 // Construct from a single char (repeated n times)
264 // <thrown>
265 // <li> length_error if n == npos
266 // </thrown>
267 String(size_type n, Char c) : string(n, c) {}
268 // Construct from iterator
269 template<class InputIterator>
270 String(InputIterator begin, InputIterator end) : string(begin, end) {}
271 // From single char (** Casacore addition).
272 // <note role=warning> Note that there is no automatic Char-to-String
273 // conversion available. This stops inadvertent conversions of
274 // integer to string. </note>
275 explicit String(Char c) : string(1, c) {}
276 // Construct from a SubString
277 String(const SubString &str) : string(str.ref_p, str.pos_p, str.len_p) {}
278 // Construct from a stream.
279 String(ostringstream &os);
280
281 //# Destructor
282 // Destructor
284
285 //# Operators
286 // Assignments (they are all deep copies according to standard)
287 // <group>
288 String& operator=(const string& str) {
289 return static_cast<String&>(string::operator=(str)); }
291 return (*this = String(str)); }
292 String& operator=(const Char* s) {
293 return static_cast<String&>(string::operator=(s)); }
295 return static_cast<String&>(string::operator=(c)); }
296 // </group>
297 // ** Casacore addition: synonym for at(pos, len)
299 // Concatenate
300 // <group>
301 String& operator+=(const string& str) {
302 return static_cast<String&>(string::operator+=(str)); }
303 String& operator+=(const Char* s) {
304 return static_cast<String&>(string::operator+=(s)); }
306 return static_cast<String&>(string::operator+=(c)); }
307 // </group>
308
309 // Indexing. The standard version is undefined if <src>pos > size()</src>, or
310 // <src>pos >= size()</src> for non-const version.
311 // <note role=warning> The const_reference version needs the at() version
312 // for the gcc compiler: no const [] exists. </note>
313 // <group>
315 return string::at(pos); }
317 return string::operator[](pos); }
318 // *** Casacore addition
319 // <group>
321 return string::at(pos); }
322 Char firstchar() const { return at(static_cast<size_type>(0)); }
323 Char lastchar() const { return at(length()-1); }
324 // </group>
325 // </group>
326
327 //# Member functions
328 // Iterators
329 // <group>
330 iterator begin() { return string::begin(); }
331 const_iterator begin() const { return string::begin(); }
332 iterator end() { return string::end(); }
333 const_iterator end() const { return string::end(); }
334 reverse_iterator rbegin() { return string::rbegin(); }
335 const_reverse_iterator rbegin() const { return string::rbegin(); }
336 reverse_iterator rend() { return string::rend(); }
337 const_reverse_iterator rend() const { return string::rend(); }
338 // </group>
339
340 // Capacity, size
341 // <group>
342 size_type size() const { return string::size(); }
343 size_type length() const { return string::length(); }
344 size_type max_size() const { return string::max_size(); }
345 size_type capacity() const { return string::capacity(); }
346 // ** Casacore addition -- works as a capacity(n) -- Note Int
347 Int allocation() const { return string::capacity(); }
348 // </group>
349
350 // Resize by truncating or extending with copies of <src>c</src> (default
351 // Char())
352 // <thrown>
353 // <li> length_error if n > max_size()
354 // <li> length_error if res_arg > max_size()
355 // </thrown>
356 // <group>
357 // <note role=tip> The reserve length given is non-binding on the
358 // implementation </note>
360 string::resize(n); return *this; }
362 string::resize(n, c); return *this; }
363 String& reserve(size_type res_arg = 0) {
364 string::reserve(res_arg); return *this; }
365 // ** Casacore addition -- works as a resize(n)
366 void alloc(size_type n) { string::resize(n); }
367 // </group>
368
369 // Clear the string
370 // <note role=warning> clear() executed as erase() due to missing clear() in
371 // gcc </note>
372 void clear() { string::erase(begin(), end()); }
373
374 // Test for empty
375 Bool empty() const { return string::empty(); }
376
377 // Addressing
378 // <thrown>
379 // <li> out_of_range if pos >= size()
380 // </thrown>
381 // <group>
382 const_reference at(size_type n) const { return string::at(n); }
383 reference at(size_type n) { return string::at(n); }
384 // </group>
385
386 // Append
387 // <thrown>
388 // <li> out_of_range if pos > str.size()
389 // <li> length_error if new size() >= npos
390 // </thrown>
391 // <note role=warning> The standard has a
392 // <src>void push_back(const Char) </src> which is completely undefined. It
393 // probably is a remnant of the full list of container functions pop/push
394 // back/front. </note>
395 // <group>
396 String& append(const string& str) {
397 return static_cast<String&>(string::append(str)); }
398 String& append(const string& str, size_type pos, size_type n) {
399 return static_cast<String&>(string::append(str, pos, n)); }
400 String& append(const Char* s, size_type n) {
401 return static_cast<String&>(string::append(s, n)); }
402 String& append(const Char* s) {
403 return static_cast<String&>(string::append(s)); }
405 return static_cast<String&>(string::append(n, c)); }
406 template<class InputIterator>
407 String& append(InputIterator first, InputIterator last) {
408 return static_cast<String&>(string::append(first, last)); }
409 // ** Casacore addition
411 return static_cast<String&>(string::append(1, c)); }
412 // </group>
413
414 // Assign
415 // <thrown>
416 // <li> out_of_range if pos > str.size()
417 // </thrown>
418 // <group>
419 String& assign(const string& str) {
420 return static_cast<String&>(string::assign(str)); }
421 String& assign(const string& str, size_type pos, size_type n) {
422 return static_cast<String&>(string::assign(str, pos, n)); }
423 String& assign(const Char* s, size_type n) {
424 return static_cast<String&>(string::assign(s, n)); }
425 String& assign(const Char* s) {
426 return static_cast<String&>(string::assign(s)); }
428 return static_cast<String&>(string::assign(n, c)); }
429 template<class InputIterator>
430 String& assign(InputIterator first, InputIterator last) {
431 return static_cast<String&>(string::assign(first, last)); }
432 // ** Casacore addition
434 return static_cast<String&>(string::assign(1, c)); }
435 // </group>
436
437 // Insert
438 // <thrown>
439 // <li> out_of_range if pos1 > str.size() or pos2 > str.size()
440 // <li> length_error if new size() >= npos
441 // </thrown>
442 // <group>
443 String& insert(size_type pos1, const string& str) {
444 return static_cast<String&>(string::insert(pos1, str)); }
445 String& insert(size_type pos1, const string& str,
446 size_type pos2, size_type n) {
447 return static_cast<String&>(string::insert(pos1, str, pos2, n)); }
448 String& insert(size_type pos, const Char* s, size_type n) {
449 return static_cast<String&>(string::insert(pos, s, n)); }
450 String& insert(size_type pos, const Char* s) {
451 return static_cast<String&>(string::insert(pos, s)); }
453 return static_cast<String&>(string::insert(pos, n, c)); }
454 // ** Casacore addition
456 return static_cast<String&>(string::insert(pos, 1, c)); }
457
459 return string::insert(p, c); }
461 string::insert(p, n, c); }
462 template<class InputIterator>
463 void insert(iterator p, InputIterator first, InputIterator last) {
464 string::insert(p, first, last); }
465 // ** Casacore additions
466 // <group>
467 String& insert(iterator p, const string& str) {
468 return static_cast<String&>(string::insert(p-begin(), str)); }
470 return static_cast<String&>(string::insert(p-begin(), s, n)); }
471 String& insert(iterator p, const Char* s) {
472 return static_cast<String&>(string::insert(p-begin(), s)); }
473 // </group>
474 // </group>
475
476 // Compare. Returns 0 if strings equal and of equal size; else positive if
477 // str larger or longer; else negative.
478 // <note role=warning> The gcc compiler does not have the proper standard
479 // compare functions. Hence they are locally implemented. </note>
480 // <group>
481 Int compare(const string& str) const {
482 return string::compare(str); }
483 Int compare(size_type pos1, size_type n1, const string& str) const {
484 return String(*this, pos1, n1).compare(str); }
485 Int compare(size_type pos1, size_type n1, const string& str,
486 size_type pos2, size_type n2) const {
487 return String(*this, pos1, n1).compare(String(str, pos2, n2)); }
488 Int compare(const Char* s) const {
489 return string::compare(s); }
490 Int compare(size_type pos1, size_type n1, const Char* s,
491 size_type n2=npos) const {
492 return String(*this, pos1, n1).compare(String(s, n2)); }
493 // </group>
494
495 // Erase
496 // <group>
498 return static_cast<String&>(string::erase(pos, n)); }
500 return string::erase(position); }
502 return string::erase(first, last); }
503 // </group>
504
505 // Replace
506 // <thrown>
507 // <li> out_of_range if pos1 > str.size() or pos2 > str.size()
508 // <li> length_error if new size() > npos
509 // </thrown>
510 // <group>
511 String& replace(size_type pos1, size_type n1, const string& str) {
512 return static_cast<String&>(string::replace(pos1, n1, str)); }
513 String& replace(size_type pos1, size_type n1, const string& str,
514 size_type pos2, size_type n2) {
515 return static_cast<String&>(string::replace(pos1, n1, str, pos2, n2)); }
516 String& replace(size_type pos, size_type n1, const Char* s, size_type n2) {
517 return static_cast<String&>(string::replace(pos, n1, s, n2)); }
518 String& replace(size_type pos, size_type n1, const Char* s) {
519 return static_cast<String&>(string::replace(pos, n1, s)); }
521 return static_cast<String&>(string::replace(pos, n1, n2, c)); }
522 // ** Casacore addition
524 return static_cast<String&>(string::replace(pos, n1, 1, c)); }
525 String& replace(iterator i1, iterator i2, const string& str) {
526 return static_cast<String&>(string::replace(i1, i2, str)); }
528 return static_cast<String&>(string::replace(i1, i2, s, n)); }
529 String& replace(iterator i1, iterator i2, const Char* s) {
530 return static_cast<String&>(string::replace(i1, i2, s)); }
532 return static_cast<String&>(string::replace(i1, i2, n, c)); }
533 // ** Casacore addition
535 return static_cast<String&>(string::replace(i1, i2, 1, c)); }
536 template<class InputIterator>
537 String& replace(iterator i1, iterator i2, InputIterator j1,
538 InputIterator j2) {
539 return static_cast<String&>(string::replace(i1, i2, j1, j2)); }
540 // </group>
541
542 // Copy
543 // <thrown>
544 // <li> out_of_range if pos > size()
545 // </thrown>
546 size_type copy(Char* s, size_type n, size_type pos = 0) const {
547 return string::copy(s, n, pos); }
548
549 // Swap
550 void swap(string& s) { string::swap(s); }
551
552 // Get char array
553 // <group>
554 // As a proper null terminated C-string
555 const Char *c_str() const { return string::c_str(); }
556 // As pointer to char array
557 const Char *data() const { return string::data(); }
558 // ** Casacore synonym
559 const Char *chars() const { return string::c_str(); }
560 // </group>
561
562 // Get allocator used
563 // <note role=warning> gcc has no get_allocator() </note>
564 allocator_type get_allocator() const { return string::allocator_type(); }
565
566 // Get a sub string
567 // <thrown>
568 // <li> out_of_range if pos > size()
569 // </thrown>
571 return String(*this, pos, n); }
572
573 // Create a formatted string using the given printf format string.
574 static String format (const char* picture, ...);
575
576 // Convert a String to a value. All characters in the string must be used.
577 // It uses a shift from an ostringstream, so that operator must exist
578 // for the data type used.
579 // <br>In case of an error, an exception is thrown if <src>chk</src> is set.
580 // Otherwise it returns False and <src>value</src> contains the value read
581 // so far.
582 // <group>
583 template<typename T> inline Bool fromString (T& value, Bool chk=True) const
584 {
585 std::istringstream os(*this);
586 os >> value;
587 if (os.fail() || !os.eof()) {
588 if (chk) throwFromStringError();
589 return False;
590 }
591 return True;
592 }
593 template<typename T> inline T fromString() const
594 {
595 T value;
597 return value;
598 }
599 // </group>
600
601 // Convert a string to an Int, Float or Double.
602 // <br>In case of an error, an exception is thrown if <src>chk</src> is set.
603 // Otherwise the value read so far is returned (0 if nothing read).
604 // <group>
605 static Int toInt (const String& s, Bool chk=False);
606 static Float toFloat (const String& s, Bool chk=False);
607 static Double toDouble (const String& s, Bool chk=False);
608 // </group>
609
610 // Convert a value to a String.
611 // It uses a shift into an ostringstream, so that operator must be
612 // defined for the data type used.
613 template<typename T>
614 static String toString(const T& value)
615 {
616 std::ostringstream os;
617 os << value;
618 return os.str();
619 }
620
621 // Remove beginning and ending whitespace.
622 void trim();
623
624 // Remove specified chars from beginning and end of string.
625 void trim(char c[], uInt n);
626
627 // Remove specified character from beginning of string.
628 // If the character is repeated more than once on the left, all instances
629 // will be removed; e.g. ltrim(',') results in ",,xy" becoming "xy".
630 void ltrim(char c);
631
632 // Remove specified character from end of string.
633 // If the character is repeated more than once on the right, all instances
634 // will be removed; e.g. rtrim(',') results in "xy,," becoming "xy".
635 void rtrim(char c);
636
637 // Does the string start with the specified string?
638 Bool startsWith(const string& beginString) const
639 { return find(beginString) == 0; }
640
641 // Search functions. Returns either npos (if not found); else position.
642 // <note role=warning> The Regex ones are ** Casacore additions</note>
643 // <group>
644 size_type find(const string &str, size_type pos=0) const {
645 return string::find(str, pos); }
646 size_type find(const Char *s, size_type pos=0) const {
647 return string::find(s, pos); }
648 size_type find(const Char *s, size_type pos, size_type n) const {
649 return string::find(s, pos, n); }
650 size_type find(Char c, size_type pos=0) const {
651 return string::find(c, pos); }
652 size_type find(const Regex &r, size_type pos=0) const;
653 size_type rfind(const string &str, size_type pos=npos) const {
654 return string::rfind(str, pos); }
655 size_type rfind(const Char *s, size_type pos=npos) const {
656 return string::rfind(s, pos); }
657 size_type rfind(const Char *s, size_type pos, size_type n) const {
658 return string::rfind(s, pos, n); }
660 return string::rfind(c, pos); }
661 size_type find_first_of(const string &str, size_type pos=0) const {
662 return string::find_first_of(str, pos); }
663 size_type find_first_of(const Char *s, size_type pos=0) const {
664 return string::find_first_of(s, pos); }
666 return string::find_first_of(s, pos, n); }
668 return string::find_first_of(c, pos); }
669 size_type find_last_of(const string &str, size_type pos=npos) const {
670 return string::find_last_of(str, pos); }
671 size_type find_last_of(const Char *s, size_type pos=npos) const {
672 return string::find_last_of(s, pos); }
674 return string::find_last_of(s, pos, n); }
676 return string::find_last_of(c, pos); }
677 size_type find_first_not_of(const string &str, size_type pos=0) const {
678 return string::find_first_not_of(str, pos); }
679 size_type find_first_not_of(const Char *s, size_type pos=0) const {
680 return string::find_first_not_of(s, pos); }
682 return string::find_first_not_of(s, pos, n); }
684 return string::find_first_not_of(c, pos); }
685 size_type find_last_not_of(const string &str, size_type pos=npos) const {
686 return string::find_last_not_of(str, pos); }
688 return string::find_last_not_of(s, pos); }
690 return string::find_last_not_of(s, pos, n); }
692 return string::find_last_not_of(c, pos); }
693 // </group>
694
695 // Containment. ** Casacore addition
696 // <group name=contains>
697 Bool contains(Char c) const {
698 return (find(c) != npos); }
699 Bool contains(const string &str) const {
700 return (find(str) != npos); }
701 Bool contains(const Char *s) const {
702 return (find(s) != npos); }
703 Bool contains(const Regex &r) const;
704 // </group>
705 // Does the string starting at the given position contain the given substring?
706 // If the position is negative, it is counted from the end.
707 // ** Casacore addition
708 // <group name=contains_pos>
709 Bool contains(Char c, Int pos) const;
710 Bool contains(const string &str, Int pos) const;
711 Bool contains(const Char *s, Int pos) const;
712 Bool contains(const Regex &r, Int pos) const;
713 // </group>
714
715 // Matches entire string from pos
716 // (or till pos if negative pos). ** Casacore addition
717 // <group name=matches>
718 Bool matches(const string &str, Int pos = 0) const;
719 Bool matches(Char c, Int pos = 0) const {
720 return matches(String(c), pos); };
721 Bool matches(const Char *s, Int pos = 0) const {
722 return matches(String(s), pos); };
723 Bool matches(const Regex &r, Int pos = 0) const;
724 // </group>
726 // Concatenate by prepending the argument onto String. ** Casacore addition
727 // <group name=concatenation_method>
728 void prepend(const string &str);
729 void prepend(const Char *s);
730 void prepend(Char c);
731 // </group>
733 // Return the position of the target in the string or npos for failure.
734 // ** Casacore addition
735 // <group name=index>
736 size_type index(Char c, Int startpos = 0) const {
737 return ((startpos >= 0) ? find(c, startpos) :
738 rfind(c, length() + startpos - 1)); }
739 size_type index(const string &str, Int startpos = 0) const {
740 return ((startpos >= 0) ? find(str, startpos) :
741 rfind(str, length() + startpos - str.length())); }
742 size_type index(const Char *s, Int startpos = 0) const {
743 return ((startpos >= 0) ? find(s, startpos) :
744 rfind(s, length() + startpos - traits_type::length(s))); }
745 size_type index(const Regex &r, Int startpos = 0) const;
746 // </group>
748 // Return the number of occurences of target in String. ** Casacore addition
749 // <group name=freq>
750 Int freq(Char c) const;
751 Int freq(const string &str) const;
752 Int freq(const Char *s) const;
753 // </group>
755 // Extract the string "at" the argument's position. ** Casacore addition
756 // <group name=at>
758 String at(size_type pos, size_type len) const {
759 return String(*this, pos, len); }
760 SubString at(const string &str, Int startpos = 0);
761 String at(const string &str, Int startpos = 0) const;
762 SubString at(const Char *s, Int startpos = 0);
763 String at(const Char *s, Int startpos = 0) const;
764 SubString at(Char c, Int startpos = 0);
765 String at(Char c, Int startpos = 0) const;
766 SubString at(const Regex &r, Int startpos = 0);
767 String at(const Regex &r, Int startpos = 0) const;
768 // Next ones for overloading reasons.
769 // <note role=tip> It is better to use the <src>substr()</src> method
770 // in stead. </note>
771 // <group>
772 SubString at(Int pos, Int len) {
773 return at(static_cast<size_type>(pos), static_cast<size_type>(len));
774 };
775 String at(Int pos, Int len) const {
776 return at(static_cast<size_type>(pos), static_cast<size_type>(len));
777 };
778 SubString at(Int pos, size_type len) {
779 return at(static_cast<size_type>(pos), len);
780 };
781 String at(Int pos, size_type len) const {
782 return at(static_cast<size_type>(pos), len);
783 };
784 // </group>
785 // </group>
786
787 // Start at startpos and extract the string "before" the argument's
788 // position, exclusive. ** Casacore addition
789 // <group name=before>
790 SubString before(size_type pos) const;
791 SubString before(const string &str, size_type startpos = 0) const;
792 SubString before(const Char *s, size_type startpos = 0) const;
793 SubString before(Char c, size_type startpos = 0) const;
794 SubString before(const Regex &r, size_type startpos = 0) const;
795 // Next one for overloading reasons
796 SubString before(Int pos) const {
797 return before(static_cast<size_type>(pos)); };
798 // </group>
799
800 // Start at startpos and extract the SubString "through" to the argument's
801 // position, inclusive. ** Casacore addition
802 // <group name=through>
804 SubString through(const string &str, size_type startpos = 0);
805 SubString through(const Char *s, size_type startpos = 0);
806 SubString through(Char c, size_type startpos = 0);
807 SubString through(const Regex &r, size_type startpos = 0);
808 // Next one for overloading reasons
809 SubString through(Int pos) {
810 return through(static_cast<size_type>(pos)); }
811 // </group>
812
813 // Start at startpos and extract the SubString "from" the argument's
814 // position, inclusive, to the String's end. ** Casacore addition
815 // <group name=from>
816 SubString from(size_type pos);
817 SubString from(const string &str, size_type startpos = 0);
818 SubString from(const Char *s, size_type startpos = 0);
819 SubString from(Char c, size_type startpos = 0);
820 SubString from(const Regex &r, size_type startpos = 0);
821 // Next one for overloading reasons
822 SubString from(Int pos) {
823 return from(static_cast<size_type>(pos));
824 };
825 // </group>
826
827 // Start at startpos and extract the SubString "after" the argument's
828 // position, exclusive, to the String's end. ** Casacore addition
829 // <group name=after>
831 SubString after(const string &str, size_type startpos = 0);
832 SubString after(const Char *s, size_type startpos = 0);
833 SubString after(Char c, size_type startpos = 0);
834 SubString after(const Regex &r, size_type startpos = 0);
835 // Next one for overloading reasons
836 SubString after(Int pos) {
837 return after(static_cast<size_type>(pos));
838 };
839 // </group>
840
841 // Maybe forget some. ** Casacore addition
842 // <group>
843 // internal transformation to reverse order of String.
844 void reverse();
845 // internal transformation to capitalization of String.
847 // internal transformation to uppercase of String
848 void upcase();
849 // internal transformation to lowercase of String
850 void downcase();
851 // </group>
852
853 // Delete len chars starting at pos. ** Casacore addition
854 void del(size_type pos, size_type len);
855
856 // Delete the first occurrence of target after startpos. ** Casacore addition
857 //<group name=del_after>
858 void del(const string &str, size_type startpos = 0);
859 void del(const Char *s, size_type startpos = 0);
860 void del(Char c, size_type startpos = 0);
861 void del(const Regex &r, size_type startpos = 0);
862 // Overload problem
863 void del(Int pos, Int len) {
864 del(static_cast<size_type>(pos), static_cast<size_type>(len)); }
865 //</group>
866
867 // Global substitution: substitute all occurrences of pat with repl, and
868 // return the number of replacements.
869 // ** Casacore addition
870 //<group name=gsub>
871 Int gsub(const string &pat, const string &repl);
872 Int gsub(const Char *pat, const string &repl);
873 Int gsub(const Char *pat, const Char *repl);
874 Int gsub(const Regex &pat, const string &repl);
875 //</group>
876
877private:
878 // Helper functions for at, before etc
879 // <group>
881 return SubString(*this, first, l); }
882 // </group>
883
884 // Helper function for fromString.
886};
887
888// <summary>
889// Global concatenation operators
890// </summary>
891
892// The global concatenation operators
893// <group name=concatenator>
894inline String operator+(const String &lhs, const String &rhs) {
895 String str(lhs); str.append(rhs); return str; }
896inline String operator+(const Char *lhs, const String &rhs) {
897 String str(lhs); str.append(rhs); return str; }
898inline String operator+(Char lhs, const String &rhs) {
899 String str(lhs); str.append(rhs); return str; }
900inline String operator+(const String &lhs, const Char *rhs) {
901 String str(lhs); str.append(rhs); return str; }
902inline String operator+(const String &lhs, Char rhs) {
903 String str(lhs); str.append(rhs); return str; }
904// </group>
905
906// <summary>
907// Global comparison operators
908// </summary>
909
910// The global comparison operators
911// <group name=comparitor>
912inline Bool operator==(const String &x, const String &y) {
913 return x.compare(y) == 0; }
914inline Bool operator!=(const String &x, const String &y) {
915 return x.compare(y) != 0; }
916inline Bool operator>(const String &x, const String &y) {
917 return x.compare(y) > 0; }
918inline Bool operator>=(const String &x, const String &y) {
919 return x.compare(y) >= 0; }
920inline Bool operator<(const String &x, const String &y) {
921 return x.compare(y) < 0; }
922inline Bool operator<=(const String &x, const String &y) {
923 return x.compare(y) <= 0; }
924inline Bool operator==(const String &x, const Char *t) {
925 return x.compare(t) == 0; }
926inline Bool operator!=(const String &x, const Char *t) {
927 return x.compare(t) != 0; }
928inline Bool operator>(const String &x, const Char *t) {
929 return x.compare(t) > 0; }
930inline Bool operator>=(const String &x, const Char *t) {
931 return x.compare(t) >= 0; }
932inline Bool operator<(const String &x, const Char *t) {
933 return x.compare(t) < 0; }
934inline Bool operator<=(const String &x, const Char *t) {
935 return x.compare(t) <= 0; }
936inline Bool operator==(const String &x, const Char t) {
937 return x.compare(String(t)) == 0; }
938inline Bool operator!=(const String &x, const Char t) {
939 return x.compare(String(t)) != 0; }
940inline Bool operator>(const String &x, const Char t) {
941 return x.compare(String(t)) > 0; }
942inline Bool operator>=(const String &x, const Char t) {
943 return x.compare(String(t)) >= 0; }
944inline Bool operator<(const String &x, const Char t) {
945 return x.compare(String(t)) < 0; }
946inline Bool operator<=(const String &x, const Char t) {
947 return x.compare(String(t)) <= 0; }
948// ** Casacore additions of global compares. Returns 0 if equal; lt or gt 0 if
949// strings unequal or of unequal lengths.
950// <group>
951inline Int compare(const string &x, const string &y) {
952 return x.compare(y); }
953inline Int compare(const string &x, const Char *y) {
954 return x.compare(y); }
955inline Int compare(const string &x, const Char y) {
956 return x.compare(String(y)); }
957// this version ignores case. ** Casacore addition. Result is 0 if equal
958// strings of equal lengths; else lt or gt 0 to indicate differences.
959Int fcompare(const String& x, const String& y);
960// </group>
961// </group>
962
963// <summary> Splitting </summary>
964// Global function which splits the String into string array res at separator
965// and returns the number of elements. ** Casacore addition
966// <group name=split>
967Int split(const string &str, string res[], Int maxn,
968 const string &sep);
969Int split(const string &str, string res[], Int maxn,
970 const Char sep);
971Int split(const string &str, string res[], Int maxn,
972 const Regex &sep);
973//</group>
974
975// <summary> Some general functions </summary>
976// Functions to find special patterns, join and replicate
977// <group name=common>
978String common_prefix(const string &x, const string &y,
979 Int startpos = 0);
980String common_suffix(const string &x, const string &y,
981 Int startpos = -1);
982String replicate(Char c, String::size_type n);
983String replicate(const string &str, String::size_type n);
984String join(string src[], Int n, const string &sep);
985// </group>
987// <summary> Casing and related functions </summary>
988// Case conversion and rearrangement functions
989// <group name=case>
990// Global function which returns a transformation to reverse order of String.
991String reverse(const string& str);
992// Global function which returns a transformation to uppercase of String.
993String upcase(const string& str);
994// Global function which returns a transformation to lowercase of String.
995String downcase(const string& str);
996// Global function which returns a transformation to capitalization of
997// String.
998String capitalize(const string& str);
999// Global function which removes leading and trailing whitespace.
1000String trim(const string& str);
1001// </group>
1003// <summary> IO </summary>
1004// <group name=io>
1005// Output
1006ostream &operator<<(ostream &s, const String &x);
1007// </group>
1008
1009//# Inlines
1010inline SubString::SubString(const string &str, string::size_type pos,
1011 string::size_type len) :
1012 ref_p(str), pos_p((pos > str.length()) ? str.length() : pos),
1013 len_p((len == string::npos || pos_p+len > str.length()) ?
1014 str.length()-pos_p : len) {}
1015
1016inline SubString String::operator()(size_type pos, size_type len) {
1017 return at(pos, len); }
1018inline const Char *SubString::chars() const {
1019 return String(*this).c_str(); }
1021inline Bool String::contains(Char c, Int pos) const {
1022 return (index(c, pos) != npos); }
1023inline Bool String::contains(const string &str, Int pos) const {
1024 return (index(str, pos) != npos); }
1025inline Bool String::contains(const Char *s, Int pos) const {
1026 return (index(s, pos) != npos); }
1027inline Bool String::contains(const Regex &r, Int pos) const {
1028 return (index(r, pos) != npos); }
1029
1030inline ostream &operator<<(ostream &s, const String &x) {
1031 s << x.c_str(); return s; }
1032
1033
1034} //# NAMESPACE CASACORE - END
1035
1036
1037// Define the hash function for String, so unordered_set<String> can be used.
1038namespace std {
1039template<>
1040struct hash<casacore::String>
1041{
1042 std::size_t operator()(casacore::String const& k) const noexcept
1043 { return std::hash<std::string>()(k); }
1044};
1045
1046}
1047
1048#endif
String: the storage and methods of handling collections of characters.
Definition String.h:223
static String format(const char *picture,...)
Create a formatted string using the given printf format string.
String & assign(const Char *s, size_type n)
Definition String.h:423
iterator end()
Definition String.h:332
size_type max_size() const
Definition String.h:344
String & replace(size_type pos1, size_type n1, const string &str)
Replace.
Definition String.h:511
Bool matches(const string &str, Int pos=0) const
Matches entire string from pos (or till pos if negative pos).
void del(const Char *s, size_type startpos=0)
Int compare(size_type pos1, size_type n1, const string &str, size_type pos2, size_type n2) const
Definition String.h:485
Int gsub(const Regex &pat, const string &repl)
String & replace(size_type pos, size_type n1, Char c)
** Casacore addition
Definition String.h:523
SubString at(Int pos, Int len)
Next ones for overloading reasons.
Definition String.h:773
static Float toFloat(const String &s, Bool chk=False)
iterator begin()
Iterators.
Definition String.h:330
String & insert(iterator p, const Char *s, size_type n)
Definition String.h:469
SubString from(Int pos)
Next one for overloading reasons.
Definition String.h:823
Char firstchar() const
Definition String.h:322
SubString from(const string &str, size_type startpos=0)
Bool contains(const string &str) const
Definition String.h:700
const Char * data() const
As pointer to char array
Definition String.h:557
Char lastchar() const
Definition String.h:323
void swap(string &s)
Swap.
Definition String.h:550
iterator erase(iterator first, iterator last)
Definition String.h:501
String(const Char *s, size_type n)
Construct from char* with given length.
Definition String.h:260
size_type find_first_of(const Char *s, size_type pos=0) const
Definition String.h:663
void downcase()
internal transformation to lowercase of String
string::const_reverse_iterator const_reverse_iterator
Definition String.h:242
String & append(const Char *s)
Definition String.h:402
String & replace(iterator i1, iterator i2, size_type n, Char c)
Definition String.h:531
size_type rfind(const Char *s, size_type pos, size_type n) const
Definition String.h:657
size_type find_last_of(Char c, size_type pos=npos) const
Definition String.h:675
SubString before(const Regex &r, size_type startpos=0) const
void prepend(const Char *s)
static String toString(const T &value)
Convert a value to a String.
Definition String.h:614
size_type find(const Regex &r, size_type pos=0) const
size_type find(const string &str, size_type pos=0) const
Search functions.
Definition String.h:644
size_type find_last_not_of(Char c, size_type pos=npos) const
Definition String.h:691
size_type index(const string &str, Int startpos=0) const
Definition String.h:741
SubString through(Int pos)
Next one for overloading reasons.
Definition String.h:810
Bool contains(const Char *s) const
Definition String.h:702
static const size_type npos
Definition String.h:244
size_type find_first_of(const string &str, size_type pos=0) const
Definition String.h:661
String & append(const Char *s, size_type n)
Definition String.h:400
string::const_reference const_reference
Definition String.h:235
String & operator=(const SubString &str)
Definition String.h:290
SubString before(const Char *s, size_type startpos=0) const
size_type find_last_of(const Char *s, size_type pos=npos) const
Definition String.h:671
String & replace(size_type pos1, size_type n1, const string &str, size_type pos2, size_type n2)
Definition String.h:513
String & operator+=(const string &str)
Concatenate.
Definition String.h:301
String & assign(size_type n, Char c)
Definition String.h:427
String at(const string &str, Int startpos=0) const
SubString after(Int pos)
Next one for overloading reasons.
Definition String.h:837
string::allocator_type allocator_type
Definition String.h:230
String(const Char *s)
Construct from char array.
Definition String.h:262
Int freq(Char c) const
Return the number of occurences of target in String.
string::difference_type difference_type
Definition String.h:232
size_type find_last_not_of(const Char *s, size_type pos=npos) const
Definition String.h:687
const_reverse_iterator rbegin() const
Definition String.h:335
void rtrim(char c)
Remove specified character from end of string.
const_reference operator[](size_type pos) const
Indexing.
Definition String.h:314
Bool matches(const Char *s, Int pos=0) const
Definition String.h:723
String & operator=(const Char *s)
Definition String.h:292
string::value_type value_type
Definition String.h:229
void trim(char c[], uInt n)
Remove specified chars from beginning and end of string.
size_type index(const Regex &r, Int startpos=0) const
SubString from(const Char *s, size_type startpos=0)
SubString from(const Regex &r, size_type startpos=0)
reference at(size_type n)
Definition String.h:383
String at(const Regex &r, Int startpos=0) const
SubString after(const string &str, size_type startpos=0)
void capitalize()
internal transformation to capitalization of String.
reverse_iterator rbegin()
Definition String.h:334
String & operator=(const string &str)
Assignments (they are all deep copies according to standard)
Definition String.h:288
string::reference reference
Definition String.h:234
const_reference elem(size_type pos) const
*** Casacore addition
Definition String.h:320
~String()
Destructor.
Definition String.h:283
String & replace(size_type pos, size_type n1, const Char *s, size_type n2)
Definition String.h:516
SubString through(Char c, size_type startpos=0)
String & replace(size_type pos, size_type n1, size_type n2, Char c)
Definition String.h:520
Bool fromString(T &value, Bool chk=True) const
Convert a String to a value.
Definition String.h:583
String substr(size_type pos=0, size_type n=npos) const
Get a sub string.
Definition String.h:570
Int compare(size_type pos1, size_type n1, const string &str) const
Definition String.h:483
size_type find_first_not_of(const Char *s, size_type pos=0) const
Definition String.h:679
String & insert(size_type pos, const Char *s)
Definition String.h:450
SubString before(Char c, size_type startpos=0) const
size_type capacity() const
Definition String.h:345
String(Char c)
From single char (** Casacore addition).
Definition String.h:275
SubString through(const Char *s, size_type startpos=0)
allocator_type get_allocator() const
Get allocator used Warning: gcc has no get_allocator()
Definition String.h:564
void ltrim(char c)
Remove specified character from beginning of string.
string::const_iterator const_iterator
Definition String.h:240
Int gsub(const Char *pat, const string &repl)
size_type find_first_not_of(const string &str, size_type pos=0) const
Definition String.h:677
String & insert(size_type pos, const Char *s, size_type n)
Definition String.h:448
void insert(iterator p, InputIterator first, InputIterator last)
Definition String.h:463
void clear()
Clear the string Warning: clear() executed as erase() due to missing clear() in gcc
Definition String.h:372
Int allocation() const
** Casacore addition – works as a capacity(n) – Note Int
Definition String.h:347
iterator erase(iterator position)
Definition String.h:499
size_type find_last_not_of(const Char *s, size_type pos, size_type n) const
Definition String.h:689
size_type find_last_not_of(const string &str, size_type pos=npos) const
Definition String.h:685
String & operator=(Char c)
Definition String.h:294
void del(Char c, size_type startpos=0)
String & replace(iterator i1, iterator i2, Char c)
** Casacore addition
Definition String.h:534
const Char * c_str() const
Get char array.
Definition String.h:555
string::const_pointer const_pointer
Definition String.h:237
String(ostringstream &os)
Construct from a stream.
String(const SubString &str)
Construct from a SubString.
Definition String.h:277
string::reverse_iterator reverse_iterator
Definition String.h:241
size_type copy(Char *s, size_type n, size_type pos=0) const
Copy.
Definition String.h:546
SubString at(Int pos, size_type len)
Definition String.h:779
void del(const string &str, size_type startpos=0)
Delete the first occurrence of target after startpos.
SubString through(size_type pos)
Start at startpos and extract the SubString "through" to the argument's position, inclusive.
const_iterator begin() const
Definition String.h:331
String(size_type n, Char c)
Construct from a single char (repeated n times)
Definition String.h:267
SubString through(const Regex &r, size_type startpos=0)
String & insert(size_type pos1, const string &str)
Insert.
Definition String.h:443
String & replace(iterator i1, iterator i2, const string &str)
Definition String.h:525
size_type find_last_of(const string &str, size_type pos=npos) const
Definition String.h:669
size_type find(Char c, size_type pos=0) const
Definition String.h:650
String & append(size_type n, Char c)
Definition String.h:404
String & replace(iterator i1, iterator i2, const Char *s, size_type n)
Definition String.h:527
void del(Int pos, Int len)
Overload problem.
Definition String.h:864
String at(Int pos, size_type len) const
Definition String.h:782
void insert(iterator p, size_type n, Char c)
Definition String.h:460
const_reverse_iterator rend() const
Definition String.h:337
SubString operator()(size_type pos, size_type len)
Casacore addition: synonym for at(pos, len)
Definition String.h:1018
size_type length() const
Definition String.h:343
String(const string &str, size_type pos=0, size_type n=npos)
Construct from std string Construct from (part of) other string: acts as copy constructor.
Definition String.h:254
String at(Int pos, Int len) const
Definition String.h:776
Bool startsWith(const string &beginString) const
Does the string start with the specified string?
Definition String.h:638
void trim()
Remove beginning and ending whitespace.
SubString at(const Char *s, Int startpos=0)
size_type rfind(const string &str, size_type pos=npos) const
Definition String.h:653
SubString after(const Char *s, size_type startpos=0)
size_type find(const Char *s, size_type pos, size_type n) const
Definition String.h:648
SubString at(Char c, Int startpos=0)
SubString from(size_type pos)
Start at startpos and extract the SubString "from" the argument's position, inclusive,...
String & append(const string &str, size_type pos, size_type n)
Definition String.h:398
SubString before(Int pos) const
Next one for overloading reasons.
Definition String.h:797
void del(size_type pos, size_type len)
Delete len chars starting at pos.
Bool empty() const
Test for empty.
Definition String.h:375
Bool contains(Char c) const
Containment.
Definition String.h:698
string::size_type size_type
Definition String.h:231
size_type index(Char c, Int startpos=0) const
Return the position of the target in the string or npos for failure.
Definition String.h:738
void alloc(size_type n)
** Casacore addition – works as a resize(n)
Definition String.h:366
static Int toInt(const String &s, Bool chk=False)
Convert a string to an Int, Float or Double.
size_type find_first_not_of(Char c, size_type pos=0) const
Definition String.h:683
Int freq(const string &str) const
String & insert(size_type pos, Char c)
** Casacore addition
Definition String.h:455
String at(size_type pos, size_type len) const
Definition String.h:760
SubString before(size_type pos) const
Start at startpos and extract the string "before" the argument's position, exclusive.
void reverse()
Maybe forget some.
string::pointer pointer
Definition String.h:236
SubString at(const string &str, Int startpos=0)
void prepend(Char c)
SubString _substr(size_type first, size_type l) const
Helper functions for at, before etc.
Definition String.h:880
size_type find_first_of(const Char *s, size_type pos, size_type n) const
Definition String.h:665
size_type rfind(const Char *s, size_type pos=npos) const
Definition String.h:655
String & insert(iterator p, const string &str)
** Casacore additions
Definition String.h:467
Int compare(const string &str) const
Compare.
Definition String.h:481
size_type find_first_not_of(const Char *s, size_type pos, size_type n) const
Definition String.h:681
void del(const Regex &r, size_type startpos=0)
void throwFromStringError() const
Helper function for fromString.
String & assign(const string &str)
Assign.
Definition String.h:419
String & append(const string &str)
Append.
Definition String.h:396
SubString after(const Regex &r, size_type startpos=0)
Int compare(const Char *s) const
Definition String.h:488
SubString after(Char c, size_type startpos=0)
Bool matches(const Regex &r, Int pos=0) const
String & replace(size_type pos, size_type n1, const Char *s)
Definition String.h:518
string::traits_type traits_type
Definition String.h:228
String & append(InputIterator first, InputIterator last)
Definition String.h:407
size_type size() const
Capacity, size.
Definition String.h:342
size_type find(const Char *s, size_type pos=0) const
Definition String.h:646
String & assign(const string &str, size_type pos, size_type n)
Definition String.h:421
String & insert(iterator p, const Char *s)
Definition String.h:471
String & erase(size_type pos, size_type n=npos)
Erase.
Definition String.h:497
String & insert(size_type pos, size_type n, Char c)
Definition String.h:452
SubString at(const Regex &r, Int startpos=0)
String at(const Char *s, Int startpos=0) const
string::iterator iterator
Definition String.h:239
size_type rfind(Char c, size_type pos=npos) const
Definition String.h:659
String & assign(InputIterator first, InputIterator last)
Definition String.h:430
reference operator[](size_type pos)
Definition String.h:316
size_type index(const Char *s, Int startpos=0) const
Definition String.h:744
size_type find_first_of(Char c, size_type pos=0) const
Definition String.h:667
Int compare(size_type pos1, size_type n1, const Char *s, size_type n2=npos) const
Definition String.h:490
String & assign(Char c)
** Casacore addition
Definition String.h:433
void prepend(const string &str)
Concatenate by prepending the argument onto String.
reverse_iterator rend()
Definition String.h:336
static Double toDouble(const String &s, Bool chk=False)
String & reserve(size_type res_arg=0)
Definition String.h:363
String & resize(size_type n)
Resize by truncating or extending with copies of c (default Char())
Definition String.h:359
String(InputIterator begin, InputIterator end)
Construct from iterator.
Definition String.h:270
String & insert(size_type pos1, const string &str, size_type pos2, size_type n)
Definition String.h:445
Int gsub(const string &pat, const string &repl)
Global substitution: substitute all occurrences of pat with repl, and return the number of replacemen...
String()
Default constructor.
Definition String.h:248
size_type find_last_of(const Char *s, size_type pos, size_type n) const
Definition String.h:673
SubString at(size_type pos, size_type len)
Extract the string "at" the argument's position.
String & replace(iterator i1, iterator i2, InputIterator j1, InputIterator j2)
Definition String.h:537
String & replace(iterator i1, iterator i2, const Char *s)
Definition String.h:529
String & resize(size_type n, Char c)
Definition String.h:361
const_reference at(size_type n) const
Addressing.
Definition String.h:382
SubString through(const string &str, size_type startpos=0)
SubString before(const string &str, size_type startpos=0) const
String & append(Char c)
** Casacore addition
Definition String.h:410
Bool contains(const Regex &r) const
Int freq(const Char *s) const
Bool matches(Char c, Int pos=0) const
Definition String.h:721
iterator insert(iterator p, Char c)
Definition String.h:458
String & assign(const Char *s)
Definition String.h:425
SubString from(Char c, size_type startpos=0)
SubString after(size_type pos)
Start at startpos and extract the SubString "after" the argument's position, exclusive,...
const Char * chars() const
** Casacore synonym
Definition String.h:559
String & operator+=(const Char *s)
Definition String.h:303
void upcase()
internal transformation to uppercase of String
Int gsub(const Char *pat, const Char *repl)
T fromString() const
Definition String.h:593
const_iterator end() const
Definition String.h:333
String at(Char c, Int startpos=0) const
String & operator+=(Char c)
Definition String.h:305
const string & ref_p
Referenced string.
Definition String.h:86
SubString & operator=(const Char *s)
SubString & operator=(const Char c)
SubString(const SubString &)=default
Default copy constructor.
friend class String
Definition String.h:62
string::size_type length() const
Obtain length.
Definition String.h:77
SubString & operator=(const SubString &str)
Assignment.
string::size_type pos_p
Start of sub-string.
Definition String.h:88
const Char * chars() const
Get as (const) C array.
Definition String.h:1020
string::size_type len_p
Length of sub-string.
Definition String.h:90
SubString & operator=(const String &str)
struct Node * first
Definition malloc.h:328
this file contains all the compiler specific defines
Definition mainpage.dox:28
Bool operator<=(const MVTime &lh, const MVTime &rh)
Definition MVTime.h:468
const Bool False
Definition aipstype.h:42
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
TableExprNode upcase(const TableExprNode &node)
Definition ExprNode.h:1472
Vector< String > & split(const String &s, char delim, Vector< String > &elems)
LatticeExprNode operator+(const LatticeExprNode &expr)
Global functions operating on a LatticeExprNode.
unsigned int uInt
Definition aipstype.h:49
bool operator==(const casacore_allocator< T, ALIGNMENT > &, const casacore_allocator< T, ALIGNMENT > &)
Definition Allocator.h:127
bool operator!=(const casacore_allocator< T, ALIGNMENT > &, const casacore_allocator< T, ALIGNMENT > &)
Definition Allocator.h:133
TableExprNode capitalize(const TableExprNode &node)
Definition ExprNode.h:1482
TableExprNode downcase(const TableExprNode &node)
Definition ExprNode.h:1477
float Float
Definition aipstype.h:52
Bool operator<(const MVTime &lh, const MVTime &rh)
Definition MVTime.h:466
LatticeExprNode length(const LatticeExprNode &expr, const LatticeExprNode &axis)
2-argument function to get the length of an axis.
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
Bool operator>=(const MVTime &lh, const MVTime &rh)
Definition MVTime.h:472
Bool operator>(const MVTime &lh, const MVTime &rh)
Definition MVTime.h:470
TableExprNode trim(const TableExprNode &node)
Definition ExprNode.h:1588
const Bool True
Definition aipstype.h:41
double Double
Definition aipstype.h:53
char Char
Definition aipstype.h:44
Define real & complex conjugation for non-complex types and put comparisons into std namespace.
Definition Complex.h:350
Casing and related functions Case conversion and rearrangement functions
Definition String.h:993
String downcase(const string &str)
Global function which returns a transformation to lowercase of String.
String reverse(const string &str)
Global function which returns a transformation to reverse order of String.
String capitalize(const string &str)
Global function which returns a transformation to capitalization of String.
String trim(const string &str)
Global function which removes leading and trailing whitespace.
String upcase(const string &str)
Global function which returns a transformation to uppercase of String.
Some general functions Functions to find special patterns, join and replicate
Definition String.h:980
String common_prefix(const string &x, const string &y, Int startpos=0)
String common_suffix(const string &x, const string &y, Int startpos=-1)
String replicate(const string &str, String::size_type n)
String replicate(Char c, String::size_type n)
String join(string src[], Int n, const string &sep)
Global comparison operators.
Definition String.h:912
Bool operator<=(const String &x, const Char t)
Definition String.h:947
Bool operator<=(const String &x, const Char *t)
Definition String.h:935
Bool operator!=(const String &x, const String &y)
Definition String.h:915
Bool operator==(const String &x, const Char t)
Definition String.h:937
Bool operator<(const String &x, const String &y)
Definition String.h:921
Bool operator==(const String &x, const String &y)
Definition String.h:913
Bool operator>(const String &x, const String &y)
Definition String.h:917
Bool operator>=(const String &x, const String &y)
Definition String.h:919
Int compare(const string &x, const string &y)
** Casacore additions of global compares.
Definition String.h:951
Bool operator!=(const String &x, const Char t)
Definition String.h:939
Int fcompare(const String &x, const String &y)
this version ignores case.
Bool operator>=(const String &x, const Char *t)
Definition String.h:931
Bool operator>(const String &x, const Char t)
Definition String.h:941
Bool operator==(const String &x, const Char *t)
Definition String.h:925
Int compare(const string &x, const Char y)
Definition String.h:955
Bool operator>(const String &x, const Char *t)
Definition String.h:929
Bool operator<=(const String &x, const String &y)
Definition String.h:923
Bool operator>=(const String &x, const Char t)
Definition String.h:943
Bool operator<(const String &x, const Char t)
Definition String.h:945
Int compare(const string &x, const Char *y)
Definition String.h:953
Bool operator!=(const String &x, const Char *t)
Definition String.h:927
Bool operator<(const String &x, const Char *t)
Definition String.h:933
Global concatenation operators.
Definition String.h:894
String operator+(Char lhs, const String &rhs)
Definition String.h:899
String operator+(const String &lhs, const String &rhs)
Definition String.h:895
String operator+(const String &lhs, Char rhs)
Definition String.h:903
String operator+(const String &lhs, const Char *rhs)
Definition String.h:901
String operator+(const Char *lhs, const String &rhs)
Definition String.h:897
ostream & operator<<(ostream &s, const String &x)
Output.
Splitting Global function which splits the String into string array res at separator and returns the ...
Definition String.h:968
Int split(const string &str, string res[], Int maxn, const Regex &sep)
Int split(const string &str, string res[], Int maxn, const string &sep)
Int split(const string &str, string res[], Int maxn, const Char sep)
std::size_t operator()(casacore::String const &k) const noexcept
Definition String.h:1042