nss: upgrade to release 3.73
[LibreOffice.git] / hwpfilter / source / mzstring.h
blob475ab31e283b75dd3de3ee0cc2465aa7f6a1dc5f
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
26 #include <tools/long.hxx>
28 /** @name MzString class
30 It was supposed to be used instead of std::string.
32 Notes for usage:
34 When you declare an MzString, it is initially empty. There is no need to
35 do things like #MzString a = "";#, especially not in constructors.
37 If you want to use a default empty MzString as a parameter, use
39 #void foo(MzString par = MzString()); // Correct#
41 rather than
43 #void foo(MzString par = ""); // WRONG!#
44 #void foo(MzString par = 0); // WRONG!#
46 (The last one is only wrong because some compilers can't handle it.)
48 Methods that take an index as parameter all follow this rule: Valid indexes
49 go from 0 to length()-1.
50 \begin{tabular}{rl}
51 Correct: & #foo.substr(0, length()-1);# \\
52 Wrong: & #bar.substr(0, length());#
53 \end{tabular}
55 It is important that you declare MzStrings as const if possible, because
56 some methods are much more efficient in const versions.
58 If you want to check whether a string is empty, do
60 #if (foo.empty()) something right#
62 rather than something along the lines of
64 #if (!foo) completely wrong#
66 When you use the #.copy()# method, MzString calls "#new []#", so you have to
67 release the memory with #delete[]#. Don't preallocate memory.
69 When you want to copy an MzString, just do
71 #MzString a, b = "String";#
72 #a = b; // That's it!#
74 not something like
76 #MzString a, b = "String";#
77 #a = b.copy();#
79 The class automatically handles deep copying when required.
82 class MzString
84 public:
85 MzString(); // Create an empty string
86 ~MzString();
88 int length() const;
89 const char* c_str() const;
90 operator char*() { return const_cast<char *>(c_str()); }
92 // Assignment
93 MzString &operator = (const MzString &s);
94 MzString &operator = (const char *s);
96 // Appending
98 MzString &operator << (const char *);
99 MzString &operator << (char);
100 MzString &operator << (unsigned char c) { return *this<<static_cast<char>(c); }
101 MzString &operator << (int);
102 MzString &operator << (tools::Long);
103 MzString &operator << (short i) { return *this<<static_cast<int>(i); }
104 MzString &operator << (MzString const &);
105 /* MzString &operator << (MzString *s) { return *this<<*s; }
107 // Removing
108 char operator >> (char &c);
110 // Access to specific characters
111 //char &operator [] (int n);
112 char operator [] (int n);
114 // Comparison
115 // Return:
116 // 0 : 'this' is equal to 's'.
117 // -1 : 'this' is less than 's'.
118 // 1 : 'this' is greater than 's'.
119 int compare(const char *s);
121 // Searching for parts
122 int find (char c);
123 int find (char c, int pos);
124 int rfind (char c);
125 int rfind (char c, int pos);
127 // Manipulation
128 void replace(int, char c);
130 void append (MzString const &s);
131 void append (const char *s);
132 void append (const char *s, int n);
134 private:
135 int Length; // Current Length
136 int Allocated; // Total space allocated
137 char *Data; // The actual contents
139 // Allocate some space for the data.
140 // Delete Data if it has been allocated.
141 bool allocate(int len);
144 inline int MzString::length() const
146 return Length;
150 inline const char* MzString::c_str() const
152 if (Data)
154 Data[Length] = '\0'; // We always leave room for this.
155 return Data;
157 else
158 return "";
163 // Non friend, non member operators
165 #endif // INCLUDED_HWPFILTER_SOURCE_MZSTRING_H
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */