You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
2.9 KiB

  1. /*
  2. Copyright (c) 2002, 2004-2007 MySQL AB, 2009 Sun Microsystems, Inc.
  3. Use is subject to license terms.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; version 2 of the License.
  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. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  14. */
  15. /*
  16. Functions to read and parse geometrical data.
  17. NOTE: These functions assumes that the string is end \0 terminated!
  18. */
  19. #include "mysql_priv.h"
  20. enum Gis_read_stream::enum_tok_types Gis_read_stream::get_next_toc_type()
  21. {
  22. skip_space();
  23. if (m_cur >= m_limit)
  24. return eostream;
  25. if (my_isvar_start(&my_charset_bin, *m_cur))
  26. return word;
  27. if ((*m_cur >= '0' && *m_cur <= '9') || *m_cur == '-' || *m_cur == '+')
  28. return numeric;
  29. if (*m_cur == '(')
  30. return l_bra;
  31. if (*m_cur == ')')
  32. return r_bra;
  33. if (*m_cur == ',')
  34. return comma;
  35. return unknown;
  36. }
  37. bool Gis_read_stream::get_next_word(LEX_STRING *res)
  38. {
  39. skip_space();
  40. res->str= (char*) m_cur;
  41. /* The following will also test for \0 */
  42. if ((m_cur >= m_limit) || !my_isvar_start(&my_charset_bin, *m_cur))
  43. return 1;
  44. /*
  45. We can't combine the following increment with my_isvar() because
  46. my_isvar() is a macro that would cause side effects
  47. */
  48. m_cur++;
  49. while ((m_cur < m_limit) && my_isvar(&my_charset_bin, *m_cur))
  50. m_cur++;
  51. res->length= (uint32) (m_cur - res->str);
  52. return 0;
  53. }
  54. /*
  55. Read a floating point number
  56. NOTE: Number must start with a digit or sign. It can't start with a decimal
  57. point
  58. */
  59. bool Gis_read_stream::get_next_number(double *d)
  60. {
  61. char *endptr;
  62. int err;
  63. skip_space();
  64. if ((m_cur >= m_limit) ||
  65. ((*m_cur < '0' || *m_cur > '9') && *m_cur != '-' && *m_cur != '+'))
  66. {
  67. set_error_msg("Numeric constant expected");
  68. return 1;
  69. }
  70. *d = my_strntod(m_charset, (char *)m_cur,
  71. (uint) (m_limit-m_cur), &endptr, &err);
  72. if (err)
  73. return 1;
  74. if (endptr)
  75. m_cur = endptr;
  76. return 0;
  77. }
  78. bool Gis_read_stream::check_next_symbol(char symbol)
  79. {
  80. skip_space();
  81. if ((m_cur >= m_limit) || (*m_cur != symbol))
  82. {
  83. char buff[32];
  84. strmov(buff, "'?' expected");
  85. buff[2]= symbol;
  86. set_error_msg(buff);
  87. return 1;
  88. }
  89. m_cur++;
  90. return 0;
  91. }
  92. /*
  93. Remember error message.
  94. */
  95. void Gis_read_stream::set_error_msg(const char *msg)
  96. {
  97. size_t len= strlen(msg); // ok in this context
  98. m_err_msg= (char *) my_realloc(m_err_msg, (uint) len + 1, MYF(MY_ALLOW_ZERO_PTR));
  99. memcpy(m_err_msg, msg, len + 1);
  100. }