OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium 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 String_h | |
6 #define String_h | |
7 | |
8 #include "platform/PlatformExport.h" | |
9 | |
10 #include <cctype> | |
11 #include <memory> | |
12 #include <stdint.h> | |
13 | |
14 namespace v8_inspector { | |
15 | |
16 class PLATFORM_EXPORT StringView { | |
17 public: | |
18 StringView() : m_is8Bit(true), m_length(0) { m_characters8 = nullptr; } | |
19 StringView(const uint8_t* characters, unsigned length) : m_is8Bit(true), m_l ength(length) { m_characters8 = characters; } | |
esprehn
2016/08/23 17:35:39
you can just initialize an unnamed union member di
dgozman
2016/08/24 00:45:01
Done.
| |
20 StringView(const uint16_t* characters, unsigned length) : m_is8Bit(false), m _length(length) { m_characters16 = characters; } | |
esprehn
2016/08/23 17:35:39
ditto
| |
21 | |
22 bool is8Bit() const { return m_is8Bit; } | |
23 unsigned length() const { return m_length; } | |
24 const uint8_t* characters8() const { return m_characters8; } | |
esprehn
2016/08/23 17:35:39
DCHECK(m_is8Bit)
dgozman
2016/08/24 00:45:01
Unfortunately, I cannot do that right now, since i
| |
25 const uint16_t* characters16() const { return m_characters16; } | |
esprehn
2016/08/23 17:35:39
DCHECK(!m_is8Bit)
| |
26 | |
27 private: | |
28 bool m_is8Bit; | |
29 unsigned m_length; | |
30 union { | |
31 const uint8_t* m_characters8; | |
32 const uint16_t* m_characters16; | |
33 }; | |
34 }; | |
35 | |
36 class PLATFORM_EXPORT StringBuffer { | |
esprehn
2016/08/23 17:35:39
can we put these in separate headers? StringView.h
dgozman
2016/08/24 00:45:01
Sure.
| |
37 public: | |
38 virtual ~StringBuffer() { } | |
39 virtual const StringView& string() = 0; | |
40 // This method copies contents. | |
41 static std::unique_ptr<StringBuffer> create(const StringView&); | |
42 }; | |
43 | |
44 } // namespace v8_inspector | |
45 | |
46 #endif // String_h | |
OLD | NEW |