1 // Copyright 2007, Google Inc. All rights reserved. 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above 10 // copyright notice, this list of conditions and the following disclaimer 11 // in the documentation and/or other materials provided with the 12 // distribution. 13 // * Neither the name of Google Inc. nor the names of its 14 // contributors may be used to endorse or promote products derived from 15 // this software without specific prior written permission. 16 // 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29 #ifndef URLSegments_h 30 #define URLSegments_h 31 32 #include "URLComponent.h" 33 34 namespace WTF { 35 36 // A structure that holds the identified parts of an input URL. This structure 37 // does NOT store the URL itself. The caller will have to store the URL text 38 // and its corresponding Parsed structure separately. 39 class URLSegments { 40 public: 41 // Identifies different components. 42 enum ComponentType { 43 Scheme, 44 Username, 45 Password, 46 Host, 47 Port, 48 Path, 49 Query, 50 Fragment, 51 }; 52 URLSegments()53 URLSegments() { } 54 55 // Returns the length of the URL (the end of the last component). 56 // 57 // Note that for some invalid, non-canonical URLs, this may not be the length 58 // of the string. For example "http://": the parsed structure will only 59 // contain an entry for the four-character scheme, and it doesn't know about 60 // the "://". For all other last-components, it will return the real length. 61 int length() const; 62 63 // Returns the number of characters before the given component if it exists, 64 // or where the component would be if it did exist. This will return the 65 // string length if the component would be appended to the end. 66 // 67 // Note that this can get a little funny for the port, query, and fragment 68 // components which have a delimiter that is not counted as part of the 69 // component. The |includeDelimiter| flag controls if you want this counted 70 // as part of the component or not when the component exists. 71 // 72 // This example shows the difference between the two flags for two of these 73 // delimited components that is present (the port and query) and one that 74 // isn't (the reference). The components that this flag affects are marked 75 // with a *. 76 // 0 1 2 77 // 012345678901234567890 78 // Example input: http://foo:80/?query 79 // include_delim=true, ...=false ("<-" indicates different) 80 // Scheme: 0 0 81 // Username: 5 5 82 // Password: 5 5 83 // Host: 7 7 84 // *Port: 10 11 <- 85 // Path: 13 13 86 // *Query: 14 15 <- 87 // *Fragment: 20 20 88 // 89 int charactersBefore(ComponentType, bool includeDelimiter) const; 90 91 // Each component excludes the related delimiters and has a length of -1 92 // if that component is absent but 0 if the component exists but is empty. 93 URLComponent scheme; 94 URLComponent username; 95 URLComponent password; 96 URLComponent host; 97 URLComponent port; 98 URLComponent path; 99 URLComponent query; 100 URLComponent fragment; 101 }; 102 103 } // namespace WTF 104 105 #endif // URLSegments_h 106