tweaks: rename one variable again
It is not an index, it is not an offset from anything, it is a direct pointer.master
parent
17cf7d1c62
commit
6240805c41
94
src/chars.c
94
src/chars.c
|
@ -477,91 +477,91 @@ char *mbstrcasestr(const char *haystack, const char *needle)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is equivalent to strstr(), except in that it scans the
|
/* This function is equivalent to strstr(), except in that it scans the
|
||||||
* string in reverse, starting at index. */
|
* string in reverse, starting at pointer. */
|
||||||
char *revstrstr(const char *haystack, const char *needle,
|
char *revstrstr(const char *haystack, const char *needle,
|
||||||
const char *index)
|
const char *pointer)
|
||||||
{
|
{
|
||||||
size_t needle_len = strlen(needle);
|
size_t needle_len = strlen(needle);
|
||||||
size_t tail_len = strlen(index);
|
size_t tail_len = strlen(pointer);
|
||||||
|
|
||||||
if (needle_len == 0)
|
if (needle_len == 0)
|
||||||
return (char *)index;
|
return (char *)pointer;
|
||||||
|
|
||||||
if (strlen(haystack) < needle_len)
|
if (strlen(haystack) < needle_len)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (tail_len < needle_len)
|
if (tail_len < needle_len)
|
||||||
index += tail_len - needle_len;
|
pointer += tail_len - needle_len;
|
||||||
|
|
||||||
while (index >= haystack) {
|
while (pointer >= haystack) {
|
||||||
if (strncmp(index, needle, needle_len) == 0)
|
if (strncmp(pointer, needle, needle_len) == 0)
|
||||||
return (char *)index;
|
return (char *)pointer;
|
||||||
index--;
|
pointer--;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is equivalent to strcasestr(), except in that it scans
|
/* This function is equivalent to strcasestr(), except in that it scans
|
||||||
* the string in reverse, starting at index. */
|
* the string in reverse, starting at pointer. */
|
||||||
char *revstrcasestr(const char *haystack, const char *needle,
|
char *revstrcasestr(const char *haystack, const char *needle,
|
||||||
const char *index)
|
const char *pointer)
|
||||||
{
|
{
|
||||||
size_t needle_len = strlen(needle);
|
size_t needle_len = strlen(needle);
|
||||||
size_t tail_len = strlen(index);
|
size_t tail_len = strlen(pointer);
|
||||||
|
|
||||||
if (needle_len == 0)
|
if (needle_len == 0)
|
||||||
return (char *)index;
|
return (char *)pointer;
|
||||||
|
|
||||||
if (strlen(haystack) < needle_len)
|
if (strlen(haystack) < needle_len)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (tail_len < needle_len)
|
if (tail_len < needle_len)
|
||||||
index += tail_len - needle_len;
|
pointer += tail_len - needle_len;
|
||||||
|
|
||||||
while (index >= haystack) {
|
while (pointer >= haystack) {
|
||||||
if (strncasecmp(index, needle, needle_len) == 0)
|
if (strncasecmp(pointer, needle, needle_len) == 0)
|
||||||
return (char *)index;
|
return (char *)pointer;
|
||||||
index--;
|
pointer--;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is equivalent to strcasestr() for multibyte strings,
|
/* This function is equivalent to strcasestr() for multibyte strings,
|
||||||
* except in that it scans the string in reverse, starting at index. */
|
* except in that it scans the string in reverse, starting at pointer. */
|
||||||
char *mbrevstrcasestr(const char *haystack, const char *needle,
|
char *mbrevstrcasestr(const char *haystack, const char *needle,
|
||||||
const char *index)
|
const char *pointer)
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_UTF8
|
#ifdef ENABLE_UTF8
|
||||||
if (use_utf8) {
|
if (use_utf8) {
|
||||||
size_t tail_len, needle_len;
|
size_t tail_len, needle_len;
|
||||||
|
|
||||||
if (*needle == '\0')
|
if (*needle == '\0')
|
||||||
return (char *)index;
|
return (char *)pointer;
|
||||||
|
|
||||||
needle_len = mbstrlen(needle);
|
needle_len = mbstrlen(needle);
|
||||||
|
|
||||||
if (mbstrlen(haystack) < needle_len)
|
if (mbstrlen(haystack) < needle_len)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
tail_len = mbstrlen(index);
|
tail_len = mbstrlen(pointer);
|
||||||
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
if (tail_len >= needle_len &&
|
if (tail_len >= needle_len &&
|
||||||
mbstrncasecmp(index, needle, needle_len) == 0)
|
mbstrncasecmp(pointer, needle, needle_len) == 0)
|
||||||
return (char *)index;
|
return (char *)pointer;
|
||||||
|
|
||||||
/* If we've reached the head of the haystack, we found nothing. */
|
/* If we've reached the head of the haystack, we found nothing. */
|
||||||
if (index == haystack)
|
if (pointer == haystack)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
index = haystack + move_mbleft(haystack, index - haystack);
|
pointer = haystack + move_mbleft(haystack, pointer - haystack);
|
||||||
tail_len++;
|
tail_len++;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
return revstrcasestr(haystack, needle, index);
|
return revstrcasestr(haystack, needle, pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is equivalent to strlen() for multibyte strings. */
|
/* This function is equivalent to strlen() for multibyte strings. */
|
||||||
|
@ -647,50 +647,50 @@ char *mbstrpbrk(const char *s, const char *accept)
|
||||||
return (char *) strpbrk(s, accept);
|
return (char *) strpbrk(s, accept);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Locate the first occurrence in the string that starts at head
|
/* Locate, in the string that starts at head, the first occurrence of any of
|
||||||
* of any of the characters in the string accept, starting from
|
* the characters in the string accept, starting from pointer and searching
|
||||||
* the given index and searching backwards. */
|
* backwards. */
|
||||||
char *revstrpbrk(const char *head, const char *accept, const char *index)
|
char *revstrpbrk(const char *head, const char *accept, const char *pointer)
|
||||||
{
|
{
|
||||||
if (*index == '\0') {
|
if (*pointer == '\0') {
|
||||||
if (index == head)
|
if (pointer == head)
|
||||||
return NULL;
|
return NULL;
|
||||||
index--;
|
pointer--;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (index >= head) {
|
while (pointer >= head) {
|
||||||
if (strchr(accept, *index) != NULL)
|
if (strchr(accept, *pointer) != NULL)
|
||||||
return (char *)index;
|
return (char *)pointer;
|
||||||
index--;
|
pointer--;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The same as the preceding function but then for multibyte strings. */
|
/* The same as the preceding function but then for multibyte strings. */
|
||||||
char *mbrevstrpbrk(const char *head, const char *accept, const char *index)
|
char *mbrevstrpbrk(const char *head, const char *accept, const char *pointer)
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_UTF8
|
#ifdef ENABLE_UTF8
|
||||||
if (use_utf8) {
|
if (use_utf8) {
|
||||||
if (*index == '\0') {
|
if (*pointer == '\0') {
|
||||||
if (index == head)
|
if (pointer == head)
|
||||||
return NULL;
|
return NULL;
|
||||||
index = head + move_mbleft(head, index - head);
|
pointer = head + move_mbleft(head, pointer - head);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
if (mbstrchr(accept, index) != NULL)
|
if (mbstrchr(accept, pointer) != NULL)
|
||||||
return (char *)index;
|
return (char *)pointer;
|
||||||
|
|
||||||
/* If we've reached the head of the string, we found nothing. */
|
/* If we've reached the head of the string, we found nothing. */
|
||||||
if (index == head)
|
if (pointer == head)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
index = head + move_mbleft(head, index - head);
|
pointer = head + move_mbleft(head, pointer - head);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
return revstrpbrk(head, accept, index);
|
return revstrpbrk(head, accept, pointer);
|
||||||
}
|
}
|
||||||
#endif /* !NANO_TINY */
|
#endif /* !NANO_TINY */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue