forked from erengy/taiga
/
anime_filter.cpp
86 lines (71 loc) · 2.51 KB
/
anime_filter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
** Taiga, a lightweight client for MyAnimeList
** Copyright (C) 2010-2012, Eren Okka
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "std.h"
#include "anime_filter.h"
#include "anime_item.h"
#include "string.h"
namespace anime {
// =============================================================================
Filters::Filters() {
Reset();
}
bool Filters::CheckItem(Item& item) {
// Filter my status
for (size_t i = 0; i < my_status.size(); i++)
if (!my_status.at(i) && item.GetMyStatus() == i)
return false;
// Filter airing status
for (size_t i = 0; i < status.size(); i++)
if (!status.at(i) && item.GetAiringStatus() == i + 1)
return false;
// Filter type
for (size_t i = 0; i < type.size(); i++)
if (!type.at(i) && item.GetType() == i + 1)
return false;
// Filter text
vector<wstring> words;
Split(text, L" ", words);
RemoveEmptyStrings(words);
for (auto it = words.begin(); it != words.end(); ++it) {
if (InStr(item.GetTitle(), *it, 0, true) == -1 &&
InStr(item.GetGenres(), *it, 0, true) == -1 &&
InStr(item.GetMyTags(), *it, 0, true) == -1) {
bool found = false;
for (auto synonym = item.GetSynonyms().begin();
!found && synonym != item.GetSynonyms().end(); ++synonym)
if (InStr(*synonym, *it, 0, true) > -1) found = true;
if (item.IsInList())
for (auto synonym = item.GetUserSynonyms().begin();
!found && synonym != item.GetUserSynonyms().end(); ++synonym)
if (InStr(*synonym, *it, 0, true) > -1) found = true;
if (!found) return false;
}
}
// Item passed all filters
return true;
}
void Filters::Reset() {
my_status.clear();
status.clear();
type.clear();
my_status.resize(7, true);
status.resize(3, true);
type.resize(6, true);
text = L"";
}
} // namespace anime