fixed Sttp to return T_EOF when EOF is reached

This commit is contained in:
hyung-hwan 2018-10-21 16:36:03 +00:00
parent 942f33d8d4
commit 1758ba4e1e
5 changed files with 88 additions and 26 deletions

View File

@ -48,11 +48,29 @@ public:
/// A class of an hashable object must implement this function. /// A class of an hashable object must implement this function.
virtual qse_size_t getHashCode () const = 0; virtual qse_size_t getHashCode () const = 0;
static qse_size_t getHashCode (qse_size_t init, const qse_char_t* str) static qse_size_t getHashCode (qse_size_t init, const qse_mchar_t* str)
{ {
qse_size_t n = init; qse_size_t n = init;
while (*str != QSE_T('\0')) while (*str != QSE_MT('\0'))
{
n = n * 31 + *((qse_uint8_t*)str);
str++;
}
return n;
}
static qse_size_t getHashCode (const qse_mchar_t* str)
{
return Hashable::getHashCode(0, str);
}
static qse_size_t getHashCode (qse_size_t init, const qse_wchar_t* str)
{
qse_size_t n = init;
while (*str != QSE_WT('\0'))
{ {
const qse_uint8_t* p = (const qse_uint8_t*)str; const qse_uint8_t* p = (const qse_uint8_t*)str;
for (qse_size_t i = 0; i < QSE_SIZEOF(*str); i++) for (qse_size_t i = 0; i < QSE_SIZEOF(*str); i++)
@ -63,9 +81,9 @@ public:
return n; return n;
} }
static qse_size_t getHashCode (const qse_char_t* str) static qse_size_t getHashCode (const qse_wchar_t* str)
{ {
return Hashable::getHashCode (0, str); return Hashable::getHashCode(0, str);
} }
static qse_size_t getHashCode (qse_size_t init, const void* data, qse_size_t size) static qse_size_t getHashCode (qse_size_t init, const void* data, qse_size_t size)
@ -98,7 +116,7 @@ public:
/// pointed to by \a data of the length \a size. /// pointed to by \a data of the length \a size.
static qse_size_t getHashCode (const void* data, qse_size_t size) static qse_size_t getHashCode (const void* data, qse_size_t size)
{ {
return Hashable::getHashCode (0, data, size); return Hashable::getHashCode(0, data, size);
} }
}; };

View File

@ -232,6 +232,7 @@ public:
E_EINTERN, /**< internal error */ E_EINTERN, /**< internal error */
E_ENOMEM, E_ENOMEM,
E_NARGS, /**< wrong number of arguments */
E_EINVAL, E_EINVAL,
E_EACCES, E_EACCES,
E_EPERM, E_EPERM,

View File

@ -181,6 +181,35 @@ protected:
int flush_outbuf () QSE_CPP_NOEXCEPT; int flush_outbuf () QSE_CPP_NOEXCEPT;
}; };
#if 0
class SttpStdHandler
{
int operator() (const SttpCmd& cmd)
{
}
};
template <class HANDLER>
class SttpX
{
int exec()
{
if (this->receiveCmd(&cmd) <= -1)
{
}
if (this->handler(&cmd) <= -1)
{
}
}
protected:
HANDLER handler;
};
#endif
QSE_END_NAMESPACE(QSE) QSE_END_NAMESPACE(QSE)
#endif #endif

View File

@ -67,6 +67,11 @@ public:
this->name.append (n, size); this->name.append (n, size);
} }
const QSE::String& getName () const
{
return this->name;
}
bool isNullCmd () const bool isNullCmd () const
{ {
return this->name.getSize() == 0; return this->name.getSize() == 0;

View File

@ -417,28 +417,37 @@ int Sttp::get_token () QSE_CPP_NOEXCEPT
{ {
while (QSE_ISSPACE(this->sttp_curc)) GET_CHAR (); // skip spaces... while (QSE_ISSPACE(this->sttp_curc)) GET_CHAR (); // skip spaces...
if (is_ident_char(this->sttp_curc)) return get_ident (); if (is_ident_char(this->sttp_curc)) return this->get_ident ();
else if (this->sttp_curc == QSE_T('\"') || this->sttp_curc == QSE_T('\''))
{
return get_string (sttp_curc);
}
else if (this->sttp_curc == QSE_T(';'))
{
this->token_type = T_SEMICOLON;
this->token_value = QSE_T(';');
// do not read the next character to terminate a command
// get_char ();
}
else if (this->sttp_curc == QSE_T(','))
{
this->token_type = T_COMMA;
this->token_value = QSE_T(',');
GET_CHAR ();
}
else else
{ {
this->p_errcode = E_WRONGCHAR; switch (this->sttp_curc)
return -1; {
case QSE_T('\"'):
case QSE_T('\''):
return this->get_string(sttp_curc);
case QSE_T(';'):
this->token_type = T_SEMICOLON;
this->token_value = QSE_T(';');
// do not read the next character to terminate a command
// get_char ();
break;
case QSE_T(','):
this->token_type = T_COMMA;
this->token_value = QSE_T(',');
GET_CHAR ();
break;
case QSE_CHAR_EOF:
this->token_type = T_EOF;
this->token_value = this->sttp_curc;
break;
default:
this->p_errcode = E_WRONGCHAR;
return -1;
}
} }
return 0; return 0;