root/nntp/lexutils.hh
| Revision 868b365c127bbf4f0b52f22da03e32a94a4f6653, 2.6 KB (checked in by Antti-Juhani Kaijanaho <antti-juhani@…>, 3 years ago) | |
|---|---|
|
|
| Line | |
|---|---|
| 1 | /* This file is part of Alue, the multiprotocol Internet discussion daemon |
| 2 | |
| 3 | Copyright © 2009 Antti-Juhani Kaijanaho |
| 4 | |
| 5 | Alue is free software: you can redistribute it and/or modify it |
| 6 | under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation, either version 3 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | Alue is distributed in the hope that it will be useful, but |
| 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with Alue. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | */ |
| 19 | |
| 20 | #ifndef GUARD_NNTP_LEXUTILS_HH |
| 21 | #define GUARD_NNTP_LEXUTILS_HH |
| 22 | |
| 23 | #include "../db/group.hh" |
| 24 | #include "../util.hh" |
| 25 | |
| 26 | #include <boost/tuple/tuple.hpp> |
| 27 | #include <string> |
| 28 | |
| 29 | namespace nntp |
| 30 | { |
| 31 | using util::strip_crlf; |
| 32 | using util::parse_exception; |
| 33 | using util::parse_nonnegative_integer; |
| 34 | using util::split; |
| 35 | using util::is_number; |
| 36 | using util::is_digit; |
| 37 | |
| 38 | /** Returns true if s is a RFC 3977 keyword. */ |
| 39 | bool is_keyword(std::string s); |
| 40 | |
| 41 | /** Returns true if s is a RFC 3977 newsgroup name. */ |
| 42 | bool is_newsgroup_name(std::string s); |
| 43 | |
| 44 | /** Parses a RFC 3977 range: either nn (in which case (nn,nn) |
| 45 | * is returned), nn- (in which case (nn,infinity) is |
| 46 | * returned), or nn-mm (returning (nn,mm)). Might throw |
| 47 | * parse_exception. */ |
| 48 | boost::tuple<db::group::number, db::group::number> |
| 49 | parse_range(std::string) throw (parse_exception); |
| 50 | |
| 51 | /** Returns true if s is empty or consists entirely of ws |
| 52 | * characters. */ |
| 53 | inline bool is_ws_empty(std::string s, const char *ws = " \t\r\n") { |
| 54 | return s.find_first_not_of(ws) == std::string::npos; |
| 55 | } |
| 56 | |
| 57 | /** Returns true if c is an ASCII letter (note: locale has no |
| 58 | * effect). */ |
| 59 | inline bool is_alpha(char c) |
| 60 | { |
| 61 | return ('a' <= c && c <= 'z') || |
| 62 | ('A' <= c && c <= 'Z'); |
| 63 | } |
| 64 | |
| 65 | /** Returns true if c is a RFC 3977 <wildmat-exact> character. */ |
| 66 | inline bool is_wildmat_exact(char c) |
| 67 | { |
| 68 | return (0x22 <= c && c <= 0x29) || |
| 69 | c == 0x2b || |
| 70 | (0x2d <= c && c <= 0x3e) || |
| 71 | (0x40 <= c && c <= 0x5a) || |
| 72 | (0x5e <= c && c <= 0x7e) || |
| 73 | (unsigned char)(c) > 0x80; |
| 74 | } |
| 75 | |
| 76 | } |
| 77 | #endif /* GUARD_NNTP_LEXUTILS_HH */ |
Note: See TracBrowser
for help on using the browser.
