Line data Source code
1 : // Copyright 2016 the V8 project 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 V8_INSPECTOR_STRINGUTIL_H_
6 : #define V8_INSPECTOR_STRINGUTIL_H_
7 :
8 : #include <memory>
9 :
10 : #include "src/base/logging.h"
11 : #include "src/base/macros.h"
12 : #include "src/inspector/string-16.h"
13 :
14 : #include "include/v8-inspector.h"
15 :
16 : namespace v8_inspector {
17 :
18 : namespace protocol {
19 :
20 : class Value;
21 :
22 : using String = v8_inspector::String16;
23 : using StringBuilder = v8_inspector::String16Builder;
24 :
25 : class StringUtil {
26 : public:
27 : static String substring(const String& s, size_t pos, size_t len) {
28 140348 : return s.substring(pos, len);
29 : }
30 1356380 : static String fromInteger(int number) { return String::fromInteger(number); }
31 : static String fromInteger(size_t number) {
32 2364238 : return String::fromInteger(number);
33 : }
34 23737 : static String fromDouble(double number) { return String::fromDouble(number); }
35 : static double toDouble(const char* s, size_t len, bool* isOk);
36 140348 : static size_t find(const String& s, const char* needle) {
37 280696 : return s.find(needle);
38 : }
39 : static size_t find(const String& s, const String& needle) {
40 : return s.find(needle);
41 : }
42 : static const size_t kNotFound = String::kNotFound;
43 : static void builderAppend(StringBuilder& builder, const String& s) {
44 39159216 : builder.append(s);
45 : }
46 : static void builderAppend(StringBuilder& builder, UChar c) {
47 1214681746 : builder.append(c);
48 : }
49 : static void builderAppend(StringBuilder& builder, const char* s, size_t len) {
50 7498356 : builder.append(s, len);
51 : }
52 : static void builderAppendQuotedString(StringBuilder&, const String&);
53 : static void builderReserve(StringBuilder& builder, size_t capacity) {
54 1543042 : builder.reserveCapacity(capacity);
55 : }
56 : static String builderToString(StringBuilder& builder) {
57 1543089 : return builder.toString();
58 : }
59 : static std::unique_ptr<protocol::Value> parseJSON(const String16& json);
60 : static std::unique_ptr<protocol::Value> parseJSON(const StringView& json);
61 : };
62 :
63 : } // namespace protocol
64 :
65 : v8::Local<v8::String> toV8String(v8::Isolate*, const String16&);
66 : v8::Local<v8::String> toV8StringInternalized(v8::Isolate*, const String16&);
67 : v8::Local<v8::String> toV8StringInternalized(v8::Isolate*, const char*);
68 : v8::Local<v8::String> toV8String(v8::Isolate*, const StringView&);
69 : // TODO(dgozman): rename to toString16.
70 : String16 toProtocolString(v8::Local<v8::String>);
71 : String16 toProtocolStringWithTypeCheck(v8::Local<v8::Value>);
72 : String16 toString16(const StringView&);
73 : StringView toStringView(const String16&);
74 : bool stringViewStartsWith(const StringView&, const char*);
75 :
76 547270 : class StringBufferImpl : public StringBuffer {
77 : public:
78 : // Destroys string's content.
79 : static std::unique_ptr<StringBufferImpl> adopt(String16&);
80 273635 : const StringView& string() override { return m_string; }
81 :
82 : private:
83 : explicit StringBufferImpl(String16&);
84 : String16 m_owner;
85 : StringView m_string;
86 :
87 : DISALLOW_COPY_AND_ASSIGN(StringBufferImpl);
88 : };
89 :
90 : } // namespace v8_inspector
91 :
92 : #endif // V8_INSPECTOR_STRINGUTIL_H_
|