[en_US] Added 13 autocorrect words
[LibreOffice.git] / hwpfilter / source / mzstring.h
blob0726d5bb55e030abffa00d42f8399921714f8941
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_HWPFILTER_SOURCE_MZSTRING_H
21 #define INCLUDED_HWPFILTER_SOURCE_MZSTRING_H
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 /** @name MzString class
29 It was supposed to be used instead of std::string.
31 Notes for usage:
33 When you declare an MzString, it is initially empty. There is no need to
34 do things like #MzString a = "";#, especially not in constructors.
36 If you want to use a default empty MzString as a parameter, use
38 #void foo(MzString par = MzString()); // Correct#
40 rather than
42 #void foo(MzString par = ""); // WRONG!#
43 #void foo(MzString par = 0); // WRONG!#
45 (The last one is only wrong because some compilers can't handle it.)
47 Methods that take an index as parameter all follow this rule: Valid indexes
48 go from 0 to length()-1.
49 \begin{tabular}{rl}
50 Correct: & #foo.substr(0, length()-1);# \\
51 Wrong: & #bar.substr(0, length());#
52 \end{tabular}
54 It is important that you declare MzStrings as const if possible, because
55 some methods are much more efficient in const versions.
57 If you want to check whether a string is empty, do
59 #if (foo.empty()) something right#
61 rather than something along the lines of
63 #if (!foo) completely wrong#
65 When you use the #.copy()# method, MzString calls "#new []#", so you have to
66 release the memory with #delete[]#. Don't preallocate memory.
68 When you want to copy an MzString, just do
70 #MzString a, b = "String";#
71 #a = b; // That's it!#
73 not something like
75 #MzString a, b = "String";#
76 #a = b.copy();#
78 The class automatically handles deep copying when required.
81 class MzString
83 public:
84 MzString(); // Create an empty string
85 ~MzString();
87 int length() const;
88 const char* c_str() const;
89 operator char*() { return const_cast<char *>(c_str()); }
91 // Assignment
92 MzString &operator = (const MzString &s);
93 MzString &operator = (const char *s);
95 // Appending
97 MzString &operator << (const char *);
98 MzString &operator << (char);
99 MzString &operator << (unsigned char c) { return *this<<static_cast<char>(c); }
100 MzString &operator << (int);
101 MzString &operator << (long);
102 MzString &operator << (short i) { return *this<<static_cast<int>(i); }
103 MzString &operator << (MzString const &);
104 /* MzString &operator << (MzString *s) { return *this<<*s; }
106 // Removing
107 char operator >> (char &c);
109 // Access to specific characters
110 //char &operator [] (int n);
111 char operator [] (int n);
113 // Comparison
114 // Return:
115 // 0 : 'this' is equal to 's'.
116 // -1 : 'this' is less than 's'.
117 // 1 : 'this' is greater than 's'.
118 int compare(const char *s);
120 // Searching for parts
121 int find (char c);
122 int find (char c, int pos);
123 int rfind (char c);
124 int rfind (char c, int pos);
126 // Manipulation
127 void replace(int, char c);
129 void append (MzString const &s);
130 void append (const char *s);
131 void append (const char *s, int n);
133 private:
134 int Length; // Current Length
135 int Allocated; // Total space allocated
136 char *Data; // The actual contents
138 // Allocate some space for the data.
139 // Delete Data if it has been allocated.
140 bool allocate(int len);
143 inline int MzString::length() const
145 return Length;
149 inline const char* MzString::c_str() const
151 if (Data)
153 Data[Length] = '\0'; // We always leave room for this.
154 return Data;
156 else
157 return "";
162 // Non friend, non member operators
164 #endif // INCLUDED_HWPFILTER_SOURCE_MZSTRING_H
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */