Page Speed Optimization Libraries  1.5.27.2
net/instaweb/util/public/google_url.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
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) const;
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   static const 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_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines