1
/* Based on nsURLParsers.cc from Mozilla
2
* -------------------------------------
3
* Copyright (C) 1998 Netscape Communications Corporation.
4
* Copyright (C) 2012 Apple Inc. All rights reserved.
7
* Darin Fisher (original author)
9
* This library is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU Lesser General Public
11
* License as published by the Free Software Foundation; either
12
* version 2.1 of the License, or (at your option) any later version.
14
* This library is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
* Lesser General Public License for more details.
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with this library; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
* Alternatively, the contents of this file may be used under the terms
24
* of either the Mozilla Public License Version 1.1, found at
25
* http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
26
* License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
27
* (the "GPL"), in which case the provisions of the MPL or the GPL are
28
* applicable instead of those above. If you wish to allow use of your
29
* version of this file only under the terms of one of those two
30
* licenses (the MPL or the GPL) and not to allow others to use your
31
* version of this file under the LGPL, indicate your decision by
32
* deletingthe provisions above and replace them with the notice and
33
* other provisions required by the MPL or the GPL, as the case may be.
34
* If you do not delete the provisions above, a recipient may use your
35
* version of this file under any of the LGPL, the MPL or the GPL.
39
#include "URLSegments.h"
45
int URLSegments::length() const
47
if (fragment.isValid())
48
return fragment.end();
49
return charactersBefore(Fragment, DelimiterExcluded);
52
int URLSegments::charactersBefore(ComponentType type, DelimiterInclusion includeDelimiter) const
55
return scheme.begin();
59
current = scheme.end() + 1; // Advance over the ':' at the end of the scheme.
61
if (username.isValid()) {
63
return username.begin();
64
current = username.end() + 1; // Advance over the '@' or ':' at the end.
67
if (password.isValid()) {
69
return password.begin();
70
current = password.end() + 1; // Advance over the '@' at the end.
80
if (type < Port || (type == Port && includeDelimiter == DelimiterIncluded))
81
return port.begin() - 1; // Back over delimiter.
83
return port.begin(); // Don't want delimiter counted.
93
if (query.isValid()) {
94
if (type < Query || (type == Query && includeDelimiter == DelimiterIncluded))
95
return query.begin() - 1; // Back over delimiter.
97
return query.begin(); // Don't want delimiter counted.
98
current = query.end();
101
if (fragment.isValid()) {
102
if (type == Fragment && includeDelimiter == DelimiterExcluded)
103
return fragment.begin(); // Back over delimiter.
105
// When there is a fragment and we get here, the component we wanted was before
106
// this and not found, so we always know the beginning of the fragment is right.
107
return fragment.begin() - 1; // Don't want delimiter counted.
113
void URLSegments::moveFromComponentBy(ComponentType type, int offset)
118
scheme.moveBy(offset);
120
username.moveBy(offset);
122
password.moveBy(offset);
130
query.moveBy(offset);
132
fragment.moveBy(offset);
138
#endif // USE(WTFURL)