Home | History | Annotate | Download | only in base
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef NET_BASE_URL_UTIL_H_
      6 #define NET_BASE_URL_UTIL_H_
      7 
      8 #include <string>
      9 
     10 #include "net/base/net_export.h"
     11 
     12 class GURL;
     13 
     14 namespace net {
     15 
     16 // Returns a new GURL by appending the given query parameter name and the
     17 // value. Unsafe characters in the name and the value are escaped like
     18 // %XX%XX. The original query component is preserved if it's present.
     19 //
     20 // Examples:
     21 //
     22 // AppendQueryParameter(GURL("http://example.com"), "name", "value").spec()
     23 // => "http://example.com?name=value"
     24 // AppendQueryParameter(GURL("http://example.com?x=y"), "name", "value").spec()
     25 // => "http://example.com?x=y&name=value"
     26 NET_EXPORT GURL AppendQueryParameter(const GURL& url,
     27                                      const std::string& name,
     28                                      const std::string& value);
     29 
     30 // Returns a new GURL by appending or replacing the given query parameter name
     31 // and the value. If |name| appears more than once, only the first name-value
     32 // pair is replaced. Unsafe characters in the name and the value are escaped
     33 // like %XX%XX. The original query component is preserved if it's present.
     34 //
     35 // Examples:
     36 //
     37 // AppendOrReplaceQueryParameter(
     38 //     GURL("http://example.com"), "name", "new").spec()
     39 // => "http://example.com?name=value"
     40 // AppendOrReplaceQueryParameter(
     41 //     GURL("http://example.com?x=y&name=old"), "name", "new").spec()
     42 // => "http://example.com?x=y&name=new"
     43 NET_EXPORT GURL AppendOrReplaceQueryParameter(const GURL& url,
     44                                               const std::string& name,
     45                                               const std::string& value);
     46 
     47 // Looks for |search_key| in the query portion of |url|. Returns true if the
     48 // key is found and sets |out_value| to the unescaped value for the key.
     49 // Returns false if the key is not found.
     50 NET_EXPORT bool GetValueForKeyInQuery(const GURL& url,
     51                                       const std::string& search_key,
     52                                       std::string* out_value);
     53 
     54 }  // namespace net
     55 
     56 #endif  // NET_BASE_URL_UTIL_H_
     57