-
Notifications
You must be signed in to change notification settings - Fork 610
/
string19.cpp
96 lines (76 loc) · 2.53 KB
/
string19.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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "vm/vm.hpp"
#include "capi/19/include/ruby/ruby.h"
#include "capi/19/include/ruby/encoding.h"
#include "builtin/bytearray.hpp"
#include "builtin/encoding.hpp"
#include "builtin/fixnum.hpp"
#include "builtin/integer.hpp"
#include "builtin/nativemethod.hpp"
#include "builtin/object.hpp"
#include "builtin/string.hpp"
#include "capi/capi.hpp"
#include <string.h>
using namespace rubinius;
using namespace rubinius::capi;
namespace rubinius {
namespace capi {
}
}
extern "C" {
VALUE rb_enc_str_new(const char *ptr, long len, rb_encoding *enc)
{
VALUE str = rb_str_new(ptr, len);
rb_enc_associate(str, enc);
return str;
}
VALUE rb_usascii_str_new(const char* ptr, long len) {
return rb_enc_str_new(ptr, len, rb_usascii_encoding());
}
VALUE rb_usascii_str_new2(const char* ptr) {
return rb_enc_str_new(ptr, strlen(ptr), rb_usascii_encoding());
}
VALUE rb_external_str_new_with_enc(const char* string, long size, rb_encoding* encoding) {
NativeMethodEnvironment* env = NativeMethodEnvironment::get();
String* str = String::create(env->state(), string, size);
str->taint(env->state());
Encoding* enc = Encoding::find(env->state(), encoding->name);
if(enc == Encoding::usascii_encoding(env->state())
&& !CBOOL(str->ascii_only_p(env->state()))) {
str->encoding(env->state(), Encoding::ascii8bit_encoding(env->state()));
} else {
str->encoding(env->state(), enc);
}
// TODO: handle transcoding if necessary
return env->get_handle(str);
}
VALUE rb_external_str_new(const char* string, long size) {
return rb_external_str_new_with_enc(string, size, rb_default_external_encoding());
}
VALUE rb_external_str_new_cstr(const char* string) {
return rb_external_str_new_with_enc(string, strlen(string), rb_default_external_encoding());
}
VALUE rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts) {
return rb_funcall(rb_mCAPI, rb_intern("rb_str_encode"), 4,
str, to, INT2FIX(ecflags), ecopts);
}
int rb_enc_str_coderange(VALUE string) {
// TODO
return ENC_CODERANGE_7BIT;
}
VALUE rb_locale_str_new_cstr(const char *ptr) {
// TODO
return rb_str_new2(ptr);
}
VALUE rb_locale_str_new(const char* ptr, long len) {
// TODO
return rb_str_new(ptr, len);
}
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to) {
// TODO
return str;
}
VALUE rb_str_export_to_enc(VALUE str, rb_encoding *enc) {
// TODO
return rb_str_conv_enc(str, rb_enc_get(str), enc);
}
}