1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-28 11:09:54 +00:00

Update CHANGELOG, string/has-suffix?|prefix?

string/has-suffix? and string/has-prefix? can now accept
all byte data types for both arguments.
This commit is contained in:
Calvin Rose 2019-05-09 13:42:14 -04:00
parent bbcfaf1289
commit 7a313f6038
2 changed files with 11 additions and 12 deletions

View File

@ -2,6 +2,7 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## 0.5.0 - ?? ## 0.5.0 - ??
- Fix some bugs with buffers.
- Add `trace` and `untrace` to the core library. - Add `trace` and `untrace` to the core library.
- Add `string/has-prefix?` and `string/has-suffix?` to string module. - Add `string/has-prefix?` and `string/has-suffix?` to string module.
- Add simple debugger to repl that activates on errors or debug signal - Add simple debugger to repl that activates on errors or debug signal

View File

@ -276,24 +276,22 @@ static Janet cfun_string_find(int32_t argc, Janet *argv) {
static Janet cfun_string_hasprefix(int32_t argc, Janet *argv) { static Janet cfun_string_hasprefix(int32_t argc, Janet *argv) {
janet_fixarity(argc, 2); janet_fixarity(argc, 2);
const uint8_t *prefix = janet_getstring(argv, 0); JanetByteView prefix = janet_getbytes(argv, 0);
const uint8_t *s = janet_getstring(argv, 1); JanetByteView str = janet_getbytes(argv, 1);
int32_t prefix_len = janet_string_length(prefix); return str.len < prefix.len
int32_t s_len = janet_string_length(s);
return s_len < prefix_len
? janet_wrap_false() ? janet_wrap_false()
: janet_wrap_boolean(memcmp(prefix, s, prefix_len) == 0); : janet_wrap_boolean(memcmp(prefix.bytes, str.bytes, prefix.len) == 0);
} }
static Janet cfun_string_hassuffix(int32_t argc, Janet *argv) { static Janet cfun_string_hassuffix(int32_t argc, Janet *argv) {
janet_fixarity(argc, 2); janet_fixarity(argc, 2);
const uint8_t *suffix = janet_getstring(argv, 0); JanetByteView suffix = janet_getbytes(argv, 0);
const uint8_t *s = janet_getstring(argv, 1); JanetByteView str = janet_getbytes(argv, 1);
int32_t suffix_len = janet_string_length(suffix); return str.len < suffix.len
int32_t s_len = janet_string_length(s);
return s_len < suffix_len
? janet_wrap_false() ? janet_wrap_false()
: janet_wrap_boolean(memcmp(suffix, s + s_len - suffix_len, suffix_len) == 0); : janet_wrap_boolean(memcmp(suffix.bytes,
str.bytes + str.len - suffix.len,
suffix.len) == 0);
} }
static Janet cfun_string_findall(int32_t argc, Janet *argv) { static Janet cfun_string_findall(int32_t argc, Janet *argv) {