forked from czarny247/kurs_cpp_lato_2019
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
124 lines (108 loc) · 2.9 KB
/
main.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <string>
#include <iostream>
enum class fileTypes
{
Json,
Xml,
Html,
JsonInZip,
XmlInZip,
HtmlInZip,
};
fileTypes get_file_type(std::string path)
{
if(path.size() < 5)
throw std::runtime_error("Wrong file name");
if(path.back() == 'l')
{
if(path.rfind('.') == (path.size() - 4))
return fileTypes::Xml;
return fileTypes::Html;
} else if(path.back() == 'p') {
path = path.substr(0, path.size() - 4);
if(path.back() == 'l')
{
if(path.rfind('.') == (path.size() - 4))
return fileTypes::XmlInZip;
return fileTypes::HtmlInZip;
}
return fileTypes::JsonInZip;
}
return fileTypes::Json;
}
std::string load_json(std::string path)
{
return "json data from " + path;
}
std::string load_xml(std::string path)
{
return "xml data from " + path;
}
std::string load_html(std::string path)
{
return "html data from " + path;
}
std::string load_json_in_zip(std::string path)
{
std::string result = "unziped";
path = path.substr(0, path.size() - 4);
return result + " " + "json data from " + path;
}
std::string load_xml_in_zip(std::string path)
{
std::string result = "unziped";
path = path.substr(0, path.size() - 4);
return result + " " + "xml data from " + path;
}
std::string load_html_in_zip(std::string path)
{
std::string result = "unziped";
path = path.substr(0, path.size() - 4);
return result + " " + "html data from " + path;
}
void load_data()
{
std::string path;
std::cout << "Enter file name: ";
std::cin >> path;
try {
if(get_file_type(path) == fileTypes::Json)
std::cout << load_json(path) << std::endl;
} catch (const std::exception& ex) {
std::cout << ex.what() << std::endl;
}
try {
if(get_file_type(path) == fileTypes::Xml)
std::cout << load_xml(path) << std::endl;
} catch (const std::exception& ex) {
std::cout << ex.what() << std::endl;
}
try {
if(get_file_type(path) == fileTypes::Html)
std::cout << load_html(path) << std::endl;
} catch (const std::exception& ex) {
std::cout << ex.what() << std::endl;
}
try {
if(get_file_type(path) == fileTypes::JsonInZip)
std::cout << load_json_in_zip(path) << std::endl;
} catch (const std::exception& ex) {
std::cout << ex.what() << std::endl;
}
try {
if(get_file_type(path) == fileTypes::XmlInZip)
std::cout << load_xml_in_zip(path) << std::endl;
} catch (const std::exception& ex) {
std::cout << ex.what() << std::endl;
}
try {
if(get_file_type(path) == fileTypes::HtmlInZip)
std::cout << load_html_in_zip(path) << std::endl;
} catch (const std::exception& ex) {
std::cout << ex.what() << std::endl;
}
}
int main()
{
load_data();
}