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
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 */
20
16
#ifndef DRIZZLE_SERVER_SQL_STRING_H
21
17
#define DRIZZLE_SERVER_SQL_STRING_H
23
19
/* This file is originally from the mysql distribution. Coded by monty */
21
#ifdef USE_PRAGMA_INTERFACE
22
#pragma interface /* gcc class implementation */
26
25
#ifndef NOT_FIXED_DEC
27
26
#define NOT_FIXED_DEC 31
30
#include <drizzled/common.h>
31
#include <mysys/iocache.h>
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 copy_and_convert(char *to, uint32_t to_length,
45
const CHARSET_INFO * const to_cs,
46
const char *from, uint32_t from_length,
47
const CHARSET_INFO * const from_cs,
49
uint32_t well_formed_copy_nchars(const CHARSET_INFO * const to_cs,
50
char *to, uint32_t to_length,
51
const CHARSET_INFO * const from_cs,
52
const char *from, uint32_t from_length,
54
const char **well_formed_error_pos,
55
const char **cannot_convert_error_pos,
56
const char **from_end_pos);
57
size_t my_copy_with_hex_escaping(const CHARSET_INFO * const cs,
58
char *dst, size_t dstlen,
59
const char *src, size_t srclen);
61
#if defined(__cplusplus)
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,
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);
68
50
uint32_t str_length,Alloced_length;
70
const CHARSET_INFO *str_charset;
52
CHARSET_INFO *str_charset;
74
Ptr=0; str_length=Alloced_length=0; alloced=0;
75
str_charset= &my_charset_bin;
56
Ptr=0; str_length=Alloced_length=0; alloced=0;
57
str_charset= &my_charset_bin;
77
59
String(uint32_t length_arg)
79
alloced=0; Alloced_length=0; (void) real_alloc(length_arg);
61
alloced=0; Alloced_length=0; (void) real_alloc(length_arg);
80
62
str_charset= &my_charset_bin;
82
String(const char *str, const CHARSET_INFO * const cs)
64
String(const char *str, CHARSET_INFO *cs)
84
66
Ptr=(char*) str; str_length=(uint) strlen(str); Alloced_length=0; alloced=0;
87
String(const char *str,uint32_t len, const CHARSET_INFO * const cs)
69
String(const char *str,uint32_t len, CHARSET_INFO *cs)
89
71
Ptr=(char*) str; str_length=len; Alloced_length=0; alloced=0;
92
String(char *str,uint32_t len, const CHARSET_INFO * const cs)
74
String(char *str,uint32_t len, CHARSET_INFO *cs)
94
76
Ptr=(char*) str; Alloced_length=str_length=len; alloced=0;
97
79
String(const String &str)
99
81
Ptr=str.Ptr ; str_length=str.str_length ;
100
Alloced_length=str.Alloced_length; alloced=0;
82
Alloced_length=str.Alloced_length; alloced=0;
101
83
str_charset=str.str_charset;
103
85
static void *operator new(size_t size, MEM_ROOT *mem_root)
104
86
{ return (void*) alloc_root(mem_root, (uint) size); }
105
static void operator delete(void *, size_t)
87
static void operator delete(void *ptr_arg __attribute__((unused)),
88
size_t size __attribute__((unused)))
106
89
{ TRASH(ptr_arg, size); }
107
static void operator delete(void *, MEM_ROOT *)
90
static void operator delete(void *ptr_arg __attribute__((unused)),
91
MEM_ROOT *mem_root __attribute__((unused)))
108
92
{ /* never called */ }
109
93
~String() { free(); }
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()
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);
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
bool append_with_prefill(const char *s, uint32_t arg_length,
261
bool append_with_prefill(const char *s, uint32_t arg_length,
279
262
uint32_t full_length, char fill_char);
280
263
int strstr(const String &search,uint32_t offset=0); // Returns offset to substring or -1
281
264
int strrstr(const String &search,uint32_t offset=0); // Returns offset to substring or -1