-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegexUtils.cpp
More file actions
55 lines (47 loc) · 1.24 KB
/
RegexUtils.cpp
File metadata and controls
55 lines (47 loc) · 1.24 KB
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
/* RegexUtils.cpp
* Contains useful functions for dealing with string parsing.
* Author: Adam Waggoner, Jaden Holladay, Logan Ropelato, Gray Marchese
*/
#include "RegexUtils.h"
#include <string>
#include <boost/regex.hpp>
#include <sstream>
using namespace std;
bool RegexUtils::RegexFind(const std::string val, const std::string pattern, boost::smatch & out)
{
boost::regex expr(pattern);
boost::smatch matches;
if (boost::regex_search(val, matches, expr))
{
out = matches;
return true;
}
return false;
}
// Validates that a file name is legal
bool RegexUtils::IsValidFilename(const std::string name)
{
if(name.size() > 255)
return false;
boost::regex expr("^[\\w\\- ]+$");
boost::smatch dummy;
return boost::regex_search(name, dummy, expr);
}
// Returns true if string can be parsed as an integer.
bool RegexUtils::IsInt(std::string val)
{
int dummyval;
return sscanf(val.c_str(), "%d", &dummyval);
}
// Citation: Code from http://stackoverflow.com/questions/236129/split-a-string-in-c
std::vector<std::string> RegexUtils::Split(std::string inp, char delimiter)
{
stringstream ss(inp);
string item;
vector<string> tokens;
while (getline(ss, item, delimiter))
{
tokens.push_back(item);
}
return tokens;
}