forked from shashankkumar/CodeRunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContentParser.cpp
executable file
·63 lines (50 loc) · 1.46 KB
/
ContentParser.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "includeh.h"
#include "ContentParser.h"
int ContentParser::FetchFileInfoList(FileInfoFetchOptionsStruct* FileInfoFetchOptions){
CurlWrapper *CurlVar = new CurlWrapper();
string strContent;
if(CurlVar->FetchContentFromWebPage(FileInfoFetchOptions, &strContent) == -1) {
delete CurlVar; //Clean up
return -1;
}
delete CurlVar;
FileInfoListStr = new char[strContent.size() + 1];
FileInfo = new FileInfoStruct();
strcpy(FileInfoListStr, strContent.c_str());
Ix = 0;
return 0;
}
char ContentParser::read_char() {
return FileInfoListStr[ Ix++ ];
}
int ContentParser::read_int(){
char c; int ret;
while( !isdigit( c = read_char() ) );
ret = c - '0';
while( isdigit( c = read_char() ) )
ret = ( ret * 10 + c - '0' );
return ret;
}
void ContentParser::read_char_str(char * ret){
int i;
for(i=0;i<10 && isalnum(FileInfoListStr[Ix]) ;Ix++, i++){
ret[i] = FileInfoListStr[Ix];
}
ret[i]='\0';
}
bool ContentParser::EndOfContent(){
while(true){
if(isdigit(FileInfoListStr[Ix])) return false;
else if(FileInfoListStr[Ix] == '\0') return true;
Ix++;
}
}
FileInfoStruct* ContentParser::GetNextFileInfo(){
FileInfo->FileId = read_int();
read_char_str(FileInfo->ProblemId);
FileInfo->TimeLimit = read_int();
FileInfo->MemoryLimit = read_int();
read_char_str(FileInfo->lang);
//printf("%d %s %d %d %s\n", FileInfo.FileId, FileInfo.ProblemId, FileInfo.TimeLimit, FileInfo.MemoryLimit, FileInfo.lang);
return FileInfo;
}