-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecipe.cpp
More file actions
55 lines (47 loc) · 1.55 KB
/
Recipe.cpp
File metadata and controls
55 lines (47 loc) · 1.55 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
#include "IIKH.h"
#include "trim.h"
#include <deque>
#include <string>
using namespace std;
// Class managing recipe information
Recipe::Recipe(string afterParse[7]) {
menuSize = afterParse[0];
foodName = afterParse[1];
parseIngredient(afterParse[2]); // Parse for search by ingredient
cookingTime = afterParse[3];
parseSteps(afterParse[4]); // Parse for print steps in each line
calorie = afterParse[5];
parseHashtags(afterParse[6]); // Parse for search by hashtag
}
// For parsing string
void Recipe::parseList(const string& input, deque<string>& output, char delimiter) {
size_t startPos = 0;
size_t endPos = 0;
while ((endPos = input.find(delimiter, startPos)) != string::npos) {
string item = input.substr(startPos, endPos - startPos);
item = trim(item);
output.push_back(item);
startPos = endPos + 1;
}
// Final token
if (startPos < input.length()) {
string lastItem = input.substr(startPos);
lastItem = trim(lastItem);
output.push_back(lastItem);
}
}
// Get ingredient information and put in queue
void Recipe::parseIngredient(string& input) {
parseList(input, ingredients, ',');
ingredientIndex = ingredients.size();
}
// Get step information and put in queue
void Recipe::parseSteps(string& input) {
parseList(input, steps, ';');
stepIndex = steps.size();
}
// Get hashtag information and put in queue
void Recipe::parseHashtags(string& input) {
parseList(input, hashtags, ';');
hashtagIndex = hashtags.size();
}