-
Notifications
You must be signed in to change notification settings - Fork 53
/
utils.cpp
40 lines (35 loc) · 820 Bytes
/
utils.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
//
// Created by Ameen Maali on 6/1/20.
//
#include "utils.hpp"
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include "Url.hpp"
bool load_urls_from_file(std::vector<Url> &urls, const std::string &filename, bool regex_mode)
{
std::ifstream file(filename);
if (!file)
{
std::cout << "Unable to open file " << filename << std::endl;
return false;
}
else
{
read_urls_from_stream(urls, file, regex_mode);
return true;
}
}
void read_urls_from_stream(std::vector<Url> &urls, std::istream &is, bool regex_mode)
{
std::string s;
while (getline(is, s))
{
urls.emplace_back(s, regex_mode);
}
}
bool is_number(const std::string &str)
{
return !str.empty() && std::all_of(str.begin(), str.end(), ::isdigit);
}