mirror of
https://github.com/ascii-boxes/boxes.git
synced 2025-06-25 04:02:05 +02:00
Remove obsolete parameter 'skip' from u32_strnrstr() in 'unicode' module
This commit is contained in:
parent
a11c6cdb51
commit
393f27256e
@ -492,7 +492,7 @@ match_result_t *match_outer_shape(int vside, bxstr_t *input_line, bxstr_t *shape
|
|||||||
uint32_t *s = u32_strdup(shape_line->memory);
|
uint32_t *s = u32_strdup(shape_line->memory);
|
||||||
for (; slen == (int) shape_line->num_chars || is_blank(s[slen]); slen--) {
|
for (; slen == (int) shape_line->num_chars || is_blank(s[slen]); slen--) {
|
||||||
s[slen] = char_nul;
|
s[slen] = char_nul;
|
||||||
uint32_t *p = u32_strnrstr(input_line->memory, s, slen, 0);
|
uint32_t *p = u32_strnrstr(input_line->memory, s, slen);
|
||||||
size_t p_idx = p != NULL ? p - input_line->memory : 0;
|
size_t p_idx = p != NULL ? p - input_line->memory : 0;
|
||||||
if (p == NULL || p_idx + slen
|
if (p == NULL || p_idx + slen
|
||||||
< input_line->first_char[input_line->num_chars_visible - input_line->trailing]) {
|
< input_line->first_char[input_line->num_chars_visible - input_line->trailing]) {
|
||||||
@ -714,7 +714,7 @@ static void match_vertical_side(remove_ctx_t *ctx, int vside, shape_line_ctx_t *
|
|||||||
p = u32_strstr(input_line, shape_text);
|
p = u32_strstr(input_line, shape_text);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
p = u32_strnrstr(input_line, shape_text, quality, 0);
|
p = u32_strnrstr(input_line, shape_text, quality);
|
||||||
}
|
}
|
||||||
BFREE(to_free);
|
BFREE(to_free);
|
||||||
shape_text = NULL;
|
shape_text = NULL;
|
||||||
|
@ -315,8 +315,8 @@ uint32_t *u32_nspaces(const size_t n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO It seems skip is always 0, can we remove that parameter?
|
|
||||||
uint32_t *u32_strnrstr(const uint32_t *haystack, const uint32_t *needle, const size_t needle_len, int skip)
|
uint32_t *u32_strnrstr(const uint32_t *haystack, const uint32_t *needle, const size_t needle_len)
|
||||||
{
|
{
|
||||||
if (is_empty(needle)) {
|
if (is_empty(needle)) {
|
||||||
return (uint32_t *) haystack;
|
return (uint32_t *) haystack;
|
||||||
@ -324,9 +324,6 @@ uint32_t *u32_strnrstr(const uint32_t *haystack, const uint32_t *needle, const s
|
|||||||
if (is_empty(haystack)) {
|
if (is_empty(haystack)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (skip < 0) {
|
|
||||||
skip = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t *p = u32_strrchr(haystack, needle[0]);
|
uint32_t *p = u32_strrchr(haystack, needle[0]);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
@ -334,19 +331,11 @@ uint32_t *u32_strnrstr(const uint32_t *haystack, const uint32_t *needle, const s
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (p >= haystack) {
|
while (p >= haystack) {
|
||||||
int comp = u32_strncmp(p, needle, needle_len);
|
if (u32_strncmp(p, needle, needle_len) == 0) {
|
||||||
if (comp == 0) {
|
|
||||||
if (skip--) {
|
|
||||||
--p;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
--p;
|
--p;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -228,10 +228,9 @@ uint32_t *u32_nspaces(const size_t n);
|
|||||||
* @param haystack string to search
|
* @param haystack string to search
|
||||||
* @param needle string to search for in `haystack`
|
* @param needle string to search for in `haystack`
|
||||||
* @param needle_len length in characters of `needle`
|
* @param needle_len length in characters of `needle`
|
||||||
* @param skip number of finds to ignore before returning anything
|
|
||||||
* @return pointer to last occurrence of string `needle` in string `haystack`; NULL if not found or error
|
* @return pointer to last occurrence of string `needle` in string `haystack`; NULL if not found or error
|
||||||
*/
|
*/
|
||||||
uint32_t *u32_strnrstr(const uint32_t *haystack, const uint32_t *needle, const size_t needle_len, int skip);
|
uint32_t *u32_strnrstr(const uint32_t *haystack, const uint32_t *needle, const size_t needle_len);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -170,13 +170,10 @@ void test_u32_strnrstr(void **state)
|
|||||||
uint32_t *needle = u32_strconv_from_arg("found", "ASCII");
|
uint32_t *needle = u32_strconv_from_arg("found", "ASCII");
|
||||||
assert_non_null(needle);
|
assert_non_null(needle);
|
||||||
|
|
||||||
assert_null(u32_strnrstr(NULL, needle, u32_strlen(needle), 0));
|
assert_null(u32_strnrstr(NULL, needle, u32_strlen(needle)));
|
||||||
assert_ptr_equal(haystack, u32_strnrstr(haystack, NULL, 0, 0));
|
assert_ptr_equal(haystack, u32_strnrstr(haystack, NULL, 0));
|
||||||
|
|
||||||
uint32_t *actual = u32_strnrstr(haystack, needle, u32_strlen(needle), 1);
|
uint32_t *actual = u32_strnrstr(haystack, needle, u32_strlen(needle));
|
||||||
assert_ptr_equal(haystack + 6, actual);
|
|
||||||
|
|
||||||
actual = u32_strnrstr(haystack, needle, u32_strlen(needle), -1); /* -1 will be "fixed" to 0 */
|
|
||||||
assert_ptr_equal(haystack + 12, actual);
|
assert_ptr_equal(haystack + 12, actual);
|
||||||
|
|
||||||
BFREE(haystack);
|
BFREE(haystack);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user