-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.cpp
43 lines (37 loc) · 895 Bytes
/
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
#include "util.hpp"
#include <vector>
#include <string>
#include <locale>
std::string toupper_string(const std::string& input)
{
std::locale loc;
std::string output;
for (auto c: input)
{
output += std::toupper(c, loc);
}
return output;
}
std::vector<unsigned char> string_to_vec(const std::string& s)
{
return std::vector<unsigned char>(s.begin(), s.end());
}
std::string vec_to_string(const std::vector<unsigned char>& v)
{
return std::string(v.begin(), v.end());
}
void operator+=(std::vector<unsigned char>& v, unsigned char c)
{
v.push_back(c);
}
std::vector<unsigned char> vec_from_file(std::ifstream& in, std::size_t bytes)
{
char c;
std::vector<unsigned char> ret;
for (std::size_t i = 0; i < bytes && in; i++)
{
in.get(c);
ret.push_back(static_cast<unsigned char>(c));
}
return std::move(ret);
}