source: CMT/v1r25/source/cmt_string.h

Last change on this file was 610, checked in by rybkin, 12 years ago

See C.L. 485

  • Property svn:eol-style set to native
File size: 3.1 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 char* text, int n);
29  cmt_string (const cmt_string& other);
30  ~cmt_string ();
31
32    //
33    // Operators
34    //
35  cmt_string& operator = (char c);
36  cmt_string& operator = (const char* text);
37  cmt_string& operator = (const cmt_string& other);
38
39  bool read (const cmt_string& file_name);
40  bool write (const cmt_string& file_name) const;
41  void write (FILE* f) const;
42  void write (ostream& output);
43
44  operator const char* () const;
45
46  const char* c_str () const;
47  /*char* c_str (); */
48
49  void operator += (char c);
50  void operator += (const char* text);
51  void operator += (const cmt_string& other);
52
53  cmt_string operator + (char c) const;
54  cmt_string operator + (const char* text) const;
55  cmt_string operator + (const cmt_string& other) const;
56
57  char operator [] (int index) const;
58  char& operator [] (int index);
59
60  int size () const;
61  int size ();
62  void resize (int n);
63
64  int find (char c) const;
65  int find (const char* text) const;
66  int find (const cmt_string& other) const;
67  int find (int pos, char c) const;
68  int find (int pos, const char* text) const;
69  int find (int pos, const cmt_string& other) const;
70
71  int find_last_of (char c) const;
72  int find_last_of (const char* text) const;
73  int find_last_of (const cmt_string& other) const;
74
75  void erase (int pos);
76  void erase (int pos, int length);
77
78  void replace (const char* pattern, const char* replacement);
79  void replace (const cmt_string& pattern, const cmt_string& replacement);
80
81  void replace_all (const char* pattern, const char* replacement);
82  void replace_all (const cmt_string& pattern, const cmt_string& replacement);
83
84  void trim ();
85
86  cmt_string substr (int pos) const;
87  cmt_string substr (int pos, int length) const;
88
89  void substr (int pos, cmt_string& dest) const;
90  void substr (int pos, int length, cmt_string& dest) const;
91
92  bool operator < (const char* text) const;
93  bool operator < (const cmt_string& other) const;
94
95  bool operator == (const char* text) const;
96  bool operator == (const cmt_string& other) const;
97
98  bool compare_no_case (const char* text) const;
99  bool compare_no_case (const cmt_string& other) const;
100
101  bool operator != (const char* text) const;
102  bool operator != (const cmt_string& other) const;
103
104  bool operator > (const char* text) const;
105  bool operator > (const cmt_string& other) const;
106
107private:
108  void extend (int n);
109  void allocate (int n);
110
111  char* _data;
112  int _allocated;
113  int _size;
114};
115
116ostream& operator << (ostream& o, const cmt_string& s);
117cmt_string operator + (const char* text, const cmt_string& s);
118cmt_string operator + (char c, const cmt_string& s);
119
120#endif
Note: See TracBrowser for help on using the repository browser.