~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WTF/wtf/url/src/URLSegments.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Based on nsURLParsers.cc from Mozilla
 
2
 * -------------------------------------
 
3
 * Copyright (C) 1998 Netscape Communications Corporation.
 
4
 * Copyright (C) 2012 Apple Inc. All rights reserved.
 
5
 *
 
6
 * Other contributors:
 
7
 *   Darin Fisher (original author)
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 *
 
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
 
22
 *
 
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.
 
36
 */
 
37
 
 
38
#include "config.h"
 
39
#include "URLSegments.h"
 
40
 
 
41
#if USE(WTFURL)
 
42
 
 
43
namespace WTF {
 
44
 
 
45
int URLSegments::length() const
 
46
{
 
47
    if (fragment.isValid())
 
48
        return fragment.end();
 
49
    return charactersBefore(Fragment, DelimiterExcluded);
 
50
}
 
51
 
 
52
int URLSegments::charactersBefore(ComponentType type, DelimiterInclusion includeDelimiter) const
 
53
{
 
54
    if (type == Scheme)
 
55
        return scheme.begin();
 
56
 
 
57
    int current = 0;
 
58
    if (scheme.isValid())
 
59
        current = scheme.end() + 1; // Advance over the ':' at the end of the scheme.
 
60
 
 
61
    if (username.isValid()) {
 
62
        if (type <= Username)
 
63
            return username.begin();
 
64
        current = username.end() + 1; // Advance over the '@' or ':' at the end.
 
65
    }
 
66
 
 
67
    if (password.isValid()) {
 
68
        if (type <= Password)
 
69
            return password.begin();
 
70
        current = password.end() + 1; // Advance over the '@' at the end.
 
71
    }
 
72
 
 
73
    if (host.isValid()) {
 
74
        if (type <= Host)
 
75
            return host.begin();
 
76
        current = host.end();
 
77
    }
 
78
 
 
79
    if (port.isValid()) {
 
80
        if (type < Port || (type == Port && includeDelimiter == DelimiterIncluded))
 
81
            return port.begin() - 1; // Back over delimiter.
 
82
        if (type == Port)
 
83
            return port.begin(); // Don't want delimiter counted.
 
84
        current = port.end();
 
85
    }
 
86
 
 
87
    if (path.isValid()) {
 
88
        if (type <= Path)
 
89
            return path.begin();
 
90
        current = path.end();
 
91
    }
 
92
 
 
93
    if (query.isValid()) {
 
94
        if (type < Query || (type == Query && includeDelimiter == DelimiterIncluded))
 
95
            return query.begin() - 1; // Back over delimiter.
 
96
        if (type == Query)
 
97
            return query.begin(); // Don't want delimiter counted.
 
98
        current = query.end();
 
99
    }
 
100
 
 
101
    if (fragment.isValid()) {
 
102
        if (type == Fragment && includeDelimiter == DelimiterExcluded)
 
103
            return fragment.begin(); // Back over delimiter.
 
104
 
 
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.
 
108
    }
 
109
 
 
110
    return current;
 
111
}
 
112
 
 
113
void URLSegments::moveFromComponentBy(ComponentType type, int offset)
 
114
{
 
115
    switch (type) {
 
116
    // Fall through.
 
117
    case Scheme:
 
118
        scheme.moveBy(offset);
 
119
    case Username:
 
120
        username.moveBy(offset);
 
121
    case Password:
 
122
        password.moveBy(offset);
 
123
    case Host:
 
124
        host.moveBy(offset);
 
125
    case Port:
 
126
        port.moveBy(offset);
 
127
    case Path:
 
128
        path.moveBy(offset);
 
129
    case Query:
 
130
        query.moveBy(offset);
 
131
    case Fragment:
 
132
        fragment.moveBy(offset);
 
133
    }
 
134
}
 
135
 
 
136
} // namespace WTF
 
137
 
 
138
#endif // USE(WTFURL)