Tokenizer.h
Go to the documentation of this file.
1 //==============================================================================
2 // Tokenizer.h
3 //------------------------------------------------------------------------------
4 //
5 // Package : Kernel
6 // The LHCb definition package
7 //
8 // Author : M.Frank
9 //
10 // Changes : M.Frank , 01/10/00: Initial version
11 //
12 //==============================================================================
13 #ifndef KERNEL_TOKENIZER_H
14 #define KERNEL_TOKENIZER_H
15 
16 #ifndef KERNEL_TOKENIZER_CPP
17 #warning GaudiKernel/Tokenizer.h is deprecated, see GAUDI-1024 \
18  consider alternative methods like GaudiKernel/AttribStringParser.h or \
19  regular expressions
20 #endif
21 
23 #include "GaudiKernel/Kernel.h"
24 #include <string>
25 #include <vector>
26 
27 
30 class GAUDI_API Tokenizer {
31 public:
34  class Token {
36  long m_length;
38  std::string m_tag;
40  std::string m_value;
41  public:
43  Token(const Token& copy) : m_length(copy.m_length), m_tag(copy.m_tag), m_value(copy.m_value) {
44  }
46  Token() : m_length(0) {
47  }
49  void make(const std::string& s, long st, const char* delim, const char* tagBegin, const char* tagEnd, const char* eq, const char* valBegin, const char* valEnd);
51  virtual ~Token() {
52  }
54  Token& operator=(const Token& copy);
55  // Equality operator
56  bool operator==(const Token& copy) const {
57  return m_tag == copy.m_tag && m_value == copy.m_value && m_length == copy.m_length;
58  }
60  long length() const {
61  return m_length;
62  }
64  const std::string& tag() const {
65  return m_tag;
66  }
68  const std::string& value() const {
69  return m_value;
70  }
72  void resolveValue();
73  };
74  typedef Token Item;
75  typedef std::vector<Token> Items;
76 protected:
78  Items m_tokens;
80  bool m_resolve;
81 public:
83  Tokenizer() : m_resolve(false) {}
85  Tokenizer(bool resolve) : m_resolve(resolve) {}
87  virtual ~Tokenizer() {
88  m_tokens.erase(m_tokens.begin(), m_tokens.end());
89  }
91  void analyse(const std::string& s, const char* delim, const char* tagBegin, const char* tagEnd, const char* eq, const char* valBegin, const char* valEnd);
93  void analyse(const std::string& s, const char* delim, const char* tag, const char* eq, const char* val) {
94  analyse(s, delim, tag, tag, eq, val, val);
95  }
97  void analyse(const std::string& s, const char* delim, const char* eq, const char* val) {
98  analyse(s, delim, "", "", eq, val, val);
99  }
101  void analyse(const std::string& s, const char* delim=" ", const char* eq="=") {
102  analyse(s, delim, "", "", eq, "", "");
103  }
105  Items& items() {
106  return m_tokens;
107  }
109  const Items& items() const {
110  return m_tokens;
111  }
112 };
113 #endif // KERNEL_TOKENIZER_H
#define GAUDI_API
Definition: Kernel.h:108
bool operator==(const GaudiUtils::Allocator< T1 > &, const GaudiUtils::Allocator< T2 > &)
Definition: Allocator.h:249
return false
Definition: Bootstrap.cpp:338
STL Include files.
Definition: Tokenizer.h:30
string s
Definition: gaudirun.py:244