~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/charset.cc

  • Committer: Olaf van der Spek
  • Date: 2011-02-12 17:09:31 UTC
  • mto: (2167.1.2 build) (2172.1.4 build)
  • mto: This revision was merged to the branch mainline in revision 2168.
  • Revision ID: olafvdspek@gmail.com-20110212170931-k1fg0lzsmm5i3ciq
casts

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
/*
33
33
  We collect memory in this vector that we free on delete.
34
34
*/
35
 
static vector<void *>memory_vector;
 
35
static vector<unsigned char*> memory_vector;
36
36
 
37
37
/*
38
38
  The code below implements this functionality:
53
53
static uint
54
54
get_collation_number_internal(const char *name)
55
55
{
56
 
  CHARSET_INFO **cs;
57
 
  for (cs= all_charsets;
58
 
       cs < all_charsets+array_elements(all_charsets)-1 ;
 
56
  for (CHARSET_INFO **cs= all_charsets;
 
57
       cs < all_charsets+array_elements(all_charsets)-1;
59
58
       cs++)
60
59
  {
61
60
    if ( cs[0] && cs[0]->name && !my_strcasecmp(&my_charset_utf8_general_ci, cs[0]->name, name))
66
65
  return 0;
67
66
}
68
67
 
 
68
static unsigned char *cs_alloc(size_t size)
 
69
{
 
70
  memory_vector.push_back(new unsigned char[size]);
 
71
  return memory_vector.back();
 
72
}
69
73
 
70
74
static bool init_state_maps(CHARSET_INFO *cs)
71
75
{
72
 
  uint32_t i;
73
 
  unsigned char *state_map;
74
 
  unsigned char *ident_map;
75
 
 
76
 
  if (!(cs->state_map= (unsigned char*) cs_alloc(256)))
 
76
  if (!(cs->state_map= cs_alloc(256)))
77
77
    return 1;
78
78
    
79
 
  if (!(cs->ident_map= (unsigned char*) cs_alloc(256)))
 
79
  if (!(cs->ident_map= cs_alloc(256)))
80
80
    return 1;
81
81
 
82
 
  state_map= cs->state_map;
83
 
  ident_map= cs->ident_map;
 
82
  unsigned char *state_map= cs->state_map;
 
83
  unsigned char *ident_map= cs->ident_map;
84
84
 
85
85
  /* Fill state_map with states to get a faster parser */
86
 
  for (i=0; i < 256 ; i++)
 
86
  for (int i= 0; i < 256; i++)
87
87
  {
88
88
    if (my_isalpha(cs,i))
89
 
      state_map[i]=(unsigned char) MY_LEX_IDENT;
 
89
      state_map[i]= MY_LEX_IDENT;
90
90
    else if (my_isdigit(cs,i))
91
 
      state_map[i]=(unsigned char) MY_LEX_NUMBER_IDENT;
 
91
      state_map[i]= MY_LEX_NUMBER_IDENT;
92
92
    else if (my_mbcharlen(cs, i)>1)
93
 
      state_map[i]=(unsigned char) MY_LEX_IDENT;
 
93
      state_map[i]= MY_LEX_IDENT;
94
94
    else if (my_isspace(cs,i))
95
 
      state_map[i]=(unsigned char) MY_LEX_SKIP;
 
95
      state_map[i]= MY_LEX_SKIP;
96
96
    else
97
 
      state_map[i]=(unsigned char) MY_LEX_CHAR;
 
97
      state_map[i]= MY_LEX_CHAR;
98
98
  }
99
 
  state_map[(unsigned char)'_']=state_map[(unsigned char)'$']=(unsigned char) MY_LEX_IDENT;
100
 
  state_map[(unsigned char)'\'']=(unsigned char) MY_LEX_STRING;
101
 
  state_map[(unsigned char)'.']=(unsigned char) MY_LEX_REAL_OR_POINT;
102
 
  state_map[(unsigned char)'>']=state_map[(unsigned char)'=']=state_map[(unsigned char)'!']= (unsigned char) MY_LEX_CMP_OP;
103
 
  state_map[(unsigned char)'<']= (unsigned char) MY_LEX_LONG_CMP_OP;
104
 
  state_map[(unsigned char)'&']=state_map[(unsigned char)'|']=(unsigned char) MY_LEX_BOOL;
105
 
  state_map[(unsigned char)'#']=(unsigned char) MY_LEX_COMMENT;
106
 
  state_map[(unsigned char)';']=(unsigned char) MY_LEX_SEMICOLON;
107
 
  state_map[(unsigned char)':']=(unsigned char) MY_LEX_SET_VAR;
108
 
  state_map[0]=(unsigned char) MY_LEX_EOL;
109
 
  state_map[(unsigned char)'\\']= (unsigned char) MY_LEX_ESCAPE;
110
 
  state_map[(unsigned char)'/']= (unsigned char) MY_LEX_LONG_COMMENT;
111
 
  state_map[(unsigned char)'*']= (unsigned char) MY_LEX_END_LONG_COMMENT;
112
 
  state_map[(unsigned char)'@']= (unsigned char) MY_LEX_USER_END;
113
 
  state_map[(unsigned char) '`']= (unsigned char) MY_LEX_USER_VARIABLE_DELIMITER;
114
 
  state_map[(unsigned char)'"']= (unsigned char) MY_LEX_STRING_OR_DELIMITER;
 
99
  state_map['_']=state_map['$']= MY_LEX_IDENT;
 
100
  state_map['\'']= MY_LEX_STRING;
 
101
  state_map['.']= MY_LEX_REAL_OR_POINT;
 
102
  state_map['>']=state_map['=']=state_map['!']=  MY_LEX_CMP_OP;
 
103
  state_map['<']=  MY_LEX_LONG_CMP_OP;
 
104
  state_map['&']=state_map['|']= MY_LEX_BOOL;
 
105
  state_map['#']= MY_LEX_COMMENT;
 
106
  state_map[';']= MY_LEX_SEMICOLON;
 
107
  state_map[':']= MY_LEX_SET_VAR;
 
108
  state_map[0]= MY_LEX_EOL;
 
109
  state_map['\\']=  MY_LEX_ESCAPE;
 
110
  state_map['/']=  MY_LEX_LONG_COMMENT;
 
111
  state_map['*']=  MY_LEX_END_LONG_COMMENT;
 
112
  state_map['@']=  MY_LEX_USER_END;
 
113
  state_map['`']=  MY_LEX_USER_VARIABLE_DELIMITER;
 
114
  state_map['"']=  MY_LEX_STRING_OR_DELIMITER;
115
115
 
116
116
  /*
117
117
    Create a second map to make it faster to find identifiers
118
118
  */
119
 
  for (i=0; i < 256 ; i++)
 
119
  for (int i= 0; i < 256; i++)
120
120
  {
121
 
    ident_map[i]= (unsigned char) (state_map[i] == MY_LEX_IDENT ||
122
 
                           state_map[i] == MY_LEX_NUMBER_IDENT);
 
121
    ident_map[i]= state_map[i] == MY_LEX_IDENT || state_map[i] == MY_LEX_NUMBER_IDENT;
123
122
  }
124
123
 
125
124
  /* Special handling of hex and binary strings */
126
 
  state_map[(unsigned char)'x']= state_map[(unsigned char)'X']= (unsigned char) MY_LEX_IDENT_OR_HEX;
127
 
  state_map[(unsigned char)'b']= state_map[(unsigned char)'B']= (unsigned char) MY_LEX_IDENT_OR_BIN;
 
125
  state_map['x']= state_map['X']=  MY_LEX_IDENT_OR_HEX;
 
126
  state_map['b']= state_map['B']=  MY_LEX_IDENT_OR_BIN;
128
127
  return 0;
129
128
}
130
129
 
131
 
 
132
130
static bool charset_initialized= false;
133
131
 
134
132
DRIZZLED_API CHARSET_INFO *all_charsets[256];
140
138
  cs->state|= MY_CS_AVAILABLE;
141
139
}
142
140
 
143
 
void *cs_alloc(size_t size)
144
 
{
145
 
  void *ptr= malloc(size);
146
 
 
147
 
  memory_vector.push_back(ptr);
148
 
 
149
 
  return ptr;
150
 
}
151
 
 
152
 
 
153
 
 
154
141
static bool init_available_charsets(myf myflags)
155
142
{
156
143
  bool error= false;
185
172
}
186
173
 
187
174
 
188
 
void free_charsets(void)
 
175
void free_charsets()
189
176
{
190
 
  charset_initialized= true;
 
177
  charset_initialized= true; // olaf: shouldn't this be = false?
191
178
 
192
 
  while (memory_vector.empty() == false)
 
179
  while (!memory_vector.empty())
193
180
  {
194
 
    void *ptr= memory_vector.back();
 
181
    delete[] memory_vector.back();
195
182
    memory_vector.pop_back();
196
 
    free(ptr);
197
183
  }
198
 
  memory_vector.clear();
199
 
 
200
184
}
201
185
 
202
186
 
225
209
 
226
210
const char *get_charset_name(uint32_t charset_number)
227
211
{
228
 
  const CHARSET_INFO *cs;
229
212
  init_available_charsets(MYF(0));
230
213
 
231
 
  cs=all_charsets[charset_number];
 
214
  const CHARSET_INFO *cs= all_charsets[charset_number];
232
215
  if (cs && (cs->number == charset_number) && cs->name )
233
 
    return (char*) cs->name;
 
216
    return cs->name;
234
217
 
235
 
  return (char*) "?";   /* this mimics find_type() */
 
218
  return "?";   /* this mimics find_type() */
236
219
}
237
220
 
238
221
 
381
364
    }
382
365
  }
383
366
  *to= 0;
384
 
  return overflow ? UINT32_MAX : (uint32_t) (to - to_start);
 
367
  return overflow ? UINT32_MAX : to - to_start;
385
368
}
386
369
 
387
370
} /* namespace drizzled */