-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchBook.cpp
71 lines (65 loc) · 1.71 KB
/
SearchBook.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
#include "SearchBook.h"
#include<bits/stdc++.h>
#include "myLibType.h"
#include<Qstring>
using namespace std;
extern vector<Book> books;
extern vector<Book> view_now;
bool Lib::Judgement(unsigned char c)
{
if(c>0x80)
return true;
else
return false;
}
bool Lib::comparison(wstring sentence1,wstring sentence2)
{
int a=-1;
bool compare=0;
if(sentence1.empty()) return true;
else
{
for(auto wc:sentence1)
{
a=sentence2.find(wc);
if(a!=-1)
{
compare=1;
break;
}
}
return compare;
}
}
vector<Book> Lib::findbook(wstring name,wstring author,wstring publisher,wstring categoryNumber)
{
vector<Book> findbooks;
int i=0;
int k=0;
for(i=0;i<books.size();i++)
{
if(Lib::comparison(name,Lib::String2Wstring(books[i].name))==true) k++;
if(Lib::comparison(author,Lib::String2Wstring(books[i].author))==true) k++;
if(Lib::comparison(publisher,Lib::String2Wstring(books[i].publisher))==true) k++;
if(Lib::comparison(categoryNumber,Lib::String2Wstring(books[i].categoryNumber))==true) k++;
if(k==4)
{
findbooks.push_back(books[i]);
k=0;
}
else k=0;
}
view_now=findbooks;
return view_now;
}
std::wstring Lib::String2Wstring(std::string str)
{
QString qs=QString::fromStdString(str);
std::wstring res=qs.toStdWString();
return res;
}
std::string Lib::Wstring2String(std::wstring wstr){
QString qs=QString::fromStdWString(wstr);
std::string res=qs.toStdString();
return res;
}