c830d97493a1f187f0b845ab041ac21cc3734d35
[anna.git] / include / anna / http / internal / Tokenizer.hpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #ifndef anna_http_internal_Tokenizer_hpp
10 #define anna_http_internal_Tokenizer_hpp
11
12 #include <anna/core/util/Recycler.hpp>
13
14 #include <anna/http/internal/Token.hpp>
15
16 namespace anna {
17
18 class DataBlock;
19
20 namespace http {
21
22 class Tokenizer : public Recycler<Token> {
23 public:
24   void apply(const DataBlock&) throw(RuntimeException);
25   void apply(const DataBlock&, const char* separator) throw(RuntimeException);
26   void apply(const DataBlock&, const char separator) throw(RuntimeException);
27
28   const Token* operator [](int index) const throw();
29
30   const Token* operator [](const_iterator ii) const throw() {
31     return (ii == end()) ? NULL : token(ii);
32   }
33
34   static const Token* token(const_iterator ii) throw() { return data(ii); }
35   static Token* token(iterator ii) throw() { return data(ii); }
36
37 private:
38   int createToken(const char* p, const int size) throw() {
39     create()->setValue(p, size);
40     return size;
41   }
42
43   static int find(const char* data, const int size, const char character) throw();
44   static int find(const char* data, const int size, const char* searched) throw();
45   static bool isSpace(const int c) throw() { return c <= '\t' || c == ' ' || c >= 128; }
46 };
47
48 }
49 }
50
51 #endif