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:
parent
bbcfaf1289
commit
7a313f6038
@ -2,6 +2,7 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## 0.5.0 - ??
|
||||
- Fix some bugs with buffers.
|
||||
- Add `trace` and `untrace` to the core library.
|
||||
- Add `string/has-prefix?` and `string/has-suffix?` to string module.
|
||||
- Add simple debugger to repl that activates on errors or debug signal
|
||||
|
@ -276,24 +276,22 @@ static Janet cfun_string_find(int32_t argc, Janet *argv) {
|
||||
|
||||
static Janet cfun_string_hasprefix(int32_t argc, Janet *argv) {
|
||||
janet_fixarity(argc, 2);
|
||||
const uint8_t *prefix = janet_getstring(argv, 0);
|
||||
const uint8_t *s = janet_getstring(argv, 1);
|
||||
int32_t prefix_len = janet_string_length(prefix);
|
||||
int32_t s_len = janet_string_length(s);
|
||||
return s_len < prefix_len
|
||||
JanetByteView prefix = janet_getbytes(argv, 0);
|
||||
JanetByteView str = janet_getbytes(argv, 1);
|
||||
return str.len < prefix.len
|
||||
? 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) {
|
||||
janet_fixarity(argc, 2);
|
||||
const uint8_t *suffix = janet_getstring(argv, 0);
|
||||
const uint8_t *s = janet_getstring(argv, 1);
|
||||
int32_t suffix_len = janet_string_length(suffix);
|
||||
int32_t s_len = janet_string_length(s);
|
||||
return s_len < suffix_len
|
||||
JanetByteView suffix = janet_getbytes(argv, 0);
|
||||
JanetByteView str = janet_getbytes(argv, 1);
|
||||
return str.len < suffix.len
|
||||
? 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user