libUTL++
BBcodeParser.h
1 #pragma once
2 
4 
5 #include <libutl/Hashtable.h>
6 #include <libutl/RBtree.h>
7 
9 
10 UTL_NS_BEGIN;
11 
13 
14 class MemStream;
15 class Token;
16 
18 
19 enum bbcode_context_t
20 {
21  bbc_block,
22  bbc_inline,
23  bbc_list,
24  bbc_list_item
25 };
26 
28 
38 
40 class BBcodeParser : public utl::Object
41 {
43 
44 public:
45  void addIsolatedTag(const String& name, const String& markup);
46 
47  String* parse(const String& input) const;
48 
49  String parseColor(const String& colorName) const;
50 
51  uint_t
52  indentSize() const
53  {
54  return _indentSize;
55  }
56 
57  void
58  setIndentSize(uint_t indentSize)
59  {
60  _indentSize = indentSize;
61  }
62 
63 public:
64  static String filter(const String& text);
65 
66 private:
67  void init();
68  void deInit();
69  utl::Deque* tokenize(const String& input) const;
70  void parse(utl::MemStream& os, utl::Deque& tokens) const;
71  bbcode_context_t
72  processTag(utl::Deque& list, const String& name, uint_t lineNo, uint_t colNo) const;
73  bbcode_context_t processTag(utl::Deque& list, const utl::Deque::iterator& startTagIt) const;
74  bbcode_context_t findContext(utl::Deque& list) const;
75  bool isIsolatedTag(const String& name) const;
76 
77 private:
78  static String toString(const utl::Token* tk, bool verbatim = false);
79  static utl::Token* takeHead(utl::Deque& list);
80  static void removeWShead(utl::Deque& list);
81  static void removeWStail(utl::Deque& list);
82  static void removeNLtail(utl::Deque& list);
83  static void readStartTag(const String& startTag, String& tagName, String& tagParam);
84 
85 private:
86  utl::Hashtable _colorNames;
87  utl::Hashtable _tags;
88  BitArray _emoticonChars;
89  BitArray _emoticonPostChars;
90  uint_t _indentSize;
91 };
92 
94 
95 UTL_NS_END;
String toString(const FwdIt &begin, const FwdIt &end, const String &sep, bool key=false)
Obtain a string representation of a sequence (via Object::toString()).
void deInit()
De-initialize UTL++.
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
Character string.
Definition: String.h:31
Deque iterator.
Definition: DequeIt.h:22
Memory stream.
Definition: MemStream.h:40
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
Scanned token.
Definition: Token.h:22
Chained hashing collection.
Definition: Hashtable.h:92
A sequence of objects permitting efficient insertion and removal at either end.
Definition: Deque.h:28
Root of UTL++ class hierarchy.
Definition: Object.h:52
BBCode parser.
Definition: BBcodeParser.h:40
void init()
Initialize UTL++.
Array of n-bit values.
Definition: BitArray.h:36