2014-05-05 21:30:46 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2013-09-23 21:23:56 +04:00
|
|
|
// IWYU pragma: private, include "nsString.h"
|
2001-04-02 23:40:52 +04:00
|
|
|
|
|
|
|
#ifndef nsAString_h___
|
|
|
|
#define nsAString_h___
|
|
|
|
|
|
|
|
#include "nsStringFwd.h"
|
|
|
|
#include "nsStringIterator.h"
|
2017-07-10 22:23:10 +03:00
|
|
|
#include "mozilla/TypedEnumBits.h"
|
2001-04-02 23:40:52 +04:00
|
|
|
|
2004-04-25 02:02:22 +04:00
|
|
|
#include <string.h>
|
2012-04-13 20:58:59 +04:00
|
|
|
#include <stdarg.h>
|
2001-04-02 23:40:52 +04:00
|
|
|
|
2008-09-19 19:07:22 +04:00
|
|
|
#define kNotFound -1
|
|
|
|
|
2017-07-10 22:23:10 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace detail {
|
|
|
|
// NOTE: these flags are declared public _only_ for convenience inside
|
|
|
|
// the string implementation. And they are outside of the string
|
|
|
|
// class so that the type is the same for both narrow and wide
|
|
|
|
// strings.
|
|
|
|
|
|
|
|
// bits for mDataFlags
|
|
|
|
enum class StringDataFlags : uint16_t
|
|
|
|
{
|
|
|
|
// Some terminology:
|
|
|
|
//
|
|
|
|
// "dependent buffer" A dependent buffer is one that the string class
|
|
|
|
// does not own. The string class relies on some
|
|
|
|
// external code to ensure the lifetime of the
|
|
|
|
// dependent buffer.
|
|
|
|
//
|
|
|
|
// "shared buffer" A shared buffer is one that the string class
|
|
|
|
// allocates. When it allocates a shared string
|
|
|
|
// buffer, it allocates some additional space at
|
|
|
|
// the beginning of the buffer for additional
|
|
|
|
// fields, including a reference count and a
|
|
|
|
// buffer length. See nsStringHeader.
|
|
|
|
//
|
|
|
|
// "adopted buffer" An adopted buffer is a raw string buffer
|
|
|
|
// allocated on the heap (using moz_xmalloc)
|
|
|
|
// of which the string class subsumes ownership.
|
|
|
|
//
|
|
|
|
// Some comments about the string data flags:
|
|
|
|
//
|
|
|
|
// SHARED, OWNED, and FIXED are all mutually exlusive. They
|
|
|
|
// indicate the allocation type of mData. If none of these flags
|
|
|
|
// are set, then the string buffer is dependent.
|
|
|
|
//
|
|
|
|
// SHARED, OWNED, or FIXED imply TERMINATED. This is because
|
|
|
|
// the string classes always allocate null-terminated buffers, and
|
|
|
|
// non-terminated substrings are always dependent.
|
|
|
|
//
|
|
|
|
// VOIDED implies TERMINATED, and moreover it implies that mData
|
|
|
|
// points to char_traits::sEmptyBuffer. Therefore, VOIDED is
|
|
|
|
// mutually exclusive with SHARED, OWNED, and FIXED.
|
|
|
|
|
|
|
|
TERMINATED = 1 << 0, // IsTerminated returns true
|
|
|
|
VOIDED = 1 << 1, // IsVoid returns true
|
|
|
|
SHARED = 1 << 2, // mData points to a heap-allocated, shared buffer
|
|
|
|
OWNED = 1 << 3, // mData points to a heap-allocated, raw buffer
|
|
|
|
FIXED = 1 << 4, // mData points to a fixed-size writable, dependent buffer
|
|
|
|
LITERAL = 1 << 5 // mData points to a string literal; DataFlags::TERMINATED will also be set
|
|
|
|
};
|
|
|
|
|
|
|
|
// bits for mClassFlags
|
|
|
|
enum class StringClassFlags : uint16_t
|
|
|
|
{
|
2017-07-21 01:46:58 +03:00
|
|
|
FIXED = 1 << 0, // |this| is of type nsTFixedString
|
|
|
|
NULL_TERMINATED = 1 << 1 // |this| requires its buffer is null-terminated
|
2017-07-10 22:23:10 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(StringDataFlags)
|
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(StringClassFlags)
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
// declare nsAString
|
2004-02-19 05:44:03 +03:00
|
|
|
#include "string-template-def-unichar.h"
|
2008-09-19 19:07:22 +04:00
|
|
|
#include "nsTSubstring.h"
|
2004-02-19 05:44:03 +03:00
|
|
|
#include "string-template-undef.h"
|
2001-04-02 23:40:52 +04:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
// declare nsACString
|
2004-02-19 05:44:03 +03:00
|
|
|
#include "string-template-def-char.h"
|
2008-09-19 19:07:22 +04:00
|
|
|
#include "nsTSubstring.h"
|
2004-02-19 05:44:03 +03:00
|
|
|
#include "string-template-undef.h"
|
2001-04-02 23:40:52 +04:00
|
|
|
|
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
/**
|
|
|
|
* ASCII case-insensitive comparator. (for Unicode case-insensitive
|
|
|
|
* comparision, see nsUnicharUtils.h)
|
|
|
|
*/
|
2011-08-18 17:46:39 +04:00
|
|
|
class nsCaseInsensitiveCStringComparator
|
2014-05-05 21:30:46 +04:00
|
|
|
: public nsCStringComparator
|
|
|
|
{
|
|
|
|
public:
|
2014-05-27 11:15:35 +04:00
|
|
|
nsCaseInsensitiveCStringComparator()
|
|
|
|
{
|
|
|
|
}
|
2014-05-05 21:30:46 +04:00
|
|
|
typedef char char_type;
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
virtual int operator()(const char_type*, const char_type*,
|
2015-03-21 19:28:04 +03:00
|
|
|
uint32_t, uint32_t) const override;
|
2014-05-05 21:30:46 +04:00
|
|
|
};
|
2001-04-18 09:20:06 +04:00
|
|
|
|
2008-10-01 04:50:42 +04:00
|
|
|
class nsCaseInsensitiveCStringArrayComparator
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
template<class A, class B>
|
2014-05-27 11:15:35 +04:00
|
|
|
bool Equals(const A& aStrA, const B& aStrB) const
|
|
|
|
{
|
|
|
|
return aStrA.Equals(aStrB, nsCaseInsensitiveCStringComparator());
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// included here for backwards compatibility
|
2004-02-19 05:44:03 +03:00
|
|
|
#ifndef nsSubstringTuple_h___
|
|
|
|
#include "nsSubstringTuple.h"
|
2001-04-02 23:40:52 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // !defined(nsAString_h___)
|