summaryrefslogtreecommitdiff
path: root/mysys/mf_casecnv.c
blob: 631db18b1edd8724499e56c98048b0f279874d78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* 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 */

/*
  Functions to convert to lover_case and to upper_case in scandinavia.

  case_sort converts a character string to a representaion that can
  be compared by strcmp to find with is alfabetical bigger.
  (lower- and uppercase letters is compared as the same)
*/

#include "mysys_priv.h"
#include <m_ctype.h>
#ifndef SCO
#include <m_string.h>
#endif


	/* to sort-string that can be compared to get text in order */

void case_sort(CHARSET_INFO *cs, my_string str, uint length)
{
  register uchar *map=cs->sort_order;
  
  for ( ; length>0 ; length--, str++)
    *str= (char) map[(uchar) *str];
} /* case_sort */


int my_sortcmp(CHARSET_INFO *cs, const char *s, const char *t, uint len)
{
#ifdef USE_STRCOLL
  if (use_strcoll(cs))
    return my_strnncoll(cs,(uchar *)s, len, (uchar *)t, len);
  else
#endif
  {
    register uchar *map=cs->sort_order;
    while (len--)
    {
      if (map[(uchar) *s++] != map[(uchar) *t++])
        return ((int) map[(uchar) s[-1]] - (int) map[(uchar) t[-1]]);
    }
    return 0;
  }
}

int my_sortncmp(CHARSET_INFO *cs,
                const char *s, uint s_len, 
                const char *t, uint t_len)
{
#ifdef USE_STRCOLL
  if (use_strcoll(cs))
    return my_strnncoll(cs, (uchar *)s, s_len, (uchar *)t, t_len);
  else
#endif
  {
    uint len= min(s_len,t_len);
    register uchar *map=cs->sort_order;
    
    while (len--)
    {
      if (map[(uchar) *s++] != map[(uchar) *t++])
        return ((int) map[(uchar) s[-1]] - (int) map[(uchar) t[-1]]);
    }
    return (int) (s_len - t_len);
  }
}