~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/charset.cc

  • Committer: devananda
  • Date: 2009-07-01 17:38:47 UTC
  • mto: (1093.1.7 captain)
  • mto: This revision was merged to the branch mainline in revision 1095.
  • Revision ID: devananda.vdv@gmail.com-20090701173847-3n3mbtessg5ff35e
refactored function/benchmark into plugin/benchmark

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
 
 
16
 
#include "config.h"
17
 
 
18
 
#include "drizzled/charset.h"
19
 
#include "drizzled/error.h"
20
 
#include "drizzled/charset_info.h"
21
 
#include "drizzled/internal/m_string.h"
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include "mysys/mysys_priv.h"
 
17
#include "mysys/mysys_err.h"
 
18
#include <mystrings/m_ctype.h>
 
19
#include <mystrings/m_string.h>
22
20
#include <drizzled/configmake.h>
23
 
#include <vector>
24
 
 
25
 
using namespace std;
26
 
 
27
 
namespace drizzled
28
 
{
29
 
 
30
 
/*
31
 
  We collect memory in this vector that we free on delete.
32
 
*/
33
 
static vector<void *>memory_vector;
 
21
 
34
22
 
35
23
/*
36
24
  The code below implements this functionality:
70
58
  unsigned char *state_map;
71
59
  unsigned char *ident_map;
72
60
 
73
 
  if (!(cs->state_map= (unsigned char*) cs_alloc(256)))
 
61
  if (!(cs->state_map= (unsigned char*) malloc(256)))
74
62
    return 1;
75
63
    
76
 
  if (!(cs->ident_map= (unsigned char*) cs_alloc(256)))
 
64
  if (!(cs->ident_map= (unsigned char*) malloc(256)))
77
65
    return 1;
78
66
 
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;
 
80
#endif
91
81
    else if (my_isspace(cs,i))
92
82
      state_map[i]=(unsigned char) MY_LEX_SKIP;
93
83
    else
139
129
 
140
130
void *cs_alloc(size_t size)
141
131
{
142
 
  void *ptr= malloc(size);
143
 
 
144
 
  memory_vector.push_back(ptr);
145
 
 
146
 
  return ptr;
 
132
  return malloc(size);
147
133
}
148
134
 
149
135
 
150
 
 
151
136
static bool init_available_charsets(myf myflags)
152
137
{
153
138
  bool error= false;
185
170
void free_charsets(void)
186
171
{
187
172
  charset_initialized= true;
188
 
 
189
 
  while (memory_vector.empty() == false)
190
 
  {
191
 
    void *ptr= memory_vector.back();
192
 
    memory_vector.pop_back();
193
 
    free(ptr);
194
 
  }
195
 
  memory_vector.clear();
196
 
 
197
173
}
198
174
 
199
175
 
337
313
  const char *to_start= to;
338
314
  const char *end, *to_end=to_start + (to_length ? to_length-1 : 2*length);
339
315
  bool overflow= false;
 
316
#ifdef USE_MB
340
317
  bool use_mb_flag= use_mb(charset_info);
 
318
#endif
341
319
  for (end= from + length; from < end; from++)
342
320
  {
 
321
#ifdef USE_MB
343
322
    int tmp_length;
344
323
    if (use_mb_flag && (tmp_length= my_ismbchar(charset_info, from, end)))
345
324
    {
358
337
      turned into a multi-byte character by the addition of an escaping
359
338
      character, because we are only escaping the ' character with itself.
360
339
     */
 
340
#endif
361
341
    if (*from == '\'')
362
342
    {
363
343
      if (to + 2 > to_end)
381
361
  *to= 0;
382
362
  return overflow ? UINT32_MAX : (uint32_t) (to - to_start);
383
363
}
384
 
 
385
 
} /* namespace drizzled */