Remove duplicate functionality in string.c

This commit is contained in:
Calvin Rose
2019-01-05 21:23:44 -05:00
parent 1f98eff33a
commit 0fdd404a71
3 changed files with 60 additions and 203 deletions
+10 -33
View File
@@ -95,12 +95,8 @@ static Janet janet_core_print(int32_t argc, Janet *argv) {
static Janet janet_core_describe(int32_t argc, Janet *argv) {
JanetBuffer b;
janet_buffer_init(&b, 0);
for (int32_t i = 0; i < argc; ++i) {
int32_t len;
const uint8_t *str = janet_description(argv[i]);
len = janet_string_length(str);
janet_buffer_push_bytes(&b, str, len);
}
for (int32_t i = 0; i < argc; ++i)
janet_description_b(&b, argv[i]);
Janet ret = janet_stringv(b.data, b.count);
janet_buffer_deinit(&b);
return ret;
@@ -109,56 +105,37 @@ static Janet janet_core_describe(int32_t argc, Janet *argv) {
static Janet janet_core_string(int32_t argc, Janet *argv) {
JanetBuffer b;
janet_buffer_init(&b, 0);
for (int32_t i = 0; i < argc; ++i) {
int32_t len;
const uint8_t *str = janet_to_string(argv[i]);
len = janet_string_length(str);
janet_buffer_push_bytes(&b, str, len);
}
for (int32_t i = 0; i < argc; ++i)
janet_to_string_b(&b, argv[i]);
Janet ret = janet_stringv(b.data, b.count);
janet_buffer_deinit(&b);
return ret;
}
static Janet janet_core_symbol(int32_t argc, Janet *argv) {
int32_t i;
JanetBuffer b;
janet_buffer_init(&b, 0);
for (i = 0; i < argc; ++i) {
int32_t len;
const uint8_t *str = janet_to_string(argv[i]);
len = janet_string_length(str);
janet_buffer_push_bytes(&b, str, len);
}
for (int32_t i = 0; i < argc; ++i)
janet_to_string_b(&b, argv[i]);
Janet ret = janet_symbolv(b.data, b.count);
janet_buffer_deinit(&b);
return ret;
}
static Janet janet_core_keyword(int32_t argc, Janet *argv) {
int32_t i;
JanetBuffer b;
janet_buffer_init(&b, 0);
for (i = 0; i < argc; ++i) {
int32_t len;
const uint8_t *str = janet_to_string(argv[i]);
len = janet_string_length(str);
janet_buffer_push_bytes(&b, str, len);
}
for (int32_t i = 0; i < argc; ++i)
janet_to_string_b(&b, argv[i]);
Janet ret = janet_keywordv(b.data, b.count);
janet_buffer_deinit(&b);
return ret;
}
static Janet janet_core_buffer(int32_t argc, Janet *argv) {
int32_t i;
JanetBuffer *b = janet_buffer(0);
for (i = 0; i < argc; ++i) {
int32_t len;
const uint8_t *str = janet_to_string(argv[i]);
len = janet_string_length(str);
janet_buffer_push_bytes(b, str, len);
}
for (int32_t i = 0; i < argc; ++i)
janet_to_string_b(b, argv[i]);
return janet_wrap_buffer(b);
}