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