summaryrefslogtreecommitdiff
path: root/src/libstddjb
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstddjb')
-rw-r--r--src/libstddjb/case_lowerb.c7
-rw-r--r--src/libstddjb/case_lowers.c7
-rw-r--r--src/libstddjb/case_startb.c1
-rw-r--r--src/libstddjb/case_str.c33
-rw-r--r--src/libstddjb/case_upperb.c7
-rw-r--r--src/libstddjb/case_uppers.c7
6 files changed, 17 insertions, 45 deletions
diff --git a/src/libstddjb/case_lowerb.c b/src/libstddjb/case_lowerb.c
index 66284df..7cc5331 100644
--- a/src/libstddjb/case_lowerb.c
+++ b/src/libstddjb/case_lowerb.c
@@ -1,13 +1,14 @@
/* ISC license. */
+#include <ctype.h>
+
#include <skalibs/bytestr.h>
void case_lowerb (char *s, size_t len)
{
- unsigned char const d = 'a' - 'A' ;
while (len--)
{
- if (('A' <= *s) && (*s <= 'Z')) *s += d ;
- ++s ;
+ int c = tolower(*s) ;
+ *s++ = (unsigned char)c ;
}
}
diff --git a/src/libstddjb/case_lowers.c b/src/libstddjb/case_lowers.c
index 349eade..a674f28 100644
--- a/src/libstddjb/case_lowers.c
+++ b/src/libstddjb/case_lowers.c
@@ -1,13 +1,14 @@
/* ISC license. */
+#include <ctype.h>
+
#include <skalibs/bytestr.h>
void case_lowers (char *s)
{
- unsigned char const d = 'a' - 'A' ;
while (*s)
{
- if (('A' <= *s) && (*s <= 'Z')) *s += d ;
- ++s ;
+ int c = tolower(*s) ;
+ *s++ = (unsigned char)c ;
}
}
diff --git a/src/libstddjb/case_startb.c b/src/libstddjb/case_startb.c
index 42e12f2..8b98631 100644
--- a/src/libstddjb/case_startb.c
+++ b/src/libstddjb/case_startb.c
@@ -2,6 +2,7 @@
#include <string.h>
#include <strings.h>
+
#include <skalibs/bytestr.h>
int case_startb (char const *s, size_t slen, char const *t)
diff --git a/src/libstddjb/case_str.c b/src/libstddjb/case_str.c
deleted file mode 100644
index 59f157f..0000000
--- a/src/libstddjb/case_str.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/* ISC license. */
-
-#include <skalibs/sysdeps.h>
-
-#ifdef SKALIBS_HASSTRCASESTR
-
-#include <skalibs/nonposix.h>
-#include <string.h>
-#include <skalibs/bytestr.h>
-
-size_t case_str (char const *haystack, char const *needle)
-{
- char *p = strcasestr(haystack, needle) ;
- return p ? p - haystack : strlen(haystack) ;
-}
-
-#else
-
-#include <string.h>
-#include <strings.h>
-#include <skalibs/bytestr.h>
-
-size_t case_str (char const *haystack, char const *needle)
-{
- size_t nlen = strlen(needle) ;
- char const *p = haystack ;
- if (!nlen) return 0 ;
- for (; *p ; p++)
- if (!strncasecmp(p, needle, nlen)) return p - haystack ;
- return strlen(haystack) ;
-}
-
-#endif
diff --git a/src/libstddjb/case_upperb.c b/src/libstddjb/case_upperb.c
index 78ece8f..f245f4d 100644
--- a/src/libstddjb/case_upperb.c
+++ b/src/libstddjb/case_upperb.c
@@ -1,13 +1,14 @@
/* ISC license. */
+#include <ctype.h>
+
#include <skalibs/bytestr.h>
void case_upperb (char *s, size_t len)
{
- unsigned char const d = 'a' - 'A' ;
while (len--)
{
- if (('a' <= *s) && (*s <= 'z')) *s -= d ;
- ++s ;
+ int c = toupper(*s) ;
+ *s++ = (unsigned char)c ;
}
}
diff --git a/src/libstddjb/case_uppers.c b/src/libstddjb/case_uppers.c
index da0837c..4191711 100644
--- a/src/libstddjb/case_uppers.c
+++ b/src/libstddjb/case_uppers.c
@@ -1,13 +1,14 @@
/* ISC license. */
+#include <ctype.h>
+
#include <skalibs/bytestr.h>
void case_uppers (char *s)
{
- unsigned char const d = 'a' - 'A' ;
while (*s)
{
- if (('a' <= *s) && (*s <= 'z')) *s -= d ;
- ++s ;
+ int c = toupper(*s) ;
+ *s++ = (unsigned char)c ;
}
}