1 // Copyright (c) 2011 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 #include <algorithm>
6
7 #include "net/base/escape.h"
8
9 #include "base/i18n/icu_string_conversions.h"
10 #include "base/utf_string_conversions.h"
11
12 // This file exists to avoid having escape.cc depend on ICU.
13
EscapeQueryParamValue(const string16 & text,const char * codepage,bool use_plus,string16 * escaped)14 bool EscapeQueryParamValue(const string16& text, const char* codepage,
15 bool use_plus, string16* escaped) {
16 // TODO(brettw) bug 1201094: this function should be removed, this "SKIP"
17 // behavior is wrong when the character can't be encoded properly.
18 std::string encoded;
19 if (!base::UTF16ToCodepage(text, codepage,
20 base::OnStringConversionError::SKIP, &encoded))
21 return false;
22
23 escaped->assign(UTF8ToUTF16(EscapeQueryParamValue(encoded, use_plus)));
24 return true;
25 }
26