ReactOS  0.4.14-dev-77-gd9e7c48
mbsncoll.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS system libraries
4  * FILE: lib/sdk/crt/mbstring/mbsncoll.c
5  * PURPOSE:
6  * PROGRAMER: Ariadne
7  * UPDATE HISTORY:
8  * 12/04/99: Created
9  */
10 #include <mbstring.h>
11 
12 
13 int colldif(unsigned short c1, unsigned short c2)
14 {
15  return c1 - c2;
16 }
17 
18 /*
19  * @implemented
20  */
21 int _mbsncoll(const unsigned char *str1, const unsigned char *str2, size_t n)
22 {
23  unsigned char *s1 = (unsigned char *)str1;
24  unsigned char *s2 = (unsigned char *)str2;
25 
26  unsigned short *short_s1, *short_s2;
27 
28  int l1, l2;
29 
30  if (n == 0)
31  return 0;
32  do {
33 
34  if (*s1 == 0)
35  break;
36 
37  l1 = _ismbblead(*s1);
38  l2 = _ismbblead(*s2);
39  if ( !l1 && !l2 ) {
40 
41  if (*s1 != *s2)
42  return colldif(*s1, *s2);
43  else {
44  s1 += 1;
45  s2 += 1;
46  n--;
47  }
48  }
49  else if ( l1 && l2 ){
50  short_s1 = (unsigned short *)s1;
51  short_s2 = (unsigned short *)s2;
52  if ( *short_s1 != *short_s2 )
53  return colldif(*short_s1, *short_s2);
54  else {
55  s1 += 2;
56  s2 += 2;
57  n--;
58 
59  }
60  }
61  else
62  return colldif(*s1, *s2);
63  } while (n > 0);
64  return 0;
65 }
66 
67 /*
68  * @implemented
69  */
70 int _mbsnbcoll(const unsigned char *str1, const unsigned char *str2, size_t n)
71 {
72  unsigned char *s1 = (unsigned char *)str1;
73  unsigned char *s2 = (unsigned char *)str2;
74 
75  unsigned short *short_s1, *short_s2;
76 
77  int l1, l2;
78 
79  if (n == 0)
80  return 0;
81  do {
82 
83  if (*s1 == 0)
84  break;
85 
86  l1 = _ismbblead(*s1);
87  l2 = _ismbblead(*s2);
88  if ( !l1 && !l2 ) {
89 
90  if (*s1 != *s2)
91  return colldif(*s1, *s2);
92  else {
93  s1 += 1;
94  s2 += 1;
95  n--;
96  }
97  }
98  else if ( l1 && l2 ){
99  short_s1 = (unsigned short *)s1;
100  short_s2 = (unsigned short *)s2;
101  if ( *short_s1 != *short_s2 )
102  return colldif(*short_s1, *short_s2);
103  else {
104  s1 += 2;
105  s2 += 2;
106  n-=2;
107 
108  }
109  }
110  else
111  return colldif(*s1, *s2);
112  } while (n > 0);
113  return 0;
114 }
115 
struct S2 s2
GLdouble n
Definition: glext.h:7729
int colldif(unsigned short c1, unsigned short c2)
Definition: mbsncoll.c:13
int _mbsncoll(const unsigned char *str1, const unsigned char *str2, size_t n)
Definition: mbsncoll.c:21
struct S1 s1
int _mbsnbcoll(const unsigned char *str1, const unsigned char *str2, size_t n)
Definition: mbsncoll.c:70
int __cdecl _ismbblead(unsigned int)
Definition: ismblead.c:20