mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / sql / gstream.cc
blob9e556627da386146f0e1ad5e3fc77e88867b1224
1 /*
2 Copyright (c) 2002, 2004, 2005, 2007 MySQL AB, 2009 Sun Microsystems, Inc.
3 Use is subject to license terms.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 Functions to read and parse geometrical data.
21 NOTE: These functions assumes that the string is end \0 terminated!
24 #include "mysql_priv.h"
26 enum Gis_read_stream::enum_tok_types Gis_read_stream::get_next_toc_type()
28 skip_space();
29 if (m_cur >= m_limit)
30 return eostream;
31 if (my_isvar_start(&my_charset_bin, *m_cur))
32 return word;
33 if ((*m_cur >= '0' && *m_cur <= '9') || *m_cur == '-' || *m_cur == '+')
34 return numeric;
35 if (*m_cur == '(')
36 return l_bra;
37 if (*m_cur == ')')
38 return r_bra;
39 if (*m_cur == ',')
40 return comma;
41 return unknown;
45 bool Gis_read_stream::get_next_word(LEX_STRING *res)
47 skip_space();
48 res->str= (char*) m_cur;
49 /* The following will also test for \0 */
50 if ((m_cur >= m_limit) || !my_isvar_start(&my_charset_bin, *m_cur))
51 return 1;
54 We can't combine the following increment with my_isvar() because
55 my_isvar() is a macro that would cause side effects
57 m_cur++;
58 while ((m_cur < m_limit) && my_isvar(&my_charset_bin, *m_cur))
59 m_cur++;
61 res->length= (uint32) (m_cur - res->str);
62 return 0;
67 Read a floating point number
69 NOTE: Number must start with a digit or sign. It can't start with a decimal
70 point
73 bool Gis_read_stream::get_next_number(double *d)
75 char *endptr;
76 int err;
78 skip_space();
80 if ((m_cur >= m_limit) ||
81 ((*m_cur < '0' || *m_cur > '9') && *m_cur != '-' && *m_cur != '+'))
83 set_error_msg("Numeric constant expected");
84 return 1;
87 *d = my_strntod(m_charset, (char *)m_cur,
88 (uint) (m_limit-m_cur), &endptr, &err);
89 if (err)
90 return 1;
91 if (endptr)
92 m_cur = endptr;
93 return 0;
97 bool Gis_read_stream::check_next_symbol(char symbol)
99 skip_space();
100 if ((m_cur >= m_limit) || (*m_cur != symbol))
102 char buff[32];
103 strmov(buff, "'?' expected");
104 buff[2]= symbol;
105 set_error_msg(buff);
106 return 1;
108 m_cur++;
109 return 0;
114 Remember error message.
117 void Gis_read_stream::set_error_msg(const char *msg)
119 size_t len= strlen(msg); // ok in this context
120 m_err_msg= (char *) my_realloc(m_err_msg, (uint) len + 1, MYF(MY_ALLOW_ZERO_PTR));
121 memcpy(m_err_msg, msg, len + 1);