1 #ifndef GSTREAM_INCLUDED
2 #define GSTREAM_INCLUDED
3 
4 /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
5 
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; version 2 of the License.
9 
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
18 
19 
20 #include "my_global.h"                          /* NULL, NullS */
21 #include "my_sys.h"                             /* MY_ALLOW_ZERO_PTR */
22 #include "m_ctype.h"           /* my_charset_latin1, my_charset_bin */
23 
24 typedef struct charset_info_st CHARSET_INFO;
25 typedef struct st_mysql_lex_string LEX_STRING;
26 
27 class Gis_read_stream
28 {
29 public:
30   enum enum_tok_types
31   {
32     unknown,
33     eostream,
34     word,
35     numeric,
36     l_bra,
37     r_bra,
38     comma
39   };
40 
Gis_read_stream(CHARSET_INFO * charset,const char * buffer,int size)41   Gis_read_stream(CHARSET_INFO *charset, const char *buffer, int size)
42     :m_cur(buffer), m_limit(buffer + size), m_err_msg(NULL), m_charset(charset)
43   {}
Gis_read_stream()44   Gis_read_stream(): m_cur(NullS), m_limit(NullS), m_err_msg(NullS)
45   {}
~Gis_read_stream()46   ~Gis_read_stream()
47   {
48     my_free(m_err_msg);
49   }
50 
51   enum enum_tok_types get_next_toc_type();
52   bool get_next_word(LEX_STRING *);
53   bool get_next_number(double *);
54   bool check_next_symbol(char);
55 
skip_space()56   inline void skip_space()
57   {
58     while ((m_cur < m_limit) && my_isspace(&my_charset_latin1, *m_cur))
59       m_cur++;
60   }
61   /* Skip next character, if match. Return 1 if no match */
skip_char(char skip)62   inline bool skip_char(char skip)
63   {
64     skip_space();
65     if ((m_cur >= m_limit) || *m_cur != skip)
66       return 1;					/* Didn't find char */
67     m_cur++;
68     return 0;
69   }
70   void set_error_msg(const char *msg);
71 
72   // caller should free this pointer
get_error_msg()73   char *get_error_msg()
74   {
75     char *err_msg = m_err_msg;
76     m_err_msg= NullS;
77     return err_msg;
78   }
79 
80 protected:
81   const char *m_cur;
82   const char *m_limit;
83   char *m_err_msg;
84   CHARSET_INFO *m_charset;
85 };
86 
87 #endif /* GSTREAM_INCLUDED */
88