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.cpp
More file actions
42 lines (36 loc) · 1.26 KB
/
string.cpp
File metadata and controls
42 lines (36 loc) · 1.26 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
#include <cstdlib>
#include "string.hpp"
#include "utils.hpp"
namespace lib_ruby_parser
{
extern "C"
{
StringBlob LIB_RUBY_PARSER_new_string_owned(char *s, size_t len);
StringBlob LIB_RUBY_PARSER_new_string_from_cstr(const char *s);
void LIB_RUBY_PARSER_drop_string(String *string);
bool LIB_RUBY_PARSER_maybe_string_is_some(const MaybeString *maybe_string);
bool LIB_RUBY_PARSER_maybe_string_is_none(const MaybeString *maybe_string);
void LIB_RUBY_PARSER_drop_maybe_string(MaybeString *maybe_string);
}
LIST_IMPL(String, char, LIB_RUBY_PARSER_drop_string);
String String::Owned(char *s, size_t len)
{
return from_blob<StringBlob, String>(
LIB_RUBY_PARSER_new_string_owned(s, len));
}
String String::Copied(const char *s)
{
return from_blob<StringBlob, String>(
LIB_RUBY_PARSER_new_string_from_cstr(s));
}
MaybeString::MaybeString() : string(String(nullptr, 0, 0)){};
MaybeString::MaybeString(String string_) : string(std::move(string_)){};
bool MaybeString::is_some() const
{
return this->string.ptr != nullptr;
}
bool MaybeString::is_none() const
{
return this->string.ptr == nullptr;
}
} // lib_ruby_parser