This repository was archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring.hpp
More file actions
72 lines (57 loc) · 1.76 KB
/
string.hpp
File metadata and controls
72 lines (57 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef LIB_RUBY_PARSER_String_HPP
#define LIB_RUBY_PARSER_String_HPP
#include <cstddef>
#include <cstdint>
#include <cstdbool>
namespace lib_ruby_parser
{
/// Representation of a String.
/// `ptr` is NOT NULL-terminated.
/// `capacity` doesn't matter.
class String
{
public:
char *ptr;
size_t capacity;
size_t len;
String() = delete;
String(char *ptr, size_t len, size_t capacity);
String(const String &) = delete;
String &operator=(String const &) = delete;
String(String &&);
String &operator=(String &&);
~String();
static String Owned(char *s, size_t len);
static String Copied(const char *s);
};
extern "C"
{
struct StringBlob
{
uint8_t bytes[sizeof(String)];
};
}
/// Rerpresentation of Option<String>.
/// Rust has a Option<non-null ptr> optimization that None is NULL on the byte level.
/// Thus, it's not a tagged enum.
/// To check whether it's a Some(String) or None use helpers:
/// + LIB_RUBY_PARSER_maybe_string_is_some
/// + LIB_RUBY_PARSER_maybe_string_is_none
class MaybeString
{
public:
String string;
MaybeString();
explicit MaybeString(String s);
MaybeString(const MaybeString &) = delete;
MaybeString &operator=(MaybeString const &) = delete;
MaybeString(MaybeString &&) = default;
MaybeString &operator=(MaybeString &&) = default;
~MaybeString() = default;
/// Returns `true` if pointer is `Some(String)`
bool is_some() const;
/// Returns `true` if pointer is `None`
bool is_none() const;
};
} // namespace lib_ruby_parser
#endif // LIB_RUBY_PARSER_String_HPP