OSDN Git Service

Initial commit. Text view widget is implemented.
[fukui-no-namari/dialektos.git] / src / bbs_detail_2ch.cxx
1 /*
2  * Copyright (C) 2009 by Aiwota Programmer
3  * aiwotaprog@tetteke.tk
4  *
5  * This file is part of Dialektos.
6  *
7  * Dialektos is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * Dialektos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Dialektos.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include "bbs_detail_2ch.hxx"
22
23 #include <boost/filesystem.hpp>
24 #include <boost/xpressive/xpressive.hpp>
25 #include <string>
26 #include <iostream>
27
28 namespace dialektos {
29
30 namespace bbs_detail {
31
32
33 const std::string CH2::bbs_name = "2ch";
34
35 CH2* CH2::judge(const std::string& uri) {
36   if (CH2* bbs = judge_thread(uri)) return bbs;
37   if (CH2* bbs = judge_board(uri)) return bbs;
38   return 0;
39 }
40
41 CH2* CH2::judge_thread(const std::string& uri) {
42   using namespace boost::xpressive;
43
44   sregex regex = "http://" >> (s1=+(_w|'-')) >> ".2ch.net/test/read.cgi/" >> (s2=+_w)
45   >> '/' >> (s3=+_d) >> '/' >> -*(_d|'-');
46
47   smatch what;
48   if (!regex_match(uri, what, regex))
49     return 0;
50
51   const std::string host = what[1];
52   const std::string board = what[2];
53   const std::string thread = what[3];
54
55   return new CH2(uri, host, board, thread);
56 }
57
58 CH2* CH2::judge_board(const std::string& uri) {
59   using namespace boost::xpressive;
60
61   sregex regex = "http://" >> (s1=+(_w|'-')) >> ".2ch.net/" >> (s2=+_w) >> '/' >> -*_w;
62
63   smatch what;
64   if (!regex_match(uri, what, regex))
65     return 0;
66
67   const std::string host = what[1];
68   const std::string board = what[2];
69
70   return new CH2(uri, host, board, "");
71 }
72
73
74 CH2::CH2(const std::string& uri, const std::string& host,
75     const std::string& board, const std::string& thread) :
76       Base(uri, host, board, thread) {}
77
78 CH2::CH2(const CH2& rhs) : Base(rhs) {}
79
80 CH2::~CH2() {}
81
82 CH2* CH2::do_clone(const CH2& rhs) const {
83   return new CH2(rhs);
84 }
85
86 std::string CH2::get_board_dir_path() const {
87   std::string homedir = std::getenv("HOME");
88   boost::filesystem::path dir(homedir);
89   dir = dir / ".dialektos" / "logs" / get_bbs_name() / board_;
90   return dir.file_string();
91 }
92
93
94 const std::string& CH2::get_bbs_name() const {
95   return bbs_name;
96 }
97
98 } // namespace bbs_detail
99
100 } // namespace dialektos