summaryrefslogtreecommitdiff
path: root/chromium/components/ui_devtools/string_util.cc
blob: fde02a7b521fb9e9cbfc65334aaa1d7ac7252d00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright 2016 The Chromium 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 "components/ui_devtools/string_util.h"

#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "components/ui_devtools/Protocol.h"

namespace ui_devtools {
namespace protocol {

// static
std::unique_ptr<Value> StringUtil::parseJSON(const String& string) {
  DCHECK(base::IsStringUTF8(string));
  // TODO(mhashmi): 16-bit strings need to be handled
  return parseJSONCharacters(reinterpret_cast<const uint8_t*>(&string[0]),
                             string.length());
};

// static
void StringUtil::builderAppendQuotedString(StringBuilder& builder,
                                           const String& str) {
  builder.append('"');
  base::string16 str16 = base::UTF8ToUTF16(str);
  escapeWideStringForJSON(reinterpret_cast<const uint16_t*>(&str16[0]),
                          str16.length(), &builder);
  builder.append('"');
}

}  // namespace protocol
}  // namespace ui_devtools