]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/string.hh
*** empty log message ***
[lilypond.git] / flower / include / string.hh
1 /*
2   FILE   : string.hh -- declare String
3
4   Rehacked by HWN 3/nov/95
5   removed String & 's
6   introduced Class String_handle
7 */
8
9 #ifndef STD_STRING_HH
10 #error string.hh is obsolete, use std-string.hh
11 #endif
12
13 #ifndef STRING_HH
14 #define STRING_HH
15
16 // too darn slow with gcc3
17 #ifdef STREAM_SUPPORT
18 #if (__GNUC__ > 2)
19 #include <iostream>
20 #else
21 class ostream;
22 #endif
23 #endif
24
25 #include "arithmetic-operator.hh"
26 #include "string-handle.hh"
27
28 namespace std {
29
30 class String
31 {
32 public:
33
34   /* partial std::string interface */
35   String ();
36   String (int n, char c);
37   String (char const *source);
38   String (char const *, int n);
39   String (String const &, int pos, ssize n=NPOS);
40
41   String &operator = (String const &source);
42   /// concatenate s
43   void operator += (char const *s) { strh_ += s; }
44   void operator += (String s);
45   char &operator [] (int n);
46   char operator [] (int n) const;
47
48
49   char const *c_str () const;
50   char const *data () const;
51   bool empty () const;
52   int find (String s, int pos=0) const;
53   int find (char c, int pos=0) const;
54   int find (char const *c, int pos=0) const;
55   int rfind (char c) const;
56   String replace (int pos, int n, String str);
57
58   String substr (int pos=0, ssize n=NPOS) const;
59   int compare (String const &s) const;
60
61   void append (String);
62   int length () const;
63
64   String insert (ssize pos, String);
65   ssize copy (char *s, ssize n, ssize pos=0) const;
66
67 protected:
68   String_handle strh_;
69
70   bool null_terminated ();
71
72 private:
73   ///  return "new"-ed copy of contents
74   Byte *get_copy_byte () const;
75   char *get_copy_str0 () const;
76
77   Byte const *to_bytes () const;
78   Byte *get_bytes ();
79
80   void prepend (String);
81
82   /// return n leftmost chars
83   String left_string (int n) const;
84
85   /// return n rightmost chars
86   String right_string (int n) const;
87
88   /// return a piece starting at index (first char = index_i 0), length n
89   String cut_string (int index_i, int n) const;
90
91   /// cut out a middle piece, return remainder
92   String nomid_string (int index_i, int n) const;
93
94   static int compare (String const &s1, const String &s2);
95
96   /// index of rightmost character C in string
97   int index_last (char c) const;
98   
99   int index (char c) const;
100
101   /// index of leftmost occurance of STRING
102   int index (String) const;
103
104   int index_any (String) const;
105
106 #ifdef STREAM_SUPPORT
107   /// provide Stream output
108   void print_on (ostream &os) const;
109 #endif
110
111   /// convert to an integer
112   int to_int () const;
113
114   /// convert to a double
115   double to_double () const;
116
117   String substitute (String find, String replace);
118   String substitute (char find, char replace);
119 };
120
121 #ifdef STRING_UTILS_INLINED
122 #ifndef INLINE
123 #define INLINE inline
124 #endif
125 #include "string.icc"
126 /* we should be resetting INLINE. oh well. */
127 #endif
128
129 // because char const* also has an operator ==, this is for safety:
130 bool operator == (String s1, char const *s2);
131 bool operator == (char const *s1, String s2);
132 bool operator != (String s1, char const *s2);
133 bool operator != (char const *s1, String s2);
134
135 IMPLEMENT_ARITHMETIC_OPERATOR (String, +);
136 #ifdef STREAM_SUPPORT
137 ostream &operator << (ostream &os, String d);
138 #endif
139
140 }
141
142 /*
143   technically incorrect, but lets keep it here: this is a
144   catch all place for this stuff.
145 */
146 #include "international.hh"
147
148
149 #endif /* STRING_HH */