Bump for 3.6-28
[LibreOffice.git] / hwpfilter / source / mzstring.h
blob699c7cb1845759789fe051024286b23f410398a2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef _MZSTRING_H_
30 #define _MZSTRING_H_
32 #ifdef HAVE_CONFIG_H
33 # include "config.h"
34 #endif
36 /** @name MzString class
38 It was supposed to be used instead of std::string.
40 Notes for usage:
42 When you declare an MzString, it is initially empty. There is no need to
43 do things like #MzString a = "";#, especially not in constructors.
45 If you want to use a default empty MzString as a parameter, use
47 #void foo(MzString par = MzString()); // Correct#
49 rather than
51 #void foo(MzString par = ""); // WRONG!#
52 #void foo(MzString par = 0); // WRONG!#
54 (The last one is only wrong because some compilers can't handle it.)
56 Methods that take an index as parameter all follow this rule: Valid indexes
57 go from 0 to length()-1.
58 \begin{tabular}{rl}
59 Correct: & #foo.substr(0, length()-1);# \\
60 Wrong: & #bar.substr(0, length());#
61 \end{tabular}
63 It is important that you declare MzStrings as const if possible, because
64 some methods are much more efficient in const versions.
66 If you want to check whether a string is empty, do
68 #if (foo.empty()) something right#
70 rather than something along the lines of
72 #if (!foo) completely wrong#
74 When you use the #.copy()# method, MzString calls "#new []#", so you have to
75 release the memory with #delete[]#. Don't preallocate memory.
77 When you want to copy an MzString, just do
79 #MzString a, b = "String";#
80 #a = b; // That's it!#
82 not something like
84 #MzString a, b = "String";#
85 #a = b.copy();#
87 The class automatically handles deep copying when required.
90 class MzString
92 public:
93 MzString(); // Create an empty string
94 // if len = 0, len becomes s.length)
95 MzString(MzString const &s, int len = 0);
96 ~MzString();
98 int length() const;
99 const char* c_str() const;
100 operator char*() { return (char *)c_str(); }
102 // If it is not posible to use the constructor with an initial
103 // allocation size, use the following member to set the size.
104 bool resize(int len);
106 // Assignment
107 MzString &operator = (MzString &s);
108 MzString &operator = (const char *s);
110 // Appending
111 MzString &operator += (char);
112 MzString &operator += (const char *);
113 MzString &operator += (MzString const &);
115 MzString &operator << (const char *);
116 MzString &operator << (char);
117 MzString &operator << (unsigned char c) { return *this<<(char)c; }
118 MzString &operator << (int);
119 MzString &operator << (long);
120 MzString &operator << (short i) { return *this<<(int)i; }
121 MzString &operator << (MzString const &);
122 /* MzString &operator << (MzString *s) { return *this<<*s; }
124 // Removing
125 char operator >> (char &c);
127 // Access to specific characters
128 //char &operator [] (int n);
129 char operator [] (int n);
130 char last();
132 // Comparison
133 // Return:
134 // 0 : 'this' is equal to 's'.
135 // -1 : 'this' is less than 's'.
136 // 1 : 'this' is greater than 's'.
137 int compare(const char *s);
139 // Searching for parts
140 int find (char c);
141 int find (char c, int pos);
142 int find (char *);
143 int find (char *, int pos);
144 int rfind (char c);
145 int rfind (char c, int pos);
147 // Manipulation
148 void replace(int, char c);
150 void append (MzString const &s);
151 void append (const char *s);
152 void append (const char *s, int n);
154 private:
155 int Length; // Current Length
156 int Allocated; // Total space allocated
157 char *Data; // The actual contents
159 // Allocate some space for the data.
160 // Delete Data if it has been allocated.
161 bool allocate(int len);
164 inline int MzString::length() const
166 return Length;
170 inline const char* MzString::c_str() const
172 if (Data)
174 Data[Length] = '\0'; // We always leave room for this.
175 return (const char *)Data;
176 } else
177 return "";
182 // Non friend, non member operators
184 #endif /* _MZSTRING_H_ */
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */