-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunhelper.h
35 lines (28 loc) · 1020 Bytes
/
funhelper.h
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
//
// Various common global helper functions
// Created by rthier on 2016.07.15..
//
#ifndef NFTSIMPLEPROJ_HELPERFUN_H
#define NFTSIMPLEPROJ_HELPERFUN_H
#include <string>
#include <algorithm> // std::mismatch
/**
* Returns if the given keyword is a real existing prefix of the given target string.
*/
static bool isStartsWith(const std::string &targetString, const std::string keyword) {
// If the keyword is longer than the read field descriptor line
// then we cannot parse it!
if(keyword.size() > targetString.size()) {
return false;
}
// Otherwise check for the first mismatching character of the keyword string
auto mismatch = std::mismatch(keyword.begin(), keyword.end(),
targetString.begin(), targetString.end());
// It is a prefix if the first mismatch is after the end of the keyword string!
if(mismatch.first == keyword.end()){
return true;
} else {
return false;
}
}
#endif //NFTSIMPLEPROJ_HELPERFUN_H