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.

120 lines
2.8 KiB

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