|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
|
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 /** |
|
9 * nsTDependentSubstring_CharT |
|
10 * |
|
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. |
|
14 * |
|
15 * NAMES: |
|
16 * nsDependentSubstring for wide characters |
|
17 * nsDependentCSubstring for narrow characters |
|
18 */ |
|
19 class nsTDependentSubstring_CharT : public nsTSubstring_CharT |
|
20 { |
|
21 public: |
|
22 |
|
23 typedef nsTDependentSubstring_CharT self_type; |
|
24 |
|
25 public: |
|
26 |
|
27 void Rebind( const substring_type&, uint32_t startPos, uint32_t length = size_type(-1) ); |
|
28 |
|
29 void Rebind( const char_type* data, size_type length ); |
|
30 |
|
31 void Rebind( const char_type* start, const char_type* end ) |
|
32 { |
|
33 Rebind(start, size_type(end - start)); |
|
34 } |
|
35 |
|
36 nsTDependentSubstring_CharT( const substring_type& str, uint32_t startPos, uint32_t length = size_type(-1) ) |
|
37 : substring_type() |
|
38 { |
|
39 Rebind(str, startPos, length); |
|
40 } |
|
41 |
|
42 nsTDependentSubstring_CharT( const char_type* data, size_type length ) |
|
43 : substring_type(const_cast<char_type*>(data), length, F_NONE) {} |
|
44 |
|
45 nsTDependentSubstring_CharT( const char_type* start, const char_type* end ) |
|
46 : substring_type(const_cast<char_type*>(start), uint32_t(end - start), F_NONE) {} |
|
47 |
|
48 #if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER) |
|
49 nsTDependentSubstring_CharT( char16ptr_t data, size_type length ) |
|
50 : nsTDependentSubstring_CharT(static_cast<const char16_t*>(data), length) {} |
|
51 |
|
52 nsTDependentSubstring_CharT( char16ptr_t start, char16ptr_t end ) |
|
53 : nsTDependentSubstring_CharT(static_cast<const char16_t*>(start), static_cast<const char16_t*>(end)) {} |
|
54 #endif |
|
55 |
|
56 nsTDependentSubstring_CharT( const const_iterator& start, const const_iterator& end ) |
|
57 : substring_type(const_cast<char_type*>(start.get()), uint32_t(end.get() - start.get()), F_NONE) {} |
|
58 |
|
59 // Create a nsTDependentSubstring to be bound later |
|
60 nsTDependentSubstring_CharT() |
|
61 : substring_type() {} |
|
62 |
|
63 // auto-generated copy-constructor OK (XXX really?? what about base class copy-ctor?) |
|
64 |
|
65 private: |
|
66 // NOT USED |
|
67 void operator=( const self_type& ); // we're immutable, you can't assign into a substring |
|
68 }; |
|
69 |
|
70 inline |
|
71 const nsTDependentSubstring_CharT |
|
72 Substring( const nsTSubstring_CharT& str, uint32_t startPos, uint32_t length = uint32_t(-1) ) |
|
73 { |
|
74 return nsTDependentSubstring_CharT(str, startPos, length); |
|
75 } |
|
76 |
|
77 inline |
|
78 const nsTDependentSubstring_CharT |
|
79 Substring( const nsReadingIterator<CharT>& start, const nsReadingIterator<CharT>& end ) |
|
80 { |
|
81 return nsTDependentSubstring_CharT(start.get(), end.get()); |
|
82 } |
|
83 |
|
84 inline |
|
85 const nsTDependentSubstring_CharT |
|
86 Substring( const CharT* data, uint32_t length ) |
|
87 { |
|
88 return nsTDependentSubstring_CharT(data, length); |
|
89 } |
|
90 |
|
91 inline |
|
92 const nsTDependentSubstring_CharT |
|
93 Substring( const CharT* start, const CharT* end ) |
|
94 { |
|
95 return nsTDependentSubstring_CharT(start, end); |
|
96 } |
|
97 |
|
98 inline |
|
99 const nsTDependentSubstring_CharT |
|
100 StringHead( const nsTSubstring_CharT& str, uint32_t count ) |
|
101 { |
|
102 return nsTDependentSubstring_CharT(str, 0, count); |
|
103 } |
|
104 |
|
105 inline |
|
106 const nsTDependentSubstring_CharT |
|
107 StringTail( const nsTSubstring_CharT& str, uint32_t count ) |
|
108 { |
|
109 return nsTDependentSubstring_CharT(str, str.Length() - count, count); |
|
110 } |