1
by brian
clean slate |
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 */
|
|
15 |
||
16 |
/* There may be prolems include all of theese. Try to test in
|
|
17 |
configure with ones are needed? */
|
|
18 |
||
19 |
/* This is needed for the definitions of strchr... on solaris */
|
|
20 |
||
212.5.39
by Monty Taylor
Phew. Moved my_base and my_global. |
21 |
|
1
by brian
clean slate |
22 |
#ifndef _m_string_h
|
23 |
#define _m_string_h
|
|
236.1.27
by Monty Taylor
Some cleanups/decoupling in mystring. |
24 |
|
25 |
#include <drizzled/global.h> |
|
26 |
||
1
by brian
clean slate |
27 |
#ifndef __USE_GNU
|
411.1.1
by Brian Aker
Work on removing GNU specific calls. |
28 |
#define __USE_GNU /* We want to use my_stpcpy */ |
1
by brian
clean slate |
29 |
#endif
|
30 |
#if defined(HAVE_STRINGS_H)
|
|
31 |
#include <strings.h> |
|
32 |
#endif
|
|
33 |
#if defined(HAVE_STRING_H)
|
|
34 |
#include <string.h> |
|
35 |
#endif
|
|
36 |
||
236.1.27
by Monty Taylor
Some cleanups/decoupling in mystring. |
37 |
#include <stdlib.h> |
38 |
#include <stddef.h> |
|
39 |
#include <stdbool.h> |
|
40 |
#include <assert.h> |
|
41 |
#include <limits.h> |
|
481.1.24
by Monty Taylor
Split a method out into innodb_plugin_extras. Innodb is the only thing that uses it. I imagine we probably want to do something totally different with this... |
42 |
#include <ctype.h> |
1
by brian
clean slate |
43 |
|
44 |
/* This is needed for the definitions of memcpy... on solaris */
|
|
45 |
#if defined(HAVE_MEMORY_H) && !defined(__cplusplus)
|
|
46 |
#include <memory.h> |
|
47 |
#endif
|
|
48 |
||
49 |
#if defined(__cplusplus)
|
|
50 |
extern "C" { |
|
51 |
#endif
|
|
52 |
||
53 |
/*
|
|
54 |
my_str_malloc() and my_str_free() are assigned to implementations in
|
|
55 |
strings/alloc.c, but can be overridden in the calling program.
|
|
56 |
*/
|
|
57 |
extern void *(*my_str_malloc)(size_t); |
|
58 |
extern void (*my_str_free)(void *); |
|
59 |
||
411.1.1
by Brian Aker
Work on removing GNU specific calls. |
60 |
char *my_stpncpy(register char *dst, register const char *src, size_t n); |
61 |
char *my_stpcpy(register char *dst, register const char *src); |
|
62 |
||
63 |
#define strmov_overlapp(A,B) my_stpcpy(A,B)
|
|
1
by brian
clean slate |
64 |
#define strmake_overlapp(A,B,C) strmake(A,B,C)
|
65 |
||
236.1.27
by Monty Taylor
Some cleanups/decoupling in mystring. |
66 |
extern void bmove_upp(unsigned char *dst,const unsigned char *src,size_t len); |
67 |
||
68 |
extern void bchange(unsigned char *dst,size_t old_len,const unsigned char *src, |
|
1
by brian
clean slate |
69 |
size_t new_len,size_t tot_len); |
70 |
extern char *strfield(char *src,int fields,int chars,int blanks, |
|
71 |
int tabch); |
|
154
by Brian Aker
Removed oddball types in my_global.h |
72 |
extern char *strfill(char * s,size_t len,char fill); |
1
by brian
clean slate |
73 |
extern char *strkey(char *dst,char *head,char *tail,char *flags); |
74 |
extern char *strmake(char *dst,const char *src,size_t length); |
|
75 |
#ifndef strmake_overlapp
|
|
76 |
extern char *strmake_overlapp(char *dst,const char *src, size_t length); |
|
77 |
#endif
|
|
78 |
||
79 |
extern char *strsuff(const char *src,const char *suffix); |
|
236.1.27
by Monty Taylor
Some cleanups/decoupling in mystring. |
80 |
extern char *strxcat(char *dst,const char *src, ...); |
81 |
extern char *strxmov(char *dst,const char *src, ...); |
|
82 |
extern char *strxcpy(char *dst,const char *src, ...); |
|
83 |
extern char *strxncat(char *dst,size_t len, const char *src, ...); |
|
84 |
extern char *strxnmov(char *dst,size_t len, const char *src, ...); |
|
85 |
extern char *strxncpy(char *dst,size_t len, const char *src, ...); |
|
1
by brian
clean slate |
86 |
|
87 |
/* Prototypes of normal stringfunctions (with may ours) */
|
|
88 |
||
89 |
#ifdef WANT_STRING_PROTOTYPES
|
|
90 |
extern char *strcat(char *, const char *); |
|
154
by Brian Aker
Removed oddball types in my_global.h |
91 |
extern char *strchr(const char *, char); |
92 |
extern char *strrchr(const char *, char); |
|
1
by brian
clean slate |
93 |
extern char *strcpy(char *, const char *); |
94 |
#endif
|
|
95 |
||
96 |
#if !defined(__cplusplus)
|
|
97 |
#ifndef HAVE_STRPBRK
|
|
98 |
extern char *strpbrk(const char *, const char *); |
|
99 |
#endif
|
|
100 |
#endif
|
|
101 |
extern int is_prefix(const char *, const char *); |
|
102 |
||
103 |
/* Conversion routines */
|
|
104 |
typedef enum { |
|
105 |
MY_GCVT_ARG_FLOAT, |
|
106 |
MY_GCVT_ARG_DOUBLE
|
|
107 |
} my_gcvt_arg_type; |
|
108 |
||
109 |
double my_strtod(const char *str, char **end, int *error); |
|
110 |
double my_atof(const char *nptr); |
|
236.1.27
by Monty Taylor
Some cleanups/decoupling in mystring. |
111 |
size_t my_fcvt(double x, int precision, char *to, bool *error); |
1
by brian
clean slate |
112 |
size_t my_gcvt(double x, my_gcvt_arg_type type, int width, char *to, |
236.1.27
by Monty Taylor
Some cleanups/decoupling in mystring. |
113 |
bool *error); |
1
by brian
clean slate |
114 |
|
115 |
#define NOT_FIXED_DEC 31
|
|
116 |
||
117 |
/*
|
|
118 |
The longest string my_fcvt can return is 311 + "precision" bytes.
|
|
119 |
Here we assume that we never cal my_fcvt() with precision >= NOT_FIXED_DEC
|
|
120 |
(+ 1 byte for the terminating '\0').
|
|
121 |
*/
|
|
122 |
#define FLOATING_POINT_BUFFER (311 + NOT_FIXED_DEC)
|
|
123 |
||
124 |
/*
|
|
125 |
We want to use the 'e' format in some cases even if we have enough space
|
|
126 |
for the 'f' one just to mimic sprintf("%.15g") behavior for large integers,
|
|
127 |
and to improve it for numbers < 10^(-4).
|
|
128 |
That is, for |x| < 1 we require |x| >= 10^(-15), and for |x| > 1 we require
|
|
129 |
it to be integer and be <= 10^DBL_DIG for the 'f' format to be used.
|
|
130 |
We don't lose precision, but make cases like "1e200" or "0.00001" look nicer.
|
|
131 |
*/
|
|
132 |
#define MAX_DECPT_FOR_F_FORMAT DBL_DIG
|
|
133 |
||
134 |
/*
|
|
135 |
The maximum possible field width for my_gcvt() conversion.
|
|
136 |
(DBL_DIG + 2) significant digits + sign + "." + ("e-NNN" or
|
|
137 |
MAX_DECPT_FOR_F_FORMAT zeros for cases when |x|<1 and the 'f' format is used).
|
|
138 |
*/
|
|
398.1.5
by Monty Taylor
Removed C++ includes and std namespace from global.h. |
139 |
#define MY_GCVT_MAX_FIELD_WIDTH (DBL_DIG + 4 + cmax(5, MAX_DECPT_FOR_F_FORMAT))
|
1
by brian
clean slate |
140 |
|
141 |
||
152
by Brian Aker
longlong replacement |
142 |
extern char *llstr(int64_t value,char *buff); |
143 |
extern char *ullstr(int64_t value,char *buff); |
|
1
by brian
clean slate |
144 |
|
145 |
extern char *int2str(long val, char *dst, int radix, int upcase); |
|
146 |
extern char *int10_to_str(long val,char *dst,int radix); |
|
147 |
extern char *str2int(const char *src,int radix,long lower,long upper, |
|
148 |
long *val); |
|
152
by Brian Aker
longlong replacement |
149 |
int64_t my_strtoll10(const char *nptr, char **endptr, int *error); |
150 |
extern char *int64_t2str(int64_t val,char *dst,int radix); |
|
151 |
extern char *int64_t10_to_str(int64_t val,char *dst,int radix); |
|
1
by brian
clean slate |
152 |
|
153 |
||
154 |
#if defined(__cplusplus)
|
|
155 |
}
|
|
156 |
#endif
|
|
157 |
||
158 |
/*
|
|
159 |
LEX_STRING -- a pair of a C-string and its length.
|
|
160 |
*/
|
|
161 |
||
162 |
#ifndef _my_plugin_h
|
|
163 |
/* This definition must match the one given in mysql/plugin.h */
|
|
164 |
struct st_mysql_lex_string |
|
165 |
{
|
|
166 |
char *str; |
|
167 |
size_t length; |
|
168 |
};
|
|
169 |
#endif
|
|
170 |
typedef struct st_mysql_lex_string LEX_STRING; |
|
171 |
||
172 |
#define STRING_WITH_LEN(X) (X), ((size_t) (sizeof(X) - 1))
|
|
236.1.27
by Monty Taylor
Some cleanups/decoupling in mystring. |
173 |
#define USTRING_WITH_LEN(X) ((unsigned char*) X), ((size_t) (sizeof(X) - 1))
|
1
by brian
clean slate |
174 |
#define C_STRING_WITH_LEN(X) ((char *) (X)), ((size_t) (sizeof(X) - 1))
|
175 |
||
176 |
/**
|
|
177 |
Skip trailing space.
|
|
178 |
||
179 |
@param ptr pointer to the input string
|
|
180 |
@param len the length of the string
|
|
181 |
@return the last non-space character
|
|
182 |
*/
|
|
183 |
||
481.1.24
by Monty Taylor
Split a method out into innodb_plugin_extras. Innodb is the only thing that uses it. I imagine we probably want to do something totally different with this... |
184 |
static inline const unsigned char * |
481.1.22
by Monty Taylor
Collapsed over-optimized skip_trailing_spaces. |
185 |
skip_trailing_space(const unsigned char *ptr,size_t len) |
1
by brian
clean slate |
186 |
{
|
236.1.27
by Monty Taylor
Some cleanups/decoupling in mystring. |
187 |
const unsigned char *end= ptr + len; |
1
by brian
clean slate |
188 |
|
481.1.22
by Monty Taylor
Collapsed over-optimized skip_trailing_spaces. |
189 |
while (end > ptr && isspace(*--end)) |
190 |
continue; |
|
191 |
return end+1; |
|
1
by brian
clean slate |
192 |
}
|
193 |
||
194 |
#endif
|