-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlowCParser.h
More file actions
117 lines (95 loc) · 3.37 KB
/
FlowCParser.h
File metadata and controls
117 lines (95 loc) · 3.37 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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#pragma once
#include <string>
#include <array>
#include <vector>
#include <cstring>
namespace FlowCParser {
using namespace std;
inline string goToNextLine(unsigned char *&text) {
unsigned char *start = text;
size_t pos = 0;
if (text[pos] == '\n' || (text[pos] == '\r' && text[++pos] == '\n'))
++pos;
text = text + pos;
return string(text, text + pos);
}
inline bool isEmpty(unsigned char *&text){
return text == nullptr || *text == '\0';
}
inline string returnString(unsigned char *&start, unsigned char *&endP) {
if (isEmpty(endP))
return string((char *) start);
return string(start, endP);
}
inline string goToNewLine(unsigned char *&text) {
unsigned char *start = text;
text = (unsigned char*) strpbrk((char*)text, "\n\r");
return returnString(start, text);
}
inline string goTo(unsigned char *&text, char c) {
unsigned char *start = text;
text = (unsigned char*) strchr((char*)text, c);
return returnString(start, text);
}
inline string goTo(unsigned char *&text,const string& str) {
unsigned char *start = text;
text = (unsigned char*) strstr((char*)text, str.c_str());
return returnString(start, text);
}
inline vector<char> returnVector(unsigned char *&start, unsigned char *&endP) {
if (isEmpty(endP))
return vector<char> (start, start + strlen((char*)start));
return vector<char>(start, endP);
}
inline vector<char> goToV(unsigned char *&text,const string& str) {
unsigned char *start = text;
text = (unsigned char*) strstr((char*)text, str.c_str());
return returnVector(start, text);
}
inline string gotoNextNonWhite(unsigned char *&text) {
unsigned char *start = text;
while (*text++ != '\0') {
if (!isblank(*text))
break;
}
return returnString(start, text);
}
inline string gotoNextNonAlpha(unsigned char *&text) {
unsigned char *start = text;
text = (unsigned char*) strpbrk((char*)text, " \n\r");
return returnString(start, text);
}
inline string goToOne(unsigned char *&text, const string &goToOne) {
unsigned char *start = text;
text = (unsigned char*) strpbrk((char*)text, goToOne.c_str());
return returnString(start, text);
}
inline bool isDoubleNewLine(unsigned char *&text) {
return (*text == '\n' && *(++text) == '\n') ||
(*text == '\r' && *(++text) == '\n' && *(++text) == '\r' && *(++text) == '\n');
}
inline string goToEnd(unsigned char *&text) {
return string((char*)text);
}
inline string between(unsigned char *&text, const char startChar, const char endChar) {
char *posStart = strchr((char*)text, startChar);
if (posStart == nullptr)
return "";
char *posEnd = strchr(posStart + 1, endChar);
if (posEnd == nullptr)
return "";
return string(posStart, posEnd);
}
inline vector<char>::iterator findLastData(vector<char> &data) {
auto rtn = data.end() - 1;
if(*rtn == '-')
--rtn;
if(*rtn == '-')
--rtn;
if(*rtn == '\n')
--rtn;
if(*rtn == '\r')
--rtn;
return rtn;
}
};