-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring.cpp
42 lines (32 loc) · 1.25 KB
/
string.cpp
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 <string>
#include <sstream>
#include "string.h"
const uint8_t STRING_TYPE_MASK = 0x06;
value_t string_preprocess(const std::string& str) {
return wrap_string(str.substr(1, str.size() - 2));
}
value_t wrap_string(const std::string& str) {
double_storage_t* storage = alloc_double_storage();
storage->header = make_header(true, STRING_TYPE_MASK, MARK_POLICY_NONE);
storage->first_slot = (uint64_t) new std::string(str);
return wrap_pointer(storage);
}
std::string unwrap_string(value_t value) {
return *(unwrap_internal_string(value));
}
std::string* unwrap_internal_string(value_t value) {
double_storage_t* storage = (double_storage_t*) unwrap_pointer(value);
return ((std::string*) storage->first_slot);
}
std::string string_format(value_t value) {
std::stringstream sstream;
double_storage_t* storage = (double_storage_t*) unwrap_pointer(value);
std::string* string_pointer = (std::string*) storage->first_slot;
sstream << "\"" << *string_pointer << "\"";
return sstream.str();
}
void string_finalize(value_t value) {
double_storage_t* storage = (double_storage_t*) unwrap_pointer(value);
std::string* string_pointer = (std::string*) storage->first_slot;
delete string_pointer;
}