~vlad-lesin/percona-server/mysql-5.0.33-original

« back to all changes in this revision

Viewing changes to sql/gstream.cc

  • Committer: Vlad Lesin
  • Date: 2012-07-31 09:21:34 UTC
  • Revision ID: vladislav.lesin@percona.com-20120731092134-zfodx022b7992wsi
VirginĀ 5.0.33

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; either version 2 of the License, or
 
6
   (at your option) any later version.
 
7
 
 
8
   This program is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
   GNU General Public License for more details.
 
12
 
 
13
   You should have received a copy of the GNU General Public License
 
14
   along with this program; if not, write to the Free Software
 
15
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
16
 
 
17
/*
 
18
  Functions to read and parse geometrical data.
 
19
  NOTE: These functions assumes that the string is end \0 terminated!
 
20
*/
 
21
 
 
22
#include "mysql_priv.h"
 
23
 
 
24
enum Gis_read_stream::enum_tok_types Gis_read_stream::get_next_toc_type()
 
25
{
 
26
  skip_space();
 
27
  if (m_cur >= m_limit)
 
28
    return eostream;
 
29
  if (my_isvar_start(&my_charset_bin, *m_cur))
 
30
    return word;
 
31
  if ((*m_cur >= '0' && *m_cur <= '9') || *m_cur == '-' || *m_cur == '+')
 
32
    return numeric;
 
33
  if (*m_cur == '(')
 
34
    return l_bra;
 
35
  if (*m_cur == ')')
 
36
    return r_bra;
 
37
  if (*m_cur == ',')
 
38
    return comma;
 
39
  return unknown;
 
40
}
 
41
 
 
42
 
 
43
bool Gis_read_stream::get_next_word(LEX_STRING *res)
 
44
{
 
45
  skip_space();
 
46
  res->str= (char*) m_cur;
 
47
  /* The following will also test for \0 */
 
48
  if (!my_isvar_start(&my_charset_bin, *m_cur))
 
49
    return 1;
 
50
 
 
51
  /*
 
52
    We can't combine the following increment with my_isvar() because
 
53
    my_isvar() is a macro that would cause side effects
 
54
  */
 
55
  m_cur++;
 
56
  while ((m_cur < m_limit) && my_isvar(&my_charset_bin, *m_cur))
 
57
    m_cur++;
 
58
 
 
59
  res->length= (uint32) (m_cur - res->str);
 
60
  return 0;
 
61
}
 
62
 
 
63
 
 
64
/*
 
65
  Read a floating point number
 
66
 
 
67
  NOTE: Number must start with a digit or sign. It can't start with a decimal
 
68
  point
 
69
*/
 
70
 
 
71
bool Gis_read_stream::get_next_number(double *d)
 
72
{
 
73
  char *endptr;
 
74
  int err;
 
75
 
 
76
  skip_space();
 
77
 
 
78
  if ((m_cur >= m_limit) ||
 
79
      (*m_cur < '0' || *m_cur > '9') && *m_cur != '-' && *m_cur != '+')
 
80
  {
 
81
    set_error_msg("Numeric constant expected");
 
82
    return 1;
 
83
  }
 
84
 
 
85
  *d = my_strntod(m_charset, (char *)m_cur,
 
86
                  (uint) (m_limit-m_cur), &endptr, &err);
 
87
  if (err)
 
88
    return 1;
 
89
  if (endptr)
 
90
    m_cur = endptr;
 
91
  return 0;
 
92
}
 
93
 
 
94
 
 
95
bool Gis_read_stream::check_next_symbol(char symbol)
 
96
{
 
97
  skip_space();
 
98
  if ((m_cur >= m_limit) || (*m_cur != symbol))
 
99
  {
 
100
    char buff[32];
 
101
    strmov(buff, "'?' expected");
 
102
    buff[2]= symbol;
 
103
    set_error_msg(buff);
 
104
    return 1;
 
105
  }
 
106
  m_cur++;
 
107
  return 0;
 
108
}
 
109
 
 
110
 
 
111
/*
 
112
  Remember error message.
 
113
*/
 
114
 
 
115
void Gis_read_stream::set_error_msg(const char *msg)
 
116
{
 
117
  size_t len= strlen(msg);                      // ok in this context
 
118
  m_err_msg= (char *) my_realloc(m_err_msg, (uint) len + 1, MYF(MY_ALLOW_ZERO_PTR));
 
119
  memcpy(m_err_msg, msg, len + 1);
 
120
}