Commit 08ab3530 authored by Christoffer Ackelman's avatar Christoffer Ackelman

simplified upper/lower case conversions

parent 1c80c602
...@@ -41,23 +41,14 @@ ...@@ -41,23 +41,14 @@
char* str_ToLower(char* dst, const char* src) char* str_ToLower(char* dst, const char* src)
{ {
char* rs = dst; char* rs = dst;
static const char cvttab[] = "\
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
!^^^^^^^^^^^^^^^^^^^^^^^^^^!!!!!\
!abcdefghijklmnopqrstuvwxyz!!!!!\
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
^^^^^^^^^^^^^^^^!^^^^^^^^^^^^^!!\
àáâãäåæçèéêëìíîï!ñòóôõö÷øùúûüý!!";
if (dst == NULL) if (dst == NULL)
return NULL; return NULL;
if (src == NULL) if (src == NULL)
src = dst; src = dst;
while (*src) while (*src)
if (cvttab[(unsigned char)*src] == '^') if ((*src >= 65 && *src <= 90) || (((unsigned char) *src) >= 192 && ((unsigned char) *src) <= 222))
*dst++ = (*src++) + 32; *dst++ = (*src++) + 32;
else else
*dst++ = *src++; *dst++ = *src++;
...@@ -70,15 +61,6 @@ char* str_ToLower(char* dst, const char* src) ...@@ -70,15 +61,6 @@ char* str_ToLower(char* dst, const char* src)
char* str_ToUpper(char* dst, const char* src) char* str_ToUpper(char* dst, const char* src)
{ {
char* rs = dst; char* rs = dst;
static const char cvttab[] = "\
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
!ABCDEFGHIJKLMNOPQRSTUVWXYZ!!!!!\
!^^^^^^^^^^^^^^^^^^^^^^^^^^!!!!!\
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ!ÑÒÓÔÕÖ×ØÙÚÛÜÝ!!\
^^^^^^^^^^^^^^^^!^^^^^^^^^^^^^!!";
if (dst == NULL) if (dst == NULL)
return NULL; return NULL;
...@@ -86,7 +68,7 @@ char* str_ToUpper(char* dst, const char* src) ...@@ -86,7 +68,7 @@ char* str_ToUpper(char* dst, const char* src)
src = dst; src = dst;
while (*src) while (*src)
if (cvttab[(unsigned char)*src] == '^') if ((*src >= 97 && *src <= 122) || (((unsigned char) *src) >= 224 && ((unsigned char) *src) <= 254))
*dst++ = (*src++) - 32; *dst++ = (*src++) - 32;
else else
*dst++ = *src++; *dst++ = *src++;
......
...@@ -38,8 +38,15 @@ ...@@ -38,8 +38,15 @@
#include <string.h> #include <string.h>
/*!
Checks if two strings a and b are equal
strcmp returns 0 (i.e. false) if the strings are equal, which is not that obvious
*/
#define streq(a,b) (strcmp((a),(b)) == 0) #define streq(a,b) (strcmp((a),(b)) == 0)
/*!
Checks if the string 'str' starts with the substring 'prefix'
*/
#define str_StartsWith(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0) #define str_StartsWith(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0)
#ifdef __cplusplus #ifdef __cplusplus
...@@ -48,21 +55,23 @@ extern "C" { ...@@ -48,21 +55,23 @@ extern "C" {
//! Convert string to lower case. //! Convert string to lower case.
/*! /*!
If s is NULL, t is used also as input string. Handles all ISO 8859-1 characters, not only ASCII.
If src is NULL, dst is used also as input string.
\param t Output string. \param dst Output string.
\param s Input string. \param src Input string.
\return Returns t. \return Returns dst.
*/ */
char* str_ToLower(char* dst, const char* src); char* str_ToLower(char* dst, const char* src);
//! Convert string to upper case. //! Convert string to upper case.
/*! /*!
If s is NULL, t is used also as input string. Handles all ISO 8859-1 characters, not only ASCII.
If src is NULL, dst is used also as input string.
\param t Output string. \param dst Output string.
\param s Input string. \param src Input string.
\return Returns t. \return Returns dst.
*/ */
char* str_ToUpper(char* dst, const char* src); char* str_ToUpper(char* dst, const char* src);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment