ctype-mb.c 2.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* Copyright (C) 2000 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#include <my_global.h>
#include "m_ctype.h"

20 21 22
#ifdef USE_MB


23 24 25 26
void my_caseup_str_mb(CHARSET_INFO * cs, char *str)
{
  register uint32 l;
  register char *end=str+strlen(str); /* BAR TODO: remove strlen() call */
unknown's avatar
unknown committed
27 28
  register uchar *map=cs->to_upper;
  
29 30 31 32 33 34
  while (*str)
  {
    if ((l=my_ismbchar(cs, str,end)))
      str+=l;
    else
    { 
unknown's avatar
unknown committed
35
      *str=(char) map[(uchar)*str];
36 37 38 39 40 41 42 43 44
      str++;
    }
  }
}

void my_casedn_str_mb(CHARSET_INFO * cs, char *str)
{
  register uint32 l;
  register char *end=str+strlen(str);
unknown's avatar
unknown committed
45 46
  register uchar *map=cs->to_lower;
  
47 48 49 50 51 52
  while (*str)
  {
    if ((l=my_ismbchar(cs, str,end)))
      str+=l;
    else
    {
unknown's avatar
unknown committed
53
      *str=(char) map[(uchar)*str];
54 55 56 57 58 59 60 61 62
      str++;
    }
  }
}

void my_caseup_mb(CHARSET_INFO * cs, char *str, uint length)
{
  register uint32 l;
  register char *end=str+length;
unknown's avatar
unknown committed
63 64
  register uchar *map=cs->to_upper;
  
65 66 67 68 69 70
  while (str<end)
  {
    if ((l=my_ismbchar(cs, str,end)))
      str+=l;
    else 
    {
unknown's avatar
unknown committed
71
      *str=(char) map[(uchar)*str];
72 73 74 75 76 77 78 79 80
      str++;
    }
  }
}

void my_casedn_mb(CHARSET_INFO * cs, char *str, uint length)
{
  register uint32 l;
  register char *end=str+length;
unknown's avatar
unknown committed
81 82
  register uchar *map=cs->to_lower;
  
83 84 85 86 87 88
  while (str<end)
  {
    if ((l=my_ismbchar(cs, str,end)))
      str+=l;
    else
    {
unknown's avatar
unknown committed
89
      *str=(char) map[(uchar)*str];
90 91 92 93 94 95 96 97 98
      str++;
    }
  }
}

int my_strcasecmp_mb(CHARSET_INFO * cs,const char *s, const char *t)
{
  register uint32 l;
  register const char *end=s+strlen(s);
unknown's avatar
unknown committed
99 100
  register uchar *map=cs->to_upper;
  
101 102 103 104 105 106 107 108 109 110
  while (s<end)
  {
    if ((l=my_ismbchar(cs, s,end)))
    {
      while (l--)
        if (*s++ != *t++) 
          return 1;
    }
    else if (my_ismbhead(cs, *t)) 
      return 1;
unknown's avatar
unknown committed
111
    else if (map[(uchar) *s++] != map[(uchar) *t++])
112 113 114 115 116 117 118 119 120 121 122
      return 1;
  }
  return *t;
}


int my_strncasecmp_mb(CHARSET_INFO * cs,
				const char *s, const char *t, uint len)
{
  register uint32 l;
  register const char *end=s+len;
unknown's avatar
unknown committed
123 124
  register uchar *map=cs->to_upper;
  
125 126 127 128 129 130 131 132 133 134
  while (s<end)
  {
    if ((l=my_ismbchar(cs, s,end)))
    {
      while (l--)
        if (*s++ != *t++) 
          return 1;
    }
    else if (my_ismbhead(cs, *t)) 
      return 1;
unknown's avatar
unknown committed
135
    else if (map[(uchar) *s++] != map[(uchar) *t++]) 
136 137 138 139 140
      return 1;
  }
  return 0;
}

141
#endif