1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
39 /** @name MzString class
41 It was supposed to be used instead of std::string.
45 When you declare an MzString, it is initially empty. There is no need to
46 do things like #MzString a = "";#, especially not in constructors.
48 If you want to use a default empty MzString as a parameter, use
50 #void foo(MzString par = MzString()); // Correct#
54 #void foo(MzString par = ""); // WRONG!#
55 #void foo(MzString par = 0); // WRONG!#
57 (The last one is only wrong because some compilers can't handle it.)
59 Methods that take an index as parameter all follow this rule: Valid indexes
60 go from 0 to length()-1.
62 Correct: & #foo.substr(0, length()-1);# \\
63 Wrong: & #bar.substr(0, length());#
66 It is important that you declare MzStrings as const if possible, because
67 some methods are much more efficient in const versions.
69 If you want to check whether a string is empty, do
71 #if (foo.empty()) something right#
73 rather than something along the lines of
75 #if (!foo) completely wrong#
77 When you use the #.copy()# method, MzString calls "#new []#", so you have to
78 release the memory with #delete[]#. Don't preallocate memory.
80 When you want to copy an MzString, just do
82 #MzString a, b = "String";#
83 #a = b; // That's it!#
87 #MzString a, b = "String";#
90 The class automatically handles deep copying when required.
96 MzString(); // Create an empty string
97 // if len = 0, len becomes s.length)
98 MzString(MzString
const &s
, int len
= 0);
102 const char* c_str() const;
103 operator char*() { return (char *)c_str(); }
105 // If it is not posible to use the constructor with an initial
106 // allocation size, use the following member to set the size.
107 bool resize(int len
);
110 void operator = (MzString
&s
);
111 void operator = (const char *s
);
114 MzString
&operator += (char);
115 MzString
&operator += (const char *);
116 MzString
&operator += (MzString
const &);
118 MzString
&operator << (const char *);
119 MzString
&operator << (char);
120 MzString
&operator << (unsigned char c
) { return *this<<(char)c
; }
121 MzString
&operator << (int);
122 MzString
&operator << (long);
123 MzString
&operator << (short i
) { return *this<<(int)i
; }
124 MzString
&operator << (MzString
const &);
125 /* MzString &operator << (MzString *s) { return *this<<*s; }
128 char operator >> (char &c);
130 // Access to specific characters
131 //char &operator [] (int n);
132 char operator [] (int n
);
137 // 0 : 'this' is equal to 's'.
138 // -1 : 'this' is less than 's'.
139 // 1 : 'this' is greater than 's'.
140 int compare(const char *s
);
142 // Searching for parts
144 int find (char c
, int pos
);
146 int find (char *, int pos
);
148 int rfind (char c
, int pos
);
151 void replace(int, char c
);
153 void append (MzString
const &s
);
154 void append (const char *s
);
155 void append (const char *s
, int n
);
158 int Length
; // Current Length
159 int Allocated
; // Total space allocated
160 char *Data
; // The actual contents
162 // Allocate some space for the data.
163 // Delete Data if it has been allocated.
164 bool allocate(int len
);
167 inline int MzString::length() const
173 inline const char* MzString::c_str() const
177 Data
[Length
] = '\0'; // We always leave room for this.
178 return (const char *)Data
;
185 // Non friend, non member operators
187 #endif /* _MZSTRING_H_ */