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()
31 if (my_isvar_start(&my_charset_bin
, *m_cur
))
33 if ((*m_cur
>= '0' && *m_cur
<= '9') || *m_cur
== '-' || *m_cur
== '+')
45 bool Gis_read_stream::get_next_word(LEX_STRING
*res
)
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
))
54 We can't combine the following increment with my_isvar() because
55 my_isvar() is a macro that would cause side effects
58 while ((m_cur
< m_limit
) && my_isvar(&my_charset_bin
, *m_cur
))
61 res
->length
= (uint32
) (m_cur
- res
->str
);
67 Read a floating point number
69 NOTE: Number must start with a digit or sign. It can't start with a decimal
73 bool Gis_read_stream::get_next_number(double *d
)
80 if ((m_cur
>= m_limit
) ||
81 ((*m_cur
< '0' || *m_cur
> '9') && *m_cur
!= '-' && *m_cur
!= '+'))
83 set_error_msg("Numeric constant expected");
87 *d
= my_strntod(m_charset
, (char *)m_cur
,
88 (uint
) (m_limit
-m_cur
), &endptr
, &err
);
97 bool Gis_read_stream::check_next_symbol(char symbol
)
100 if ((m_cur
>= m_limit
) || (*m_cur
!= symbol
))
103 strmov(buff
, "'?' expected");
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);