13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
#include "drizzled/charset.h"
19
#include "drizzled/error.h"
20
#include "drizzled/charset_info.h"
21
#include "drizzled/internal/m_string.h"
16
#include "mysys_priv.h"
17
#include "mysys_err.h"
18
#include <mystrings/m_ctype.h>
19
#include <mystrings/m_string.h>
22
20
#include <drizzled/configmake.h>
31
We collect memory in this vector that we free on delete.
33
static vector<void *>memory_vector;
36
24
The code below implements this functionality:
70
58
unsigned char *state_map;
71
59
unsigned char *ident_map;
73
if (!(cs->state_map= (unsigned char*) cs_alloc(256)))
61
if (!(cs->state_map= (unsigned char*) malloc(256)))
76
if (!(cs->ident_map= (unsigned char*) cs_alloc(256)))
64
if (!(cs->ident_map= (unsigned char*) malloc(256)))
79
67
state_map= cs->state_map;
86
74
state_map[i]=(unsigned char) MY_LEX_IDENT;
87
75
else if (my_isdigit(cs,i))
88
76
state_map[i]=(unsigned char) MY_LEX_NUMBER_IDENT;
77
#if defined(USE_MB) && defined(USE_MB_IDENT)
89
78
else if (my_mbcharlen(cs, i)>1)
90
79
state_map[i]=(unsigned char) MY_LEX_IDENT;
91
81
else if (my_isspace(cs,i))
92
82
state_map[i]=(unsigned char) MY_LEX_SKIP;
285
Resolve character set by the character set name (utf8, latin1, ...).
287
The function tries to resolve character set by the specified name. If
288
there is character set with the given name, it is assigned to the "cs"
289
parameter and false is returned. If there is no such character set,
290
"default_cs" is assigned to the "cs" and true is returned.
292
@param[in] cs_name Character set name.
293
@param[in] default_cs Default character set.
294
@param[out] cs Variable to store character set.
296
@return false if character set was resolved successfully; true if there
297
is no character set with given name.
300
bool resolve_charset(const char *cs_name,
301
const CHARSET_INFO *default_cs,
302
const CHARSET_INFO **cs)
304
*cs= get_charset_by_csname(cs_name, MY_CS_PRIMARY);
317
Resolve collation by the collation name (utf8_general_ci, ...).
319
The function tries to resolve collation by the specified name. If there
320
is collation with the given name, it is assigned to the "cl" parameter
321
and false is returned. If there is no such collation, "default_cl" is
322
assigned to the "cl" and true is returned.
324
@param[out] cl Variable to store collation.
325
@param[in] cl_name Collation name.
326
@param[in] default_cl Default collation.
328
@return false if collation was resolved successfully; true if there is no
329
collation with given name.
332
bool resolve_collation(const char *cl_name,
333
const CHARSET_INFO *default_cl,
334
const CHARSET_INFO **cl)
336
*cl= get_charset_by_name(cl_name);
348
#ifdef BACKSLASH_MBTAIL
349
static CHARSET_INFO *fs_cset_cache= NULL;
351
CHARSET_INFO *fs_character_set()
356
GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_IDEFAULTANSICODEPAGE,
357
buf+2, sizeof(buf)-3);
359
We cannot call get_charset_by_name here
360
because fs_character_set() is executed before
361
LOCK_THD_charset mutex initialization, which
362
is used inside get_charset_by_name.
363
As we're now interested in cp932 only,
364
let's just detect it using strcmp().
366
fs_cset_cache= !strcmp(buf, "cp932") ?
367
&my_charset_cp932_japanese_ci : &my_charset_bin;
369
return fs_cset_cache;
309
374
Escape apostrophes by doubling them up
337
402
const char *to_start= to;
338
403
const char *end, *to_end=to_start + (to_length ? to_length-1 : 2*length);
339
404
bool overflow= false;
340
406
bool use_mb_flag= use_mb(charset_info);
341
408
for (end= from + length; from < end; from++)
344
412
if (use_mb_flag && (tmp_length= my_ismbchar(charset_info, from, end)))