00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00019
00020 #ifndef NET_INSTAWEB_UTIL_PUBLIC_GOOGLE_URL_H_
00021 #define NET_INSTAWEB_UTIL_PUBLIC_GOOGLE_URL_H_
00022
00023 #include <cstddef>
00024 #include "net/instaweb/util/public/basictypes.h"
00025 #include "net/instaweb/util/public/string.h"
00026 #include "net/instaweb/util/public/string_util.h"
00027
00028
00029 #include "googleurl/src/gurl.h"
00030
00031 namespace net_instaweb {
00032
00033 class GoogleUrl {
00034 public:
00035 explicit GoogleUrl(const GoogleString& spec);
00036 explicit GoogleUrl(const StringPiece& sp);
00037 explicit GoogleUrl(const char* str);
00040 GoogleUrl(const GoogleUrl& base, const GoogleString& relative);
00041 GoogleUrl(const GoogleUrl& base, const StringPiece& relative);
00042 GoogleUrl(const GoogleUrl& base, const char* relative);
00043 GoogleUrl();
00044
00045 void Swap(GoogleUrl* google_url) { gurl_.Swap(&google_url->gurl_); }
00046
00047 bool Reset(const StringPiece& new_url);
00048 bool Reset(const GoogleUrl& new_url);
00049 bool Reset(const GoogleUrl& base, const GoogleString& relative);
00050 bool Reset(const GoogleUrl& base, const StringPiece& relative);
00051 bool Reset(const GoogleUrl& base, const char* relative);
00052
00054 void Clear();
00055
00061 GoogleUrl* CopyAndAddQueryParam(const StringPiece& name,
00062 const StringPiece& value);
00063
00066 StringPiece AllExceptQuery() const;
00067
00073 StringPiece AllAfterQuery() const;
00074
00078 StringPiece AllExceptLeaf() const;
00079
00082 StringPiece LeafWithQuery() const;
00083
00086 StringPiece LeafSansQuery() const;
00087
00091 StringPiece PathAndLeaf() const;
00092
00097 StringPiece PathSansLeaf() const;
00098
00101 StringPiece PathSansQuery() const;
00102
00105 GoogleString ExtractFileName() const;
00106
00107 StringPiece Host() const;
00108
00111 StringPiece HostAndPort() const;
00112
00116 StringPiece Origin() const;
00117
00118 StringPiece Query() const;
00119
00121 StringPiece Scheme() const;
00122
00124 StringPiece Spec() const;
00125
00127 StringPiece UncheckedSpec() const;
00128
00130 const char* spec_c_str() const {
00131 return gurl_.possibly_invalid_spec().c_str();
00132 }
00133
00134 int IntPort() const { return gurl_.IntPort(); }
00135
00137 int EffectiveIntPort() const { return gurl_.EffectiveIntPort(); }
00138
00140 bool is_valid() const { return gurl_.is_valid(); }
00141
00142 bool is_standard() const { return gurl_.IsStandard(); }
00143 bool is_empty() const { return gurl_.is_empty(); }
00144 bool has_scheme() const { return gurl_.has_scheme(); }
00145 bool has_path() const { return gurl_.has_path(); }
00146 bool has_query() const { return gurl_.has_query(); }
00147
00148 bool SchemeIs(const char* lower_ascii_scheme) const {
00149 return gurl_.SchemeIs(lower_ascii_scheme);
00150 }
00151
00154 bool SchemeIs(const StringPiece& lower_ascii_scheme) const {
00155 return gurl_.SchemeIs(lower_ascii_scheme.as_string().c_str());
00156 }
00157
00159 bool operator==(const GoogleUrl& other) const {
00160 return gurl_ == other.gurl_;
00161 }
00162 bool operator!=(const GoogleUrl& other) const {
00163 return gurl_ != other.gurl_;
00164 }
00165
00166 private:
00168 const static size_t npos;
00169
00170 explicit GoogleUrl(const GURL& gurl);
00171
00172 static size_t LeafEndPosition(const GURL& gurl);
00173 static size_t LeafStartPosition(const GURL& gurl);
00174 static size_t PathStartPosition(const GURL& gurl);
00175 size_t LeafEndPosition() const;
00176 size_t LeafStartPosition() const;
00177 size_t PathStartPosition() const;
00178
00183 inline bool ResolveHelper(const GURL& base, const std::string& path_and_leaf);
00184
00185 GURL gurl_;
00186
00187 DISALLOW_COPY_AND_ASSIGN(GoogleUrl);
00188 };
00189
00190 }
00191
00192
00193 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_GOOGLE_URL_H_