From: James Tirta Halim <tirtajames45@gmail.com>
To: libc-alpha@sourceware.org
Cc: James Tirta Halim <tirtajames45@gmail.com>
Subject: [PATCH] strcasestr: check if ne[0] is in hs with strchr or strpbrk as does strstr
Date: Thu, 7 Sep 2023 00:42:30 +0700 [thread overview]
Message-ID: <20230906174230.306332-1-tirtajames45@gmail.com> (raw)
---
string/strcasestr.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/string/strcasestr.c b/string/strcasestr.c
index 2f6b4f8641..295cbf364d 100644
--- a/string/strcasestr.c
+++ b/string/strcasestr.c
@@ -67,6 +67,14 @@ STRCASESTR (const char *haystack, const char *needle)
/* Handle empty NEEDLE special case. */
if (needle[0] == '\0')
return (char *) haystack;
+ if (isalpha(*needle)) {
+ const char a[] = { tolower(*needle), toupper(*needle), '\0'};
+ haystack = strpbrk(haystack, a);
+ } else {
+ haystack = strchr(haystack, *needle);
+ }
+ if (haystack == NULL || needle[1] == '\0')
+ return (char *)haystack;
/* Ensure HAYSTACK length is at least as long as NEEDLE length.
Since a match may occur early on in a huge HAYSTACK, use strnlen
--
2.42.0
next reply other threads:[~2023-09-06 17:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-06 17:42 James Tirta Halim [this message]
2023-09-07 22:14 Wilco Dijkstra
2023-10-14 8:32 ` James Tirta Halim
2023-10-16 12:59 ` Adhemerval Zanella Netto
2023-10-16 13:52 ` Wilco Dijkstra
2023-10-16 16:56 ` Noah Goldstein
2023-10-17 9:57 ` Wilco Dijkstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230906174230.306332-1-tirtajames45@gmail.com \
--to=tirtajames45@gmail.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).