-rw-r--r-- | include/opkele/tidy.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/include/opkele/tidy.h b/include/opkele/tidy.h new file mode 100644 index 0000000..888e7d4 --- a/dev/null +++ b/include/opkele/tidy.h | |||
@@ -0,0 +1,73 @@ | |||
1 | #ifndef __OPKELE_TIDY_H | ||
2 | #define __OPKELE_TIDY_H | ||
3 | |||
4 | #include <cassert> | ||
5 | #include <tidy.h> | ||
6 | #include <buffio.h> | ||
7 | |||
8 | namespace opkele { | ||
9 | namespace util { | ||
10 | |||
11 | class tidy_buf_t { | ||
12 | public: | ||
13 | TidyBuffer _x; | ||
14 | |||
15 | tidy_buf_t() { tidyBufInit(&_x); } | ||
16 | virtual ~tidy_buf_t() throw() { | ||
17 | tidyBufFree(&_x); } | ||
18 | |||
19 | inline operator const TidyBuffer&(void) const { return _x; } | ||
20 | inline operator TidyBuffer&(void) { return _x; } | ||
21 | |||
22 | inline operator const char*(void) const { return (const char*)_x.bp; } | ||
23 | inline operator char*(void) { return (char*)_x.bp; } | ||
24 | |||
25 | inline const char *c_str() const { | ||
26 | return (const char*)_x.bp; } | ||
27 | inline size_t size() const { | ||
28 | return _x.size; } | ||
29 | }; | ||
30 | |||
31 | class tidy_doc_t { | ||
32 | public: | ||
33 | TidyDoc _x; | ||
34 | |||
35 | tidy_doc_t() : _x(0) { } | ||
36 | tidy_doc_t(TidyDoc x) : _x(x) { } | ||
37 | virtual ~tidy_doc_t() throw() { | ||
38 | if(_x) tidyRelease(_x); } | ||
39 | |||
40 | tidy_doc_t& operator=(TidyDoc x) { | ||
41 | if(_x) tidyRelease(_x); | ||
42 | _x = x; | ||
43 | return *this; | ||
44 | } | ||
45 | |||
46 | operator const TidyDoc(void) const { return _x; } | ||
47 | operator TidyDoc(void) { return _x; } | ||
48 | |||
49 | inline bool opt_set(TidyOptionId o,bool v) { | ||
50 | assert(_x); | ||
51 | return tidyOptSetBool(_x,o,v?yes:no); } | ||
52 | inline bool opt_set(TidyOptionId o,int v) { | ||
53 | assert(_x); | ||
54 | return tidyOptSetInt(_x,o,v); } | ||
55 | |||
56 | inline int parse_string(const string& s) { | ||
57 | assert(_x); | ||
58 | return tidyParseString(_x,s.c_str()); } | ||
59 | inline int clean_and_repair() { | ||
60 | assert(_x); | ||
61 | return tidyCleanAndRepair(_x); } | ||
62 | inline int save_buffer(TidyBuffer& ob) { | ||
63 | assert(_x); | ||
64 | return tidySaveBuffer(_x,&ob); } | ||
65 | |||
66 | static inline TidyDoc create() { | ||
67 | return tidyCreate(); } | ||
68 | }; | ||
69 | |||
70 | } | ||
71 | } | ||
72 | |||
73 | #endif /* __OPKELE_TIDY_H */ | ||