~vadim-tk/percona-server/percona-galera-5.1.57

« back to all changes in this revision

Viewing changes to sql/gstream.cc

  • Committer: root
  • Date: 2011-07-10 16:09:24 UTC
  • Revision ID: root@r815.office.percona.com-20110710160924-fyffqsbaclgu6vui
Initial port

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2004 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
/*
 
17
  Functions to read and parse geometrical data.
 
18
  NOTE: These functions assumes that the string is end \0 terminated!
 
19
*/
 
20
 
 
21
#include "mysql_priv.h"
 
22
 
 
23
enum Gis_read_stream::enum_tok_types Gis_read_stream::get_next_toc_type()
 
24
{
 
25
  skip_space();
 
26
  if (m_cur >= m_limit)
 
27
    return eostream;
 
28
  if (my_isvar_start(&my_charset_bin, *m_cur))
 
29
    return word;
 
30
  if ((*m_cur >= '0' && *m_cur <= '9') || *m_cur == '-' || *m_cur == '+')
 
31
    return numeric;
 
32
  if (*m_cur == '(')
 
33
    return l_bra;
 
34
  if (*m_cur == ')')
 
35
    return r_bra;
 
36
  if (*m_cur == ',')
 
37
    return comma;
 
38
  return unknown;
 
39
}
 
40
 
 
41
 
 
42
bool Gis_read_stream::get_next_word(LEX_STRING *res)
 
43
{
 
44
  skip_space();
 
45
  res->str= (char*) m_cur;
 
46
  /* The following will also test for \0 */
 
47
  if ((m_cur >= m_limit) || !my_isvar_start(&my_charset_bin, *m_cur))
 
48
    return 1;
 
49
 
 
50
  /*
 
51
    We can't combine the following increment with my_isvar() because
 
52
    my_isvar() is a macro that would cause side effects
 
53
  */
 
54
  m_cur++;
 
55
  while ((m_cur < m_limit) && my_isvar(&my_charset_bin, *m_cur))
 
56
    m_cur++;
 
57
 
 
58
  res->length= (uint32) (m_cur - res->str);
 
59
  return 0;
 
60
}
 
61
 
 
62
 
 
63
/*
 
64
  Read a floating point number
 
65
 
 
66
  NOTE: Number must start with a digit or sign. It can't start with a decimal
 
67
  point
 
68
*/
 
69
 
 
70
bool Gis_read_stream::get_next_number(double *d)
 
71
{
 
72
  char *endptr;
 
73
  int err;
 
74
 
 
75
  skip_space();
 
76
 
 
77
  if ((m_cur >= m_limit) ||
 
78
      ((*m_cur < '0' || *m_cur > '9') && *m_cur != '-' && *m_cur != '+'))
 
79
  {
 
80
    set_error_msg("Numeric constant expected");
 
81
    return 1;
 
82
  }
 
83
 
 
84
  *d = my_strntod(m_charset, (char *)m_cur,
 
85
                  (uint) (m_limit-m_cur), &endptr, &err);
 
86
  if (err)
 
87
    return 1;
 
88
  if (endptr)
 
89
    m_cur = endptr;
 
90
  return 0;
 
91
}
 
92
 
 
93
 
 
94
bool Gis_read_stream::check_next_symbol(char symbol)
 
95
{
 
96
  skip_space();
 
97
  if ((m_cur >= m_limit) || (*m_cur != symbol))
 
98
  {
 
99
    char buff[32];
 
100
    strmov(buff, "'?' expected");
 
101
    buff[2]= symbol;
 
102
    set_error_msg(buff);
 
103
    return 1;
 
104
  }
 
105
  m_cur++;
 
106
  return 0;
 
107
}
 
108
 
 
109
 
 
110
/*
 
111
  Remember error message.
 
112
*/
 
113
 
 
114
void Gis_read_stream::set_error_msg(const char *msg)
 
115
{
 
116
  size_t len= strlen(msg);                      // ok in this context
 
117
  m_err_msg= (char *) my_realloc(m_err_msg, (uint) len + 1, MYF(MY_ALLOW_ZERO_PTR));
 
118
  memcpy(m_err_msg, msg, len + 1);
 
119
}