mariadb/sql/gstream.cc

140 lines
2.1 KiB
C++
Raw Normal View History

2002-02-22 12:24:42 +01:00
#include "mysql_priv.h"
int GTextReadStream::get_next_toc_type() const
{
const char *cur = m_cur;
2002-12-28 00:01:05 +01:00
while ((*cur)&&(strchr(" \t\r\n",*cur)))
2002-02-22 12:24:42 +01:00
{
cur++;
}
2002-12-28 00:01:05 +01:00
if (!(*cur))
2002-02-22 12:24:42 +01:00
{
return eostream;
}
2002-12-28 00:01:05 +01:00
if (((*cur>='a') && (*cur<='z')) || ((*cur>='A') && (*cur<='Z')) ||
(*cur=='_'))
2002-02-22 12:24:42 +01:00
{
return word;
}
2002-12-28 00:01:05 +01:00
if (((*cur>='0') && (*cur<='9')) || (*cur=='-') || (*cur=='+') ||
(*cur=='.'))
2002-02-22 12:24:42 +01:00
{
return numeric;
}
2002-12-28 00:01:05 +01:00
if (*cur == '(')
2002-02-22 12:24:42 +01:00
{
return l_bra;
}
2002-12-28 00:01:05 +01:00
if (*cur == ')')
2002-02-22 12:24:42 +01:00
{
return r_bra;
}
2002-12-28 00:01:05 +01:00
if (*cur == ',')
2002-02-22 12:24:42 +01:00
{
return comma;
}
return unknown;
}
const char *GTextReadStream::get_next_word(int *word_len)
{
const char *cur = m_cur;
2002-12-28 00:01:05 +01:00
while ((*cur)&&(strchr(" \t\r\n",*cur)))
2002-02-22 12:24:42 +01:00
{
cur++;
}
m_last_text_position = cur;
2002-12-28 00:01:05 +01:00
if (!(*cur))
2002-02-22 12:24:42 +01:00
{
return 0;
}
const char *wd_start = cur;
2002-12-28 00:01:05 +01:00
if (((*cur<'a') || (*cur>'z')) && ((*cur<'A') || (*cur>'Z')) && (*cur!='_'))
2002-02-22 12:24:42 +01:00
{
return NULL;
}
++cur;
2002-12-28 00:01:05 +01:00
while (((*cur>='a') && (*cur<='z')) || ((*cur>='A') && (*cur<='Z')) ||
(*cur=='_') || ((*cur>='0') && (*cur<='9')))
2002-02-22 12:24:42 +01:00
{
++cur;
}
*word_len = cur - wd_start;
m_cur = cur;
return wd_start;
}
int GTextReadStream::get_next_number(double *d)
{
const char *cur = m_cur;
2002-12-28 00:01:05 +01:00
while ((*cur)&&(strchr(" \t\r\n",*cur)))
2002-02-22 12:24:42 +01:00
{
cur++;
}
m_last_text_position = cur;
2002-12-28 00:01:05 +01:00
if (!(*cur))
2002-02-22 12:24:42 +01:00
{
set_error_msg("Numeric constant expected");
return 1;
}
2002-12-28 00:01:05 +01:00
if (((*cur<'0') || (*cur>'9')) && (*cur!='-') && (*cur!='+') && (*cur!='.'))
2002-02-22 12:24:42 +01:00
{
set_error_msg("Numeric constant expected");
return 1;
}
char *endptr;
*d = strtod(cur, &endptr);
2002-02-22 12:24:42 +01:00
2002-12-28 00:01:05 +01:00
if (endptr)
2002-02-22 12:24:42 +01:00
{
m_cur = endptr;
}
return 0;
}
char GTextReadStream::get_next_symbol()
{
const char *cur = m_cur;
2002-12-28 00:01:05 +01:00
while ((*cur)&&(strchr(" \t\r\n",*cur)))
2002-02-22 12:24:42 +01:00
{
cur++;
}
2002-12-28 00:01:05 +01:00
if (!(*cur))
2002-02-22 12:24:42 +01:00
{
return 0;
}
m_cur = cur + 1;
m_last_text_position = cur;
return *cur;
}
void GTextReadStream::set_error_msg(const char *msg)
{
size_t len = strlen(msg);
m_err_msg = (char *)my_realloc(m_err_msg, len + 1, MYF(MY_ALLOW_ZERO_PTR));
memcpy(m_err_msg, msg, len + 1);
}