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_STRING_UTIL_H_
6 : #define V8_INSPECTOR_STRING_UTIL_H_
7 :
8 : #include <stdint.h>
9 : #include <memory>
10 :
11 : #include "src/base/logging.h"
12 : #include "src/base/macros.h"
13 : #include "src/inspector/string-16.h"
14 :
15 : #include "include/v8-inspector.h"
16 :
17 : namespace v8_inspector {
18 :
19 : namespace protocol {
20 :
21 : class Value;
22 :
23 : using String = v8_inspector::String16;
24 : using StringBuilder = v8_inspector::String16Builder;
25 :
26 : class StringUtil {
27 : public:
28 : static String substring(const String& s, size_t pos, size_t len) {
29 169239 : return s.substring(pos, len);
30 : }
31 1893213 : static String fromInteger(int number) { return String::fromInteger(number); }
32 : static String fromInteger(size_t number) {
33 345 : return String::fromInteger(number);
34 : }
35 151258 : static String fromDouble(double number) { return String::fromDouble(number); }
36 : static double toDouble(const char* s, size_t len, bool* isOk);
37 169239 : static size_t find(const String& s, const char* needle) {
38 338478 : return s.find(needle);
39 : }
40 : static size_t find(const String& s, const String& needle) {
41 : return s.find(needle);
42 : }
43 : static const size_t kNotFound = String::kNotFound;
44 : static void builderAppend(StringBuilder& builder, const String& s) {
45 42650520 : builder.append(s);
46 : }
47 : static void builderAppend(StringBuilder& builder, UChar c) {
48 1277165044 : builder.append(c);
49 : }
50 : static void builderAppend(StringBuilder& builder, const char* s, size_t len) {
51 7870403 : builder.append(s, len);
52 : }
53 : static void builderAppendQuotedString(StringBuilder&, const String&);
54 : static void builderReserve(StringBuilder& builder, size_t capacity) {
55 1867409 : builder.reserveCapacity(capacity);
56 : }
57 : static String builderToString(StringBuilder& builder) {
58 1867456 : return builder.toString();
59 : }
60 : static std::unique_ptr<protocol::Value> parseJSON(const String16& json);
61 : static std::unique_ptr<protocol::Value> parseJSON(const StringView& json);
62 : };
63 :
64 : // A read-only sequence of uninterpreted bytes with reference-counted storage.
65 : // Though the templates for generating the protocol bindings reference
66 : // this type, js_protocol.pdl doesn't have a field of type 'binary', so
67 : // therefore it's unnecessary to provide an implementation here.
68 : class Binary {
69 : public:
70 : const uint8_t* data() const { UNIMPLEMENTED(); }
71 : size_t size() const { UNIMPLEMENTED(); }
72 : String toBase64() const { UNIMPLEMENTED(); }
73 : static Binary fromBase64(const String& base64, bool* success) {
74 : UNIMPLEMENTED();
75 : }
76 : };
77 : } // namespace protocol
78 :
79 : v8::Local<v8::String> toV8String(v8::Isolate*, const String16&);
80 : v8::Local<v8::String> toV8StringInternalized(v8::Isolate*, const String16&);
81 : v8::Local<v8::String> toV8StringInternalized(v8::Isolate*, const char*);
82 : v8::Local<v8::String> toV8String(v8::Isolate*, const StringView&);
83 : // TODO(dgozman): rename to toString16.
84 : String16 toProtocolString(v8::Isolate*, v8::Local<v8::String>);
85 : String16 toProtocolStringWithTypeCheck(v8::Isolate*, v8::Local<v8::Value>);
86 : String16 toString16(const StringView&);
87 : StringView toStringView(const String16&);
88 : bool stringViewStartsWith(const StringView&, const char*);
89 :
90 697440 : class StringBufferImpl : public StringBuffer {
91 : public:
92 : // Destroys string's content.
93 : static std::unique_ptr<StringBufferImpl> adopt(String16&);
94 348720 : const StringView& string() override { return m_string; }
95 :
96 : private:
97 : explicit StringBufferImpl(String16&);
98 : String16 m_owner;
99 : StringView m_string;
100 :
101 : DISALLOW_COPY_AND_ASSIGN(StringBufferImpl);
102 : };
103 :
104 : String16 debuggerIdToString(const std::pair<int64_t, int64_t>& debuggerId);
105 : String16 stackTraceIdToString(uintptr_t id);
106 :
107 : } // namespace v8_inspector
108 :
109 : #endif // V8_INSPECTOR_STRING_UTIL_H_
|