-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtil.cpp
90 lines (85 loc) · 1.7 KB
/
Util.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
#include "Util.h"
#include <stdio.h>
#include <fstream>
#include <iostream>
#include "Log.h"
NSP_UTIL_BEG
NSP_IO_BEG
bool strsep(vector<string> &vec, string &s)
{
size_t begin = 0;
vec.clear();
while (begin < s.length())
{
size_t end = begin + (s.substr(begin)).find_first_of(' ');
if ((end >= begin) && (end != 0))
{
vec.push_back(s.substr(begin, end - begin));
}
else
{
vec.push_back(s.substr(begin));
break;
}
begin = end + 1;
}
return true;
}
bool strsep(vector<string> &vec, string &s, char c)
{
unsigned int begin = 0;
unsigned int end = 0;
vec.clear();
while (begin < s.size())
{
if (s.substr(begin).find_first_of(c) <= s.substr(begin).size())
end = begin + (s.substr(begin).find_first_of(c));
if ((end >= begin) && (end != 0))
{
vec.push_back(s.substr(begin, end - begin));
}
else
{
vec.push_back(s.substr(begin));
break;
}
begin = end + 1;
}
return true;
}
//Speichern
bool save(vector<string> &vec, string filename)
{
unsigned int i = 0;
ofstream Save(filename.c_str());
while (Save.good() && (i < vec.size()));
{
Save << vec[i++] << "\n";
}
Save.close();
vec.clear();
return true;
//Fehler abfangen???
}
bool save(vector<char>&vec, string filename)
{
ofstream Save(filename.c_str(), ios::binary | ios::trunc);
if (Save.good())
{
Save.write(vec.data(), vec.size()); //Datei schreiben
vec.clear();
}
if (Save.good())
{
Save.close();
return true;
}
else
{
LOG << "IO Thread " << "Fehler beim Schreiben der Datei " + filename << "\n";
Save.close();
return false;
}
}
};
};