blob: 2f0cbecefe14f5795e1bb969b1211281b1abc1c0 [file] [log] [blame]
// Copyright 2019 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <base/strings/utf_string_conversions.h>
#include <string>
using std::string;
string JsonSafe(const string& in) {
string utf8, s(in);
// filter \ and ", which will cause json parse error.
std::replace(s.begin(), s.end(), '\\', '"');
s.erase(std::remove(s.begin(), s.end(), '"'), s.end());
// convert to utf8
std::wstring ws(s.begin(), s.end());
base::WideToUTF8(ws.c_str(), ws.length(), &utf8);
return utf8;