~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_string.h

  • Committer: Monty Taylor
  • Date: 2008-08-04 19:37:18 UTC
  • mto: (261.2.2 codestyle)
  • mto: This revision was merged to the branch mainline in revision 262.
  • Revision ID: monty@inaugust.com-20080804193718-f0rz13uli4429ozb
Changed gettext_noop() to N_()

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
 
1
/* Copyright (C) 2000 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
19
15
 
20
16
#ifndef DRIZZLE_SERVER_SQL_STRING_H
21
17
#define DRIZZLE_SERVER_SQL_STRING_H
22
18
 
23
19
/* This file is originally from the mysql distribution. Coded by monty */
24
20
 
 
21
#ifdef USE_PRAGMA_INTERFACE
 
22
#pragma interface                       /* gcc class implementation */
 
23
#endif
25
24
 
26
25
#ifndef NOT_FIXED_DEC
27
26
#define NOT_FIXED_DEC                   31
28
27
#endif
29
28
 
30
 
#include <drizzled/common.h>
31
 
#include <mysys/iocache.h>
32
 
 
33
29
class String;
34
 
 
35
 
#if defined(__cplusplus)
36
 
extern "C" {
37
 
#endif
38
 
 
39
 
  int sortcmp(const String *a,const String *b, const CHARSET_INFO * const cs);
40
 
  int stringcmp(const String *a,const String *b);
41
 
  String *copy_if_not_alloced(String *a,String *b,uint32_t arg_length);
42
 
  uint32_t copy_and_convert(char *to, uint32_t to_length,
43
 
                            const CHARSET_INFO * const to_cs,
44
 
                            const char *from, uint32_t from_length,
45
 
                            const CHARSET_INFO * const from_cs,
46
 
                            uint32_t *errors);
47
 
  uint32_t well_formed_copy_nchars(const CHARSET_INFO * const to_cs,
48
 
                                   char *to, uint32_t to_length,
49
 
                                   const CHARSET_INFO * const from_cs,
50
 
                                   const char *from, uint32_t from_length,
51
 
                                   uint32_t nchars,
52
 
                                   const char **well_formed_error_pos,
53
 
                                   const char **cannot_convert_error_pos,
54
 
                                   const char **from_end_pos);
55
 
  size_t my_copy_with_hex_escaping(const CHARSET_INFO * const cs,
56
 
                                   char *dst, size_t dstlen,
57
 
                                   const char *src, size_t srclen);
58
 
 
59
 
#if defined(__cplusplus)
60
 
}
61
 
#endif
 
30
int sortcmp(const String *a,const String *b, CHARSET_INFO *cs);
 
31
String *copy_if_not_alloced(String *a,String *b,uint32_t arg_length);
 
32
uint32_t copy_and_convert(char *to, uint32_t to_length, CHARSET_INFO *to_cs,
 
33
                        const char *from, uint32_t from_length,
 
34
                        CHARSET_INFO *from_cs, uint *errors);
 
35
uint32_t well_formed_copy_nchars(CHARSET_INFO *to_cs,
 
36
                               char *to, uint to_length,
 
37
                               CHARSET_INFO *from_cs,
 
38
                               const char *from, uint from_length,
 
39
                               uint nchars,
 
40
                               const char **well_formed_error_pos,
 
41
                               const char **cannot_convert_error_pos,
 
42
                               const char **from_end_pos);
 
43
size_t my_copy_with_hex_escaping(CHARSET_INFO *cs,
 
44
                                 char *dst, size_t dstlen,
 
45
                                 const char *src, size_t srclen);
62
46
 
63
47
class String
64
48
{
65
49
  char *Ptr;
66
50
  uint32_t str_length,Alloced_length;
67
51
  bool alloced;
68
 
  const CHARSET_INFO *str_charset;
 
52
  CHARSET_INFO *str_charset;
69
53
public:
70
54
  String()
71
55
  { 
77
61
    alloced=0; Alloced_length=0; (void) real_alloc(length_arg); 
78
62
    str_charset= &my_charset_bin;
79
63
  }
80
 
  String(const char *str, const CHARSET_INFO * const cs)
 
64
  String(const char *str, CHARSET_INFO *cs)
81
65
  { 
82
66
    Ptr=(char*) str; str_length=(uint) strlen(str); Alloced_length=0; alloced=0;
83
67
    str_charset=cs;
84
68
  }
85
 
  String(const char *str,uint32_t len, const CHARSET_INFO * const cs)
 
69
  String(const char *str,uint32_t len, CHARSET_INFO *cs)
86
70
  { 
87
71
    Ptr=(char*) str; str_length=len; Alloced_length=0; alloced=0;
88
72
    str_charset=cs;
89
73
  }
90
 
  String(char *str,uint32_t len, const CHARSET_INFO * const cs)
 
74
  String(char *str,uint32_t len, CHARSET_INFO *cs)
91
75
  { 
92
76
    Ptr=(char*) str; Alloced_length=str_length=len; alloced=0;
93
77
    str_charset=cs;
108
92
  { /* never called */ }
109
93
  ~String() { free(); }
110
94
 
111
 
  inline void set_charset(const CHARSET_INFO * const charset_arg)
 
95
  inline void set_charset(CHARSET_INFO *charset_arg)
112
96
  { str_charset= charset_arg; }
113
 
  inline const CHARSET_INFO *charset() const { return str_charset; }
 
97
  inline CHARSET_INFO *charset() const { return str_charset; }
114
98
  inline uint32_t length() const { return str_length;}
115
99
  inline uint32_t alloced_length() const { return Alloced_length;}
116
100
  inline char& operator [] (uint32_t i) const { return Ptr[i]; }
117
101
  inline void length(uint32_t len) { str_length=len ; }
118
102
  inline bool is_empty() { return (str_length == 0); }
119
103
  inline void mark_as_const() { Alloced_length= 0;}
120
 
  inline char *ptr() { return Ptr; }
121
104
  inline const char *ptr() const { return Ptr; }
122
105
  inline char *c_ptr()
123
106
  {
151
134
      Alloced_length=0;
152
135
    str_charset=str.str_charset;
153
136
  }
154
 
  inline void set(char *str,uint32_t arg_length, const CHARSET_INFO * const cs)
 
137
  inline void set(char *str,uint32_t arg_length, CHARSET_INFO *cs)
155
138
  {
156
139
    free();
157
140
    Ptr=(char*) str; str_length=Alloced_length=arg_length ; alloced=0;
158
141
    str_charset=cs;
159
142
  }
160
 
  inline void set(const char *str,uint32_t arg_length, const CHARSET_INFO * const cs)
 
143
  inline void set(const char *str,uint32_t arg_length, CHARSET_INFO *cs)
161
144
  {
162
145
    free();
163
146
    Ptr=(char*) str; str_length=arg_length; Alloced_length=0 ; alloced=0;
164
147
    str_charset=cs;
165
148
  }
166
149
  bool set_ascii(const char *str, uint32_t arg_length);
167
 
  inline void set_quick(char *str,uint32_t arg_length, const CHARSET_INFO * const cs)
 
150
  inline void set_quick(char *str,uint32_t arg_length, CHARSET_INFO *cs)
168
151
  {
169
152
    if (!alloced)
170
153
    {
172
155
    }
173
156
    str_charset=cs;
174
157
  }
175
 
  bool set_int(int64_t num, bool unsigned_flag, const CHARSET_INFO * const cs);
176
 
  bool set(int64_t num, const CHARSET_INFO * const cs)
 
158
  bool set_int(int64_t num, bool unsigned_flag, CHARSET_INFO *cs);
 
159
  bool set(int64_t num, CHARSET_INFO *cs)
177
160
  { return set_int(num, false, cs); }
178
 
  bool set(uint64_t num, const CHARSET_INFO * const cs)
 
161
  bool set(uint64_t num, CHARSET_INFO *cs)
179
162
  { return set_int((int64_t)num, true, cs); }
180
 
  bool set_real(double num,uint32_t decimals, const CHARSET_INFO * const cs);
 
163
  bool set_real(double num,uint decimals, CHARSET_INFO *cs);
181
164
 
182
165
  /*
183
166
    PMG 2004.11.12
212
195
    {
213
196
      alloced=0;
214
197
      Alloced_length=0;
215
 
      ::free(Ptr);
 
198
      my_free(Ptr,MYF(0));
216
199
      Ptr=0;
217
200
      str_length=0;                             /* Safety */
218
201
    }
261
244
 
262
245
  bool copy();                                  // Alloc string if not alloced
263
246
  bool copy(const String &s);                   // Allocate new string
264
 
  bool copy(const char *s,uint32_t arg_length, const CHARSET_INFO * const cs);  // Allocate new string
 
247
  bool copy(const char *s,uint32_t arg_length, CHARSET_INFO *cs);       // Allocate new string
265
248
  static bool needs_conversion(uint32_t arg_length,
266
 
                               const CHARSET_INFO * const cs_from, const CHARSET_INFO * const cs_to,
 
249
                               CHARSET_INFO *cs_from, CHARSET_INFO *cs_to,
267
250
                               uint32_t *offset);
268
251
  bool copy_aligned(const char *s, uint32_t arg_length, uint32_t offset,
269
 
                    const CHARSET_INFO * const cs);
270
 
  bool set_or_copy_aligned(const char *s, uint32_t arg_length, const CHARSET_INFO * const cs);
271
 
  bool copy(const char*s,uint32_t arg_length, const CHARSET_INFO * const csfrom,
272
 
            const CHARSET_INFO * const csto, uint32_t *errors);
 
252
                    CHARSET_INFO *cs);
 
253
  bool set_or_copy_aligned(const char *s, uint32_t arg_length, CHARSET_INFO *cs);
 
254
  bool copy(const char*s,uint32_t arg_length, CHARSET_INFO *csfrom,
 
255
            CHARSET_INFO *csto, uint *errors);
273
256
  bool append(const String &s);
274
257
  bool append(const char *s);
275
258
  bool append(const char *s,uint32_t arg_length);
276
 
  bool append(const char *s,uint32_t arg_length, const CHARSET_INFO * const cs);
 
259
  bool append(const char *s,uint32_t arg_length, CHARSET_INFO *cs);
277
260
  bool append(IO_CACHE* file, uint32_t arg_length);
278
261
  bool append_with_prefill(const char *s, uint32_t arg_length, 
279
262
                           uint32_t full_length, char fill_char);
296
279
    return 0;
297
280
  }
298
281
  bool fill(uint32_t max_length,char fill);
299
 
  friend int sortcmp(const String *a,const String *b, const CHARSET_INFO * const cs);
 
282
  void strip_sp();
 
283
  friend int sortcmp(const String *a,const String *b, CHARSET_INFO *cs);
300
284
  friend int stringcmp(const String *a,const String *b);
301
285
  friend String *copy_if_not_alloced(String *a,String *b,uint32_t arg_length);
302
286
  uint32_t numchars();
352
336
     str_length++;
353
337
  }
354
338
  void qs_append(int i);
355
 
  void qs_append(uint32_t i);
 
339
  void qs_append(uint i);
356
340
 
357
341
  /* Inline (general) functions used by the protocol functions */
358
342
 
389
373
  }
390
374
};
391
375
 
392
 
static inline bool check_if_only_end_space(const CHARSET_INFO * const cs, char *str, 
 
376
static inline bool check_if_only_end_space(CHARSET_INFO *cs, char *str, 
393
377
                                           char *end)
394
378
{
395
379
  return str+ cs->cset->scan(cs, str, end, MY_SEQ_SPACES) == end;
396
380
}
397
381
 
398
 
extern "C++" {
399
 
bool operator==(const String &s1, const String &s2);
400
 
bool operator!=(const String &s1, const String &s2);
 
382
inline
 
383
bool operator==(const String &s1, const String &s2)
 
384
{
 
385
  return stringcmp(&s1,&s2) == 0;
 
386
}
 
387
 
 
388
inline
 
389
bool operator!=(const String &s1, const String &s2)
 
390
{
 
391
  return !(s1 == s2);
401
392
}
402
393
 
403
394
#endif /* DRIZZLE_SERVER_SQL_STRING_H */