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-1335  USA */
18 
19 
20 #include <my_sys.h>                             /* MY_ALLOW_ZERO_PTR */
21 #include "m_ctype.h"           /* my_charset_latin1, my_charset_bin */
22 
23 class Gis_read_stream
24 {
25 public:
26   enum enum_tok_types
27   {
28     unknown,
29     eostream,
30     word,
31     numeric,
32     l_bra,
33     r_bra,
34     comma
35   };
36 
Gis_read_stream(CHARSET_INFO * charset,const char * buffer,int size)37   Gis_read_stream(CHARSET_INFO *charset, const char *buffer, int size)
38     :m_cur(buffer), m_limit(buffer + size), m_err_msg(NULL), m_charset(charset)
39   {}
Gis_read_stream()40   Gis_read_stream(): m_cur(NullS), m_limit(NullS), m_err_msg(NullS)
41   {}
~Gis_read_stream()42   ~Gis_read_stream()
43   {
44     my_free(m_err_msg);
45   }
46 
47   enum enum_tok_types get_next_toc_type();
48   bool lookup_next_word(LEX_STRING *res);
49   bool get_next_word(LEX_STRING *);
50   bool get_next_number(double *);
51   bool check_next_symbol(char);
52 
skip_space()53   inline void skip_space()
54   {
55     while ((m_cur < m_limit) && my_isspace(&my_charset_latin1, *m_cur))
56       m_cur++;
57   }
58   /* Skip next character, if match. Return 1 if no match */
skip_char(char skip)59   inline bool skip_char(char skip)
60   {
61     skip_space();
62     if ((m_cur >= m_limit) || *m_cur != skip)
63       return 1;					/* Didn't find char */
64     m_cur++;
65     return 0;
66   }
67   /* Returns the next notempty character. */
next_symbol()68   char next_symbol()
69   {
70     skip_space();
71     if (m_cur >= m_limit)
72       return 0;                                 /* EOL meet. */
73     return *m_cur;
74   }
75   void set_error_msg(const char *msg);
76 
77   // caller should free this pointer
get_error_msg()78   char *get_error_msg()
79   {
80     char *err_msg = m_err_msg;
81     m_err_msg= NullS;
82     return err_msg;
83   }
84 
85 protected:
86   const char *m_cur;
87   const char *m_limit;
88   char *m_err_msg;
89   CHARSET_INFO *m_charset;
90 };
91 
92 #endif /* GSTREAM_INCLUDED */
93