1
/* Copyright (C) 2000 MySQL AB
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.
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.
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 */
16
#ifndef DRIZZLE_SERVER_SQL_STRING_H
17
#define DRIZZLE_SERVER_SQL_STRING_H
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
20
#ifndef DRIZZLED_SQL_STRING_H
21
#define DRIZZLED_SQL_STRING_H
19
23
/* This file is originally from the mysql distribution. Coded by monty */
21
#ifdef USE_PRAGMA_INTERFACE
22
#pragma interface /* gcc class implementation */
25
26
#ifndef NOT_FIXED_DEC
26
#define NOT_FIXED_DEC 31
27
#define NOT_FIXED_DEC (uint8_t)31
30
#include <drizzled/common.h>
31
#include <mysys/iocache.h>
30
int sortcmp(const String *a,const String *b, const CHARSET_INFO * const 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, const CHARSET_INFO * const to_cs,
33
const char *from, uint32_t from_length,
34
const CHARSET_INFO * const from_cs, uint *errors);
35
uint32_t well_formed_copy_nchars(const CHARSET_INFO * const to_cs,
36
char *to, uint to_length,
37
const CHARSET_INFO * const from_cs,
38
const char *from, uint from_length,
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(const CHARSET_INFO * const cs,
44
char *dst, size_t dstlen,
45
const char *src, size_t srclen);
37
#if defined(__cplusplus)
41
int sortcmp(const String *a,const String *b, const CHARSET_INFO * const cs);
42
int stringcmp(const String *a,const String *b);
43
String *copy_if_not_alloced(String *a,String *b,uint32_t arg_length);
44
uint32_t well_formed_copy_nchars(const CHARSET_INFO * const to_cs,
45
char *to, uint32_t to_length,
46
const CHARSET_INFO * const from_cs,
47
const char *from, uint32_t from_length,
49
const char **well_formed_error_pos,
50
const char **cannot_convert_error_pos,
51
const char **from_end_pos);
53
#if defined(__cplusplus)
50
60
uint32_t str_length,Alloced_length;
52
62
const CHARSET_INFO *str_charset;
56
Ptr=0; str_length=Alloced_length=0; alloced=0;
57
str_charset= &my_charset_bin;
67
Ptr=0; str_length=Alloced_length=0; alloced=0;
68
str_charset= &my_charset_bin;
59
70
String(uint32_t length_arg)
61
alloced=0; Alloced_length=0; (void) real_alloc(length_arg);
72
alloced=0; Alloced_length=0; (void) real_alloc(length_arg);
62
73
str_charset= &my_charset_bin;
64
75
String(const char *str, const CHARSET_INFO * const cs)
66
Ptr=(char*) str; str_length=(uint) strlen(str); Alloced_length=0; alloced=0;
77
Ptr=(char*) str; str_length=(uint32_t) strlen(str); Alloced_length=0; alloced=0;
69
80
String(const char *str,uint32_t len, const CHARSET_INFO * const cs)
71
82
Ptr=(char*) str; str_length=len; Alloced_length=0; alloced=0;
74
85
String(char *str,uint32_t len, const CHARSET_INFO * const cs)
76
87
Ptr=(char*) str; Alloced_length=str_length=len; alloced=0;
79
90
String(const String &str)
81
92
Ptr=str.Ptr ; str_length=str.str_length ;
82
Alloced_length=str.Alloced_length; alloced=0;
93
Alloced_length=str.Alloced_length; alloced=0;
83
94
str_charset=str.str_charset;
85
96
static void *operator new(size_t size, MEM_ROOT *mem_root)
86
{ return (void*) alloc_root(mem_root, (uint) size); }
87
static void operator delete(void *ptr_arg __attribute__((unused)),
88
size_t size __attribute__((unused)))
97
{ return (void*) alloc_root(mem_root, (uint32_t) size); }
98
static void operator delete(void *, size_t)
89
99
{ TRASH(ptr_arg, size); }
90
static void operator delete(void *ptr_arg __attribute__((unused)),
91
MEM_ROOT *mem_root __attribute__((unused)))
100
static void operator delete(void *, MEM_ROOT *)
92
101
{ /* never called */ }
95
104
inline void set_charset(const CHARSET_INFO * const charset_arg)
96
105
{ str_charset= charset_arg; }
249
262
static bool needs_conversion(uint32_t arg_length,
250
263
const CHARSET_INFO * const cs_from, const CHARSET_INFO * const cs_to,
251
264
uint32_t *offset);
252
bool copy_aligned(const char *s, uint32_t arg_length, uint32_t offset,
253
const CHARSET_INFO * const cs);
254
265
bool set_or_copy_aligned(const char *s, uint32_t arg_length, const CHARSET_INFO * const cs);
255
266
bool copy(const char*s,uint32_t arg_length, const CHARSET_INFO * const csfrom,
256
const CHARSET_INFO * const csto, uint *errors);
267
const CHARSET_INFO * const csto, uint32_t *errors);
257
268
bool append(const String &s);
258
269
bool append(const char *s);
259
270
bool append(const char *s,uint32_t arg_length);
260
271
bool append(const char *s,uint32_t arg_length, const CHARSET_INFO * const cs);
261
bool append(IO_CACHE* file, uint32_t arg_length);
262
bool append_with_prefill(const char *s, uint32_t arg_length,
272
bool append_with_prefill(const char *s, uint32_t arg_length,
263
273
uint32_t full_length, char fill_char);
264
274
int strstr(const String &search,uint32_t offset=0); // Returns offset to substring or -1
265
275
int strrstr(const String &search,uint32_t offset=0); // Returns offset to substring or -1
376
static inline bool check_if_only_end_space(const CHARSET_INFO * const cs, char *str,
374
static inline bool check_if_only_end_space(const CHARSET_INFO * const cs, char *str,
379
377
return str+ cs->cset->scan(cs, str, end, MY_SEQ_SPACES) == end;
383
bool operator==(const String &s1, const String &s2)
385
return stringcmp(&s1,&s2) == 0;
389
bool operator!=(const String &s1, const String &s2)
394
#endif /* DRIZZLE_SERVER_SQL_STRING_H */
381
bool operator==(const String &s1, const String &s2);
382
bool operator!=(const String &s1, const String &s2);
385
#endif /* DRIZZLED_SQL_STRING_H */