Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 : // IWYU pragma: private, include "nsString.h"
7 :
8 : #ifndef nsAString_h___
9 : #define nsAString_h___
10 :
11 : #include "nsStringFwd.h"
12 : #include "nsStringIterator.h"
13 : #include "mozilla/TypedEnumBits.h"
14 :
15 : #include <string.h>
16 : #include <stdarg.h>
17 :
18 : #define kNotFound -1
19 :
20 : namespace mozilla {
21 : namespace detail {
22 : // NOTE: these flags are declared public _only_ for convenience inside
23 : // the string implementation. And they are outside of the string
24 : // class so that the type is the same for both narrow and wide
25 : // strings.
26 :
27 : // bits for mDataFlags
28 : enum class StringDataFlags : uint16_t
29 : {
30 : // Some terminology:
31 : //
32 : // "dependent buffer" A dependent buffer is one that the string class
33 : // does not own. The string class relies on some
34 : // external code to ensure the lifetime of the
35 : // dependent buffer.
36 : //
37 : // "shared buffer" A shared buffer is one that the string class
38 : // allocates. When it allocates a shared string
39 : // buffer, it allocates some additional space at
40 : // the beginning of the buffer for additional
41 : // fields, including a reference count and a
42 : // buffer length. See nsStringHeader.
43 : //
44 : // "adopted buffer" An adopted buffer is a raw string buffer
45 : // allocated on the heap (using moz_xmalloc)
46 : // of which the string class subsumes ownership.
47 : //
48 : // Some comments about the string data flags:
49 : //
50 : // SHARED, OWNED, and FIXED are all mutually exlusive. They
51 : // indicate the allocation type of mData. If none of these flags
52 : // are set, then the string buffer is dependent.
53 : //
54 : // SHARED, OWNED, or FIXED imply TERMINATED. This is because
55 : // the string classes always allocate null-terminated buffers, and
56 : // non-terminated substrings are always dependent.
57 : //
58 : // VOIDED implies TERMINATED, and moreover it implies that mData
59 : // points to char_traits::sEmptyBuffer. Therefore, VOIDED is
60 : // mutually exclusive with SHARED, OWNED, and FIXED.
61 :
62 : TERMINATED = 1 << 0, // IsTerminated returns true
63 : VOIDED = 1 << 1, // IsVoid returns true
64 : SHARED = 1 << 2, // mData points to a heap-allocated, shared buffer
65 : OWNED = 1 << 3, // mData points to a heap-allocated, raw buffer
66 : FIXED = 1 << 4, // mData points to a fixed-size writable, dependent buffer
67 : LITERAL = 1 << 5 // mData points to a string literal; DataFlags::TERMINATED will also be set
68 : };
69 :
70 : // bits for mClassFlags
71 : enum class StringClassFlags : uint16_t
72 : {
73 : FIXED = 1 << 0 // indicates that |this| is of type nsTFixedString
74 : };
75 :
76 6738638 : MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(StringDataFlags)
77 145273 : MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(StringClassFlags)
78 :
79 : } // namespace detail
80 : } // namespace mozilla
81 :
82 : // declare nsAString
83 : #include "string-template-def-unichar.h"
84 : #include "nsTSubstring.h"
85 : #include "string-template-undef.h"
86 :
87 : // declare nsACString
88 : #include "string-template-def-char.h"
89 : #include "nsTSubstring.h"
90 : #include "string-template-undef.h"
91 :
92 :
93 : /**
94 : * ASCII case-insensitive comparator. (for Unicode case-insensitive
95 : * comparision, see nsUnicharUtils.h)
96 : */
97 : class nsCaseInsensitiveCStringComparator
98 : : public nsCStringComparator
99 : {
100 : public:
101 314 : nsCaseInsensitiveCStringComparator()
102 314 : {
103 314 : }
104 : typedef char char_type;
105 :
106 : virtual int operator()(const char_type*, const char_type*,
107 : uint32_t, uint32_t) const override;
108 : };
109 :
110 : class nsCaseInsensitiveCStringArrayComparator
111 : {
112 : public:
113 : template<class A, class B>
114 0 : bool Equals(const A& aStrA, const B& aStrB) const
115 : {
116 0 : return aStrA.Equals(aStrB, nsCaseInsensitiveCStringComparator());
117 : }
118 : };
119 :
120 : // included here for backwards compatibility
121 : #ifndef nsSubstringTuple_h___
122 : #include "nsSubstringTuple.h"
123 : #endif
124 :
125 : #endif // !defined(nsAString_h___)
|