diff --git a/qse/include/qse/Hashable.hpp b/qse/include/qse/Hashable.hpp index 8ab1da84..13993985 100644 --- a/qse/include/qse/Hashable.hpp +++ b/qse/include/qse/Hashable.hpp @@ -48,11 +48,29 @@ public: /// A class of an hashable object must implement this function. 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; - 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; for (qse_size_t i = 0; i < QSE_SIZEOF(*str); i++) @@ -63,9 +81,9 @@ public: 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) @@ -98,7 +116,7 @@ public: /// pointed to by \a data of the length \a 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); } }; diff --git a/qse/include/qse/Types.hpp b/qse/include/qse/Types.hpp index a5af9437..3da7d0db 100644 --- a/qse/include/qse/Types.hpp +++ b/qse/include/qse/Types.hpp @@ -232,6 +232,7 @@ public: E_EINTERN, /**< internal error */ E_ENOMEM, + E_NARGS, /**< wrong number of arguments */ E_EINVAL, E_EACCES, E_EPERM, diff --git a/qse/include/qse/sttp/Sttp.hpp b/qse/include/qse/sttp/Sttp.hpp index 4b8ef796..bc46fe9a 100644 --- a/qse/include/qse/sttp/Sttp.hpp +++ b/qse/include/qse/sttp/Sttp.hpp @@ -181,6 +181,35 @@ protected: int flush_outbuf () QSE_CPP_NOEXCEPT; }; + +#if 0 +class SttpStdHandler +{ + int operator() (const SttpCmd& cmd) + { + } + +}; + +template +class SttpX +{ + int exec() + { + if (this->receiveCmd(&cmd) <= -1) + { + } + + if (this->handler(&cmd) <= -1) + { + } + } + +protected: + HANDLER handler; +}; +#endif + QSE_END_NAMESPACE(QSE) #endif diff --git a/qse/include/qse/sttp/SttpCmd.hpp b/qse/include/qse/sttp/SttpCmd.hpp index 5354e4b8..084351da 100644 --- a/qse/include/qse/sttp/SttpCmd.hpp +++ b/qse/include/qse/sttp/SttpCmd.hpp @@ -67,6 +67,11 @@ public: this->name.append (n, size); } + const QSE::String& getName () const + { + return this->name; + } + bool isNullCmd () const { return this->name.getSize() == 0; diff --git a/qse/lib/sttp/Sttp.cpp b/qse/lib/sttp/Sttp.cpp index 77ec21da..0e2f4c0c 100644 --- a/qse/lib/sttp/Sttp.cpp +++ b/qse/lib/sttp/Sttp.cpp @@ -417,28 +417,37 @@ int Sttp::get_token () QSE_CPP_NOEXCEPT { while (QSE_ISSPACE(this->sttp_curc)) GET_CHAR (); // skip spaces... - if (is_ident_char(this->sttp_curc)) return get_ident (); - else if (this->sttp_curc == QSE_T('\"') || this->sttp_curc == QSE_T('\'')) + if (is_ident_char(this->sttp_curc)) return this->get_ident (); + else { - 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 - { - this->p_errcode = E_WRONGCHAR; - return -1; + switch (this->sttp_curc) + { + 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;