merged tag ooo/DEV300_m102
[LibreOffice.git] / hwpfilter / source / mzstring.h
blobf0a8470851382543fa342c09ac53e1de8d74dfa0
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 ************************************************************************/
28 #ifndef _MZSTRING_H_
29 #define _MZSTRING_H_
31 #ifdef __GNUG__
32 # pragma interface
33 #endif
35 #ifdef HAVE_CONFIG_H
36 # include "config.h"
37 #endif
39 /** @name MzString class
41 It was supposed to be used instead of std::string.
43 Notes for usage:
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#
52 rather than
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.
61 \begin{tabular}{rl}
62 Correct: & #foo.substr(0, length()-1);# \\
63 Wrong: & #bar.substr(0, length());#
64 \end{tabular}
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!#
85 not something like
87 #MzString a, b = "String";#
88 #a = b.copy();#
90 The class automatically handles deep copying when required.
93 class MzString
95 public:
96 MzString(); // Create an empty string
97 // if len = 0, len becomes s.length)
98 MzString(MzString const &s, int len = 0);
99 ~MzString();
101 int length() const;
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);
109 // Assignment
110 void operator = (MzString &s);
111 void operator = (const char *s);
113 // Appending
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; }
127 // Removing
128 char operator >> (char &c);
130 // Access to specific characters
131 //char &operator [] (int n);
132 char operator [] (int n);
133 char last();
135 // Comparison
136 // Return:
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
143 int find (char c);
144 int find (char c, int pos);
145 int find (char *);
146 int find (char *, int pos);
147 int rfind (char c);
148 int rfind (char c, int pos);
150 // Manipulation
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);
157 private:
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
169 return Length;
173 inline const char* MzString::c_str() const
175 if (Data)
177 Data[Length] = '\0'; // We always leave room for this.
178 return (const char *)Data;
179 } else
180 return "";
185 // Non friend, non member operators
187 #endif /* _MZSTRING_H_ */