OLD | NEW |
| (Empty) |
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 "src/base/macros.h" | |
9 #include "src/inspector/String16.h" | |
10 | |
11 #include "include/v8-inspector.h" | |
12 | |
13 namespace v8_inspector { | |
14 | |
15 namespace protocol { | |
16 | |
17 class Value; | |
18 | |
19 using String = v8_inspector::String16; | |
20 using StringBuilder = v8_inspector::String16Builder; | |
21 | |
22 class StringUtil { | |
23 public: | |
24 static String substring(const String& s, unsigned pos, unsigned len) { | |
25 return s.substring(pos, len); | |
26 } | |
27 static String fromInteger(int number) { return String::fromInteger(number); } | |
28 static String fromDouble(double number) { return String::fromDouble(number); } | |
29 static const size_t kNotFound = String::kNotFound; | |
30 static void builderReserve(StringBuilder& builder, unsigned capacity) { | |
31 builder.reserveCapacity(capacity); | |
32 } | |
33 }; | |
34 | |
35 std::unique_ptr<protocol::Value> parseJSON(const StringView& json); | |
36 std::unique_ptr<protocol::Value> parseJSON(const String16& json); | |
37 | |
38 } // namespace protocol | |
39 | |
40 std::unique_ptr<protocol::Value> toProtocolValue(v8::Local<v8::Context>, | |
41 v8::Local<v8::Value>, | |
42 int maxDepth = 1000); | |
43 | |
44 v8::Local<v8::String> toV8String(v8::Isolate*, const String16&); | |
45 v8::Local<v8::String> toV8StringInternalized(v8::Isolate*, const String16&); | |
46 v8::Local<v8::String> toV8StringInternalized(v8::Isolate*, const char*); | |
47 v8::Local<v8::String> toV8String(v8::Isolate*, const StringView&); | |
48 // TODO(dgozman): rename to toString16. | |
49 String16 toProtocolString(v8::Local<v8::String>); | |
50 String16 toProtocolStringWithTypeCheck(v8::Local<v8::Value>); | |
51 String16 toString16(const StringView&); | |
52 StringView toStringView(const String16&); | |
53 bool stringViewStartsWith(const StringView&, const char*); | |
54 | |
55 class StringBufferImpl : public StringBuffer { | |
56 DISALLOW_COPY_AND_ASSIGN(StringBufferImpl); | |
57 | |
58 public: | |
59 // Destroys string's content. | |
60 static std::unique_ptr<StringBufferImpl> adopt(String16&); | |
61 const StringView& string() override { return m_string; } | |
62 | |
63 private: | |
64 explicit StringBufferImpl(String16&); | |
65 String16 m_owner; | |
66 StringView m_string; | |
67 }; | |
68 | |
69 } // namespace v8_inspector | |
70 | |
71 #endif // V8_INSPECTOR_STRINGUTIL_H_ | |
OLD | NEW |