~drizzle-trunk/drizzle/development

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 <assert.h>
40
#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...
41
#include <ctype.h>
1 by brian
clean slate
42
43
/*  This is needed for the definitions of memcpy... on solaris */
44
#if defined(HAVE_MEMORY_H) && !defined(__cplusplus)
45
#include <memory.h>
46
#endif
47
48
#if defined(__cplusplus)
49
extern "C" {
50
#endif
51
411.1.1 by Brian Aker
Work on removing GNU specific calls.
52
#define strmov_overlapp(A,B) my_stpcpy(A,B)
1 by brian
clean slate
53
#define strmake_overlapp(A,B,C) strmake(A,B,C)
54
236.1.27 by Monty Taylor
Some cleanups/decoupling in mystring.
55
extern void bmove_upp(unsigned char *dst,const unsigned char *src,size_t len);
56
57
extern	void bchange(unsigned char *dst,size_t old_len,const unsigned char *src,
1 by brian
clean slate
58
		     size_t new_len,size_t tot_len);
59
extern	char *strfield(char *src,int fields,int chars,int blanks,
60
			   int tabch);
154 by Brian Aker
Removed oddball types in my_global.h
61
extern	char *strfill(char * s,size_t len,char fill);
1 by brian
clean slate
62
extern	char *strkey(char *dst,char *head,char *tail,char *flags);
63
extern	char *strmake(char *dst,const char *src,size_t length);
64
#ifndef strmake_overlapp
65
extern	char *strmake_overlapp(char *dst,const char *src, size_t length);
66
#endif
67
68
extern	char *strsuff(const char *src,const char *suffix);
236.1.27 by Monty Taylor
Some cleanups/decoupling in mystring.
69
extern	char *strxcat(char *dst,const char *src, ...);
70
extern	char *strxmov(char *dst,const char *src, ...);
71
extern	char *strxcpy(char *dst,const char *src, ...);
72
extern	char *strxncat(char *dst,size_t len, const char *src, ...);
73
extern	char *strxncpy(char *dst,size_t len, const char *src, ...);
1 by brian
clean slate
74
75
/* Prototypes of normal stringfunctions (with may ours) */
76
77
#ifdef WANT_STRING_PROTOTYPES
78
extern char *strcat(char *, const char *);
154 by Brian Aker
Removed oddball types in my_global.h
79
extern char *strchr(const char *, char);
80
extern char *strrchr(const char *, char);
1 by brian
clean slate
81
extern char *strcpy(char *, const char *);
82
#endif
83
84
#if !defined(__cplusplus)
85
#ifndef HAVE_STRPBRK
86
extern char *strpbrk(const char *, const char *);
87
#endif
88
#endif
89
extern int is_prefix(const char *, const char *);
90
91
/* Conversion routines */
92
typedef enum {
93
  MY_GCVT_ARG_FLOAT,
94
  MY_GCVT_ARG_DOUBLE
95
} my_gcvt_arg_type;
96
97
double my_strtod(const char *str, char **end, int *error);
98
double my_atof(const char *nptr);
236.1.27 by Monty Taylor
Some cleanups/decoupling in mystring.
99
size_t my_fcvt(double x, int precision, char *to, bool *error);
1 by brian
clean slate
100
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.
101
               bool *error);
1 by brian
clean slate
102
103
#define NOT_FIXED_DEC 31
104
105
/*
106
  The longest string my_fcvt can return is 311 + "precision" bytes.
107
  Here we assume that we never cal my_fcvt() with precision >= NOT_FIXED_DEC
108
  (+ 1 byte for the terminating '\0').
109
*/
110
#define FLOATING_POINT_BUFFER (311 + NOT_FIXED_DEC)
111
112
/*
113
  We want to use the 'e' format in some cases even if we have enough space
114
  for the 'f' one just to mimic sprintf("%.15g") behavior for large integers,
115
  and to improve it for numbers < 10^(-4).
116
  That is, for |x| < 1 we require |x| >= 10^(-15), and for |x| > 1 we require
117
  it to be integer and be <= 10^DBL_DIG for the 'f' format to be used.
118
  We don't lose precision, but make cases like "1e200" or "0.00001" look nicer.
119
*/
120
#define MAX_DECPT_FOR_F_FORMAT DBL_DIG
121
122
/*
123
  The maximum possible field width for my_gcvt() conversion.
124
  (DBL_DIG + 2) significant digits + sign + "." + ("e-NNN" or
125
  MAX_DECPT_FOR_F_FORMAT zeros for cases when |x|<1 and the 'f' format is used).
126
*/
398.1.5 by Monty Taylor
Removed C++ includes and std namespace from global.h.
127
#define MY_GCVT_MAX_FIELD_WIDTH (DBL_DIG + 4 + cmax(5, MAX_DECPT_FOR_F_FORMAT))
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
128
1 by brian
clean slate
129
152 by Brian Aker
longlong replacement
130
extern char *llstr(int64_t value,char *buff);
131
extern char *ullstr(int64_t value,char *buff);
1 by brian
clean slate
132
492.1.9 by Monty
Fixed problem on 32-bit.
133
extern char *int2str(int32_t val, char *dst, int radix, int upcase);
134
extern char *int10_to_str(int32_t val,char *dst,int radix);
1 by brian
clean slate
135
extern char *str2int(const char *src,int radix,long lower,long upper,
520.4.30 by Monty Taylor
Moved LEX_STRING into drizzled/lex_string.h.
136
                     long *val);
152 by Brian Aker
longlong replacement
137
int64_t my_strtoll10(const char *nptr, char **endptr, int *error);
138
extern char *int64_t2str(int64_t val,char *dst,int radix);
139
extern char *int64_t10_to_str(int64_t val,char *dst,int radix);
1 by brian
clean slate
140
141
142
#if defined(__cplusplus)
143
}
144
#endif
145
146
147
/**
148
  Skip trailing space.
149
150
   @param     ptr   pointer to the input string
151
   @param     len   the length of the string
152
   @return          the last non-space character
153
*/
154
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...
155
static inline const unsigned char *
520.4.30 by Monty Taylor
Moved LEX_STRING into drizzled/lex_string.h.
156
skip_trailing_space(const unsigned char *ptr, size_t len)
1 by brian
clean slate
157
{
236.1.27 by Monty Taylor
Some cleanups/decoupling in mystring.
158
  const unsigned char *end= ptr + len;
1 by brian
clean slate
159
481.1.22 by Monty Taylor
Collapsed over-optimized skip_trailing_spaces.
160
  while (end > ptr && isspace(*--end))
161
    continue;
162
  return end+1;
1 by brian
clean slate
163
}
164
165
#endif