OSDN Git Service

ea9fd300c0d82ed2feb83c3c208f17b321a54364
[hmh/hhml.git] / lib / ustring.h
1 #ifndef USTRING_H
2 #define USTRING_H
3
4 #include <string>
5 #include <utility>
6 #include <boost/regex.hpp>
7
8 inline char*  char_type (u_char* v) {return (char*)v;}
9 inline char*  char_type (char* v) {return v;}
10 inline const char*  char_type (const u_char* v) {return (const char*)v;}
11 //inline u_char*  uchar_type (char* v) {return (u_char*)v;}
12 inline const u_char*  uchar_type (const char* v) {return (const u_char*)v;}
13 inline char*  noconst_char (const char* v) {return (char*)v;}
14 #define UCharConst(s)           (uchar_type(s)), (sizeof (s) - 1)
15 #define CharConst(s)            (s), (sizeof (s) - 1)
16 #define comapreHead(s)          compare(0, sizeof(s) - 1, (s), sizeof(s) - 1)
17
18 typedef std::basic_string<char>         ustring;
19 typedef ustring::const_iterator         uiterator;
20 typedef std::pair<ustring::const_iterator, ustring::const_iterator>  upair;
21 typedef boost::match_results<ustring::const_iterator>  umatch;
22 typedef boost::basic_regex<char, boost::regex_traits<char> >  uregex;
23
24 inline bool  usearch (ustring::const_iterator first, ustring::const_iterator last, umatch& m, const uregex& re, boost::match_flag_type flags = boost::regex_constants::match_single_line) {
25     return regex_search (first, last, m, re, flags);
26 }
27 inline bool  usearch (const ustring& s, umatch& m, const uregex& re, boost::match_flag_type flags = boost::regex_constants::match_single_line) {
28     return regex_search (s.begin (), s.end (), m, re, flags);
29 }
30
31 inline int  match (upair& p, const u_char* s, ustring::size_type len) {
32     ustring::size_type  n = p.second - p.first;
33     return (n == len && memcmp (p.first.base (), s, n) == 0);
34 }
35
36 inline uiterator  find (uiterator b, uiterator e, ustring::value_type ch) {
37     for (; b != e; b ++) {
38         if (*b == ch)
39             return b;
40     }
41     return b;
42 }
43
44 #endif /* USTRING_H */