~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mystrings/ctype.cc

  • Committer: Brian Aker
  • Date: 2009-05-15 19:17:03 UTC
  • mto: This revision was merged to the branch mainline in revision 1023.
  • Revision ID: brian@gaz-20090515191703-bhfoodfaenh6gp9z
Force UTF8 (remove the bits for looking for ascii).

This is a reverse of commit 31951 from MySQL.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
  CHARSET_INFO cs;
61
61
  int (*add_collation)(CHARSET_INFO *cs);
62
62
} MY_CHARSET_LOADER;
63
 
 
64
 
 
65
 
 
66
 
/*
67
 
  Check repertoire: detect pure ascii strings
68
 
*/
69
 
uint
70
 
my_string_repertoire(const CHARSET_INFO * const cs, const char *str, ulong length)
71
 
{
72
 
  const char *strend= str + length;
73
 
  if (cs->mbminlen == 1)
74
 
  {
75
 
    for ( ; str < strend; str++)
76
 
    {
77
 
      if (((unsigned char) *str) > 0x7F)
78
 
        return MY_REPERTOIRE_UNICODE30;
79
 
    }
80
 
  }
81
 
  else
82
 
  {
83
 
    my_wc_t wc;
84
 
    int chlen;
85
 
    for (; (chlen= cs->cset->mb_wc(cs, &wc, (unsigned char *)str, (unsigned char *)strend)) > 0; str+= chlen)
86
 
    {
87
 
      if (wc > 0x7F)
88
 
        return MY_REPERTOIRE_UNICODE30;
89
 
    }
90
 
  }
91
 
  return MY_REPERTOIRE_ASCII;
92
 
}
93
 
 
94
 
 
95
 
/*
96
 
  Detect whether a character set is ASCII compatible.
97
 
 
98
 
  Returns true for:
99
 
 
100
 
  - all 8bit character sets whose Unicode mapping of 0x7B is '{'
101
 
    (ignores swe7 which maps 0x7B to "LATIN LETTER A WITH DIAERESIS")
102
 
 
103
 
  - all multi-byte character sets having mbminlen == 1
104
 
    (ignores ucs2 whose mbminlen is 2)
105
 
 
106
 
  TODO:
107
 
 
108
 
  When merging to 5.2, this function should be changed
109
 
  to check a new flag MY_CS_NONASCII,
110
 
 
111
 
     return (cs->flag & MY_CS_NONASCII) ? 0 : 1;
112
 
 
113
 
  This flag was previously added into 5.2 under terms
114
 
  of WL#3759 "Optimize identifier conversion in client-server protocol"
115
 
  especially to mark character sets not compatible with ASCII.
116
 
 
117
 
  We won't backport this flag to 5.0 or 5.1.
118
 
  This function is Ok for 5.0 and 5.1, because we're not going
119
 
  to introduce new tricky character sets between 5.0 and 5.2.
120
 
*/
121
 
bool
122
 
my_charset_is_ascii_based(const CHARSET_INFO * const cs)
123
 
{
124
 
  return
125
 
    (cs->mbmaxlen == 1 && cs->tab_to_uni && cs->tab_to_uni['{'] == '{') ||
126
 
    (cs->mbminlen == 1 && cs->mbmaxlen > 1);
127
 
}
128
 
 
129
 
 
130
 
/*
131
 
  Detect if a character set is 8bit,
132
 
  and it is pure ascii, i.e. doesn't have
133
 
  characters outside U+0000..U+007F
134
 
  This functions is shared between "conf_to_src"
135
 
  and dynamic charsets loader in "mysqld".
136
 
*/
137
 
bool
138
 
my_charset_is_8bit_pure_ascii(const CHARSET_INFO * const cs)
139
 
{
140
 
  size_t code;
141
 
  if (!cs->tab_to_uni)
142
 
    return 0;
143
 
  for (code= 0; code < 256; code++)
144
 
  {
145
 
    if (cs->tab_to_uni[code] > 0x7F)
146
 
      return 0;
147
 
  }
148
 
  return 1;
149
 
}
150
 
 
151
 
 
152
 
/*
153
 
  Shared function between conf_to_src and mysys.
154
 
  Check if a 8bit character set is compatible with
155
 
  ascii on the range 0x00..0x7F.
156
 
*/
157
 
bool
158
 
my_charset_is_ascii_compatible(const CHARSET_INFO * const cs)
159
 
{
160
 
  uint32_t i;
161
 
  if (!cs->tab_to_uni)
162
 
    return 1;
163
 
  for (i= 0; i < 128; i++)
164
 
  {
165
 
    if (cs->tab_to_uni[i] != i)
166
 
      return 0;
167
 
  }
168
 
  return 1;
169
 
}