source: CMT/v1r18p20041201/source/cmt_string.h @ 1

Last change on this file since 1 was 1, checked in by arnault, 19 years ago

Import all tags

File size: 3.2 KB
Line 
1//-----------------------------------------------------------
2// Copyright Christian Arnault LAL-Orsay CNRS
3// arnault@lal.in2p3.fr
4// See the complete license in cmt_license.txt "http://www.cecill.info".
5//-----------------------------------------------------------
6
7#ifndef __cmt_string_h__
8#define __cmt_string_h__
9
10#include <stdio.h>
11#include <string.h>
12
13class cmt_string
14{
15public:
16  typedef enum
17    {
18      npos = -1
19    } pos_type;
20
21    //
22    // Constructors
23    //
24  cmt_string ();
25  cmt_string (int n);
26  cmt_string (char c);
27  cmt_string (const char* text);
28  cmt_string (const cmt_string& other);
29  ~cmt_string ();
30
31    //
32    // Operators
33    //
34  cmt_string& operator = (char c);
35  cmt_string& operator = (const char* text);
36  cmt_string& operator = (const cmt_string& other);
37
38  bool read (const cmt_string& file_name);
39  bool write (const cmt_string& file_name) const;
40  void write (FILE* f) const;
41  void write (ostream& output);
42
43  operator const char* () const;
44
45  const char* c_str () const;
46  /*char* c_str (); */
47
48  void operator += (char c);
49  void operator += (const char* text);
50  void operator += (const cmt_string& other);
51
52  cmt_string operator + (char c) const;
53  cmt_string operator + (const char* text) const;
54  cmt_string operator + (const cmt_string& other) const;
55
56  char operator [] (int index) const;
57  char& operator [] (int index);
58
59  int size () const;
60  int size ();
61  void resize (int n);
62
63  int find (char c) const;
64  int find (const char* text) const;
65  int find (const cmt_string& other) const;
66  int find (int pos, char c) const;
67  int find (int pos, const char* text) const;
68  int find (int pos, const cmt_string& other) const;
69
70  int find_last_of (char c) const;
71  int find_last_of (const char* text) const;
72  int find_last_of (const cmt_string& other) const;
73
74  void erase (int pos);
75  void erase (int pos, int length);
76
77  void replace (const char* pattern, const char* replacement);
78  void replace (const cmt_string& pattern, const cmt_string& replacement);
79
80  void replace_all (const char* pattern, const char* replacement);
81  void replace_all (const cmt_string& pattern, const cmt_string& replacement);
82
83  void trim ();
84
85  cmt_string substr (int pos) const;
86  cmt_string substr (int pos, int length) const;
87
88  void substr (int pos, cmt_string& dest) const;
89  void substr (int pos, int length, cmt_string& dest) const;
90
91  bool operator < (const char* text) const;
92  bool operator < (const cmt_string& other) const;
93
94  bool operator == (const char* text) const;
95  bool operator == (const cmt_string& other) const;
96
97  bool compare_no_case (const char* text) const;
98  bool compare_no_case (const cmt_string& other) const;
99
100  bool operator != (const char* text) const;
101  bool operator != (const cmt_string& other) const;
102
103  bool operator > (const char* text) const;
104  bool operator > (const cmt_string& other) const;
105
106private:
107  void extend (int n);
108  void allocate (int n);
109
110  char* _data;
111  int _allocated;
112  int _size;
113};
114
115ostream& operator << (ostream& o, const cmt_string& s);
116cmt_string operator + (const char* text, const cmt_string& s);
117cmt_string operator + (char c, const cmt_string& s);
118
119#endif
Note: See TracBrowser for help on using the repository browser.