Bumping manifests a=b2g-bump
[gecko.git] / xpcom / string / nsTDependentSubstring.h
blobdd28f32f94e8f8a9c258917a4efca050336135db
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"
8 /**
9 * nsTDependentSubstring_CharT
11 * A string class which wraps an external array of string characters. It
12 * is the client code's responsibility to ensure that the external buffer
13 * remains valid for a long as the string is alive.
15 * NAMES:
16 * nsDependentSubstring for wide characters
17 * nsDependentCSubstring for narrow characters
19 class nsTDependentSubstring_CharT : public nsTSubstring_CharT
21 public:
23 typedef nsTDependentSubstring_CharT self_type;
25 public:
27 void Rebind(const substring_type&, uint32_t aStartPos,
28 uint32_t aLength = size_type(-1));
30 void Rebind(const char_type* aData, size_type aLength);
32 void Rebind(const char_type* aStart, const char_type* aEnd)
34 Rebind(aStart, size_type(aEnd - aStart));
37 nsTDependentSubstring_CharT(const substring_type& aStr, uint32_t aStartPos,
38 uint32_t aLength = size_type(-1))
39 : substring_type()
41 Rebind(aStr, aStartPos, aLength);
44 nsTDependentSubstring_CharT(const char_type* aData, size_type aLength)
45 : substring_type(const_cast<char_type*>(aData), aLength, F_NONE)
49 nsTDependentSubstring_CharT(const char_type* aStart, const char_type* aEnd)
50 : substring_type(const_cast<char_type*>(aStart), uint32_t(aEnd - aStart),
51 F_NONE)
55 #if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER)
56 nsTDependentSubstring_CharT(char16ptr_t aData, size_type aLength)
57 : nsTDependentSubstring_CharT(static_cast<const char16_t*>(aData), aLength)
61 nsTDependentSubstring_CharT(char16ptr_t aStart, char16ptr_t aEnd)
62 : nsTDependentSubstring_CharT(static_cast<const char16_t*>(aStart),
63 static_cast<const char16_t*>(aEnd))
66 #endif
68 nsTDependentSubstring_CharT(const const_iterator& aStart,
69 const const_iterator& aEnd)
70 : substring_type(const_cast<char_type*>(aStart.get()),
71 uint32_t(aEnd.get() - aStart.get()), F_NONE)
75 // Create a nsTDependentSubstring to be bound later
76 nsTDependentSubstring_CharT()
77 : substring_type()
81 // auto-generated copy-constructor OK (XXX really?? what about base class copy-ctor?)
83 private:
84 // NOT USED
85 void operator=(const self_type&); // we're immutable, you can't assign into a substring
88 inline const nsTDependentSubstring_CharT
89 Substring(const nsTSubstring_CharT& aStr, uint32_t aStartPos,
90 uint32_t aLength = uint32_t(-1))
92 return nsTDependentSubstring_CharT(aStr, aStartPos, aLength);
95 inline const nsTDependentSubstring_CharT
96 Substring(const nsReadingIterator<CharT>& aStart,
97 const nsReadingIterator<CharT>& aEnd)
99 return nsTDependentSubstring_CharT(aStart.get(), aEnd.get());
102 inline const nsTDependentSubstring_CharT
103 Substring(const CharT* aData, uint32_t aLength)
105 return nsTDependentSubstring_CharT(aData, aLength);
108 inline const nsTDependentSubstring_CharT
109 Substring(const CharT* aStart, const CharT* aEnd)
111 return nsTDependentSubstring_CharT(aStart, aEnd);
114 inline const nsTDependentSubstring_CharT
115 StringHead(const nsTSubstring_CharT& aStr, uint32_t aCount)
117 return nsTDependentSubstring_CharT(aStr, 0, aCount);
120 inline const nsTDependentSubstring_CharT
121 StringTail(const nsTSubstring_CharT& aStr, uint32_t aCount)
123 return nsTDependentSubstring_CharT(aStr, aStr.Length() - aCount, aCount);