X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=include%2Fanna%2Fcore%2Futil%2FTokenizer.hpp;h=585f34c5e0d12a15bcac38f0e36b8200395f98ed;hb=5a6cba5fde2b2f538a7515f8293cc0a8d9589dfa;hp=b0fbada9f08127607913c55aef9001c9a24cbf9b;hpb=4e12ac57e93c052f716a6305ad8fc099c45899d1;p=anna.git diff --git a/include/anna/core/util/Tokenizer.hpp b/include/anna/core/util/Tokenizer.hpp index b0fbada..585f34c 100644 --- a/include/anna/core/util/Tokenizer.hpp +++ b/include/anna/core/util/Tokenizer.hpp @@ -1,37 +1,9 @@ -// ANNA - Anna is Not 'N' Anymore -// -// (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo -// -// https://bitbucket.org/testillano/anna -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Authors: eduardo.ramos.testillano@gmail.com -// cisco.tierra@gmail.com +// ANNA - Anna is Not Nothingness Anymore // +// // +// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo // +// // +// See project site at http://redmine.teslayout.com/projects/anna-suite // +// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE // #ifndef anna_core_util_Tokenizer_hpp @@ -46,9 +18,12 @@ namespace anna { class RuntimeException; /** - Separa la cadena recibida en distintos elementos. + Tokenize the input string into several elements */ class Tokenizer { + + int _apply(const char* str, const char* separator) noexcept(false); + public: typedef char* const* const_iterator; @@ -85,7 +60,7 @@ public: Devuelve el estado del indicador de activacion de eliminacion de espacios de los extremos. \return El estado del indicador de activacion de eliminacion de espacios de los extremos. */ - bool activateStrip() const throw() { return a_activateStrip; } + bool activateStrip() const { return a_activateStrip; } // Operadores @@ -94,87 +69,85 @@ public: por esta clase sin espacios por delante y por detras. \param _activateStrip Parametro que indica el estado de activacion o desactivacion. */ - void activateStrip(const bool _activateStrip) throw() { a_activateStrip = _activateStrip; } + void activateStrip(const bool _activateStrip) { a_activateStrip = _activateStrip; } /** @return El elemento que ocupa la posicion i-esima. \warning Este método tiene una eficiencia de O(1), mejor usar iteradores. */ - const char* at(const int i) throw(RuntimeException); + const char* at(const int i) noexcept(false); /** @return El elemento que ocupa la posicion i-esima. \warning Este método tiene una eficiencia de O(1), mejor usar iteradores. */ - const char* at(const int i) const throw(RuntimeException); + const char* at(const int i) const noexcept(false); /** @return El elemento que ocupa la posicion i-esima. \warning Este método tiene una eficiencia de O(1), mejor usar iteradores. */ - const char* operator [](const int i) throw(RuntimeException) { return at(i); } + const char* operator [](const int i) noexcept(false) { return at(i); } /** @return El elemento que ocupa la posicion i-esima. \warning Este método tiene una eficiencia de O(1), mejor usar iteradores. */ - const char* operator [](const int i) const throw(RuntimeException) { return at(i); } + const char* operator [](const int i) const noexcept(false) { return at(i); } /** - Aplica la separacion sobre la cadena str con el separador recibido como parametro. + Process the separation over the string str with the separator provided. - @param str Cadena sobre la que aplicar la separacion. - @param separator Caracteres que van a actuar como separador de las subcadenas contenidas en el - primer parametro. + Internally used strtok_r has these imitations: sequence of two or more contiguous delimiter + bytes in the parsed string is considered to be a single delimiter. Delimiter bytes at the start + or end of the string are ignored. Put another way: the tokens returned by strtok() are always + nonempty strings. To override these limitations, the string provided can be internally modified + inserting a artificial token in order to cheat on strtok_r. For this feature, you may provide + '' or whatever string (non-empty) you prefer. - @return Numero de elementos obtenidos al aplicar la separacion. + @param str String to apply the separation. + @param separator Characters used as separator within the string tokenized + @param tokenizeContiguous If provided, it will be the artificial token used internally. The + resulting tokens shall store this string in case of contiguous separators. NULL by + default (original strtok_r behaviour). + @return Number of tokens */ - int apply(const std::string& str, const char* separator) throw(RuntimeException) { - return apply(str.c_str(), separator); + int apply(const char* str, const char* separator, const char *tokenizeContiguous = NULL) noexcept(false); + int apply(const std::string& str, const char* separator, const char *tokenizeContiguous = NULL) noexcept(false) { + return apply(str.c_str(), separator, tokenizeContiguous); } - /** - Aplica la separacion sobre la cadena str con el separador recibido como parametro. - - @param str Cadena sobre la que aplicar la separacion. - @param separator Caracteres que van a actuar como separador de las subcadenas contenidas en el - primer parametro. - - @return Numero de elementos obtenidos al aplicar la separacion. - - */ - int apply(const char* str, const char* separator) throw(RuntimeException); // Metodos /** @return El ultimo elemento obtenido la aplicar la separacion. */ - const char* last() const throw(RuntimeException); + const char* last() const noexcept(false); /** * Devuelve el número de elementos obtenidos en la separación. * \return el número de elementos obtenidos en la separación. */ - int size() const throw() { return a_maxItem; } + int size() const { return a_maxItem; } /** * Devuelve el iterador el comiento de los elementos obtenidos por #apply * \return el iterador el comiento de los elementos obtenidos por #apply */ - const_iterator begin() const throw() { return a_items; } + const_iterator begin() const { return a_items; } /** * Devuelve el iterador al final de los elementos obtenidos por #apply * \return el iterador al final de los elementos obtenidos por #apply */ - const_iterator end() const throw() { return a_items + a_maxItem; } + const_iterator end() const { return a_items + a_maxItem; } /** Devuelve la cadena referenciada por el iterator recibido como parametro. \return la cadena referenciada por el iterator recibido como parametro. */ - static const char* data(const_iterator ii) throw() { return *ii; } + static const char* data(const_iterator ii) { return *ii; } private: static const int MaxItem; @@ -184,9 +157,9 @@ private: char** a_items; int a_maxItem; - static char* strip(char* str) throw(); + static char* strip(char* str) ; - void indexException(const int index, const char* fromFile, const int fromLine) const throw(RuntimeException); + void indexException(const int index, const char* fromFile, const int fromLine) const noexcept(false); }; }