|
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 |
|
7 |
|
8 /** |
|
9 * computes the aggregate string length |
|
10 */ |
|
11 |
|
12 nsTSubstringTuple_CharT::size_type |
|
13 nsTSubstringTuple_CharT::Length() const |
|
14 { |
|
15 uint32_t len; |
|
16 if (mHead) |
|
17 len = mHead->Length(); |
|
18 else |
|
19 len = TO_SUBSTRING(mFragA).Length(); |
|
20 |
|
21 return len + TO_SUBSTRING(mFragB).Length(); |
|
22 } |
|
23 |
|
24 |
|
25 /** |
|
26 * writes the aggregate string to the given buffer. bufLen is assumed |
|
27 * to be equal to or greater than the value returned by the Length() |
|
28 * method. the string written to |buf| is not null-terminated. |
|
29 */ |
|
30 |
|
31 void |
|
32 nsTSubstringTuple_CharT::WriteTo( char_type *buf, uint32_t bufLen ) const |
|
33 { |
|
34 const substring_type& b = TO_SUBSTRING(mFragB); |
|
35 |
|
36 NS_ASSERTION(bufLen >= b.Length(), "buffer too small"); |
|
37 uint32_t headLen = bufLen - b.Length(); |
|
38 if (mHead) |
|
39 { |
|
40 mHead->WriteTo(buf, headLen); |
|
41 } |
|
42 else |
|
43 { |
|
44 const substring_type& a = TO_SUBSTRING(mFragA); |
|
45 |
|
46 NS_ASSERTION(a.Length() == headLen, "buffer incorrectly sized"); |
|
47 char_traits::copy(buf, a.Data(), a.Length()); |
|
48 } |
|
49 |
|
50 char_traits::copy(buf + headLen, b.Data(), b.Length()); |
|
51 |
|
52 #if 0 |
|
53 // we need to write out data into |buf|, ending at |buf+bufLen|. so our |
|
54 // data needs to precede |buf+bufLen| exactly. we trust that the buffer |
|
55 // was properly sized! |
|
56 |
|
57 const substring_type& b = TO_SUBSTRING(mFragB); |
|
58 |
|
59 NS_ASSERTION(bufLen >= b.Length(), "buffer is too small"); |
|
60 char_traits::copy(buf + bufLen - b.Length(), b.Data(), b.Length()); |
|
61 |
|
62 bufLen -= b.Length(); |
|
63 |
|
64 if (mHead) |
|
65 { |
|
66 mHead->WriteTo(buf, bufLen); |
|
67 } |
|
68 else |
|
69 { |
|
70 const substring_type& a = TO_SUBSTRING(mFragA); |
|
71 NS_ASSERTION(bufLen == a.Length(), "buffer is too small"); |
|
72 char_traits::copy(buf, a.Data(), a.Length()); |
|
73 } |
|
74 #endif |
|
75 } |
|
76 |
|
77 |
|
78 /** |
|
79 * returns true if this tuple is dependent on (i.e., overlapping with) |
|
80 * the given char sequence. |
|
81 */ |
|
82 |
|
83 bool |
|
84 nsTSubstringTuple_CharT::IsDependentOn( const char_type *start, const char_type *end ) const |
|
85 { |
|
86 // we start with the right-most fragment since it is faster to check. |
|
87 |
|
88 if (TO_SUBSTRING(mFragB).IsDependentOn(start, end)) |
|
89 return true; |
|
90 |
|
91 if (mHead) |
|
92 return mHead->IsDependentOn(start, end); |
|
93 |
|
94 return TO_SUBSTRING(mFragA).IsDependentOn(start, end); |
|
95 } |