/** * Parses a definition to populate a schedule * @param e SCHEDULE_ENTRY * @param def definition * @return 1 on failure */ int scheduler_parse(SCHEDULE_ENTRY *e, char *def) { // We need to manipulate the string. If def is a hardcoded string in // code then we would segfault if we don't do this char *d = strdup(def); // first word is the minute definition char *ms = findNonWhitespace(d); char *me = findWhitespace(ms); if (!*me) { fprintf(stderr, "Invalid minute definition %s\n", def); return 1; } // second word is the hour definition char *hs = findNonWhitespace(me); char *he = findWhitespace(hs); // Terminate the works *me = '\0'; *he = '\0'; // Parse minute definition int r = parseHour(hs, ms, e); // Free our work string free(d); if (r) fprintf(stderr, "Invalid definition %s\n", def); return r; }
const std::string DataTree::parseKey(const std::string& fileData, const int size, const int start, const int end, int& curIndex) { // Parsing depth is on same level with current dpeth. // Start from index after depth // If starting pos is larger than next line index, skip std::string newKey = std::string(); if (start < end) { // Ignore whitespace after dpeth curIndex = findWhitespace(fileData, start + 1); newKey = fileData.substr(start, curIndex < size ? curIndex - start : std::string::npos); } return newKey; }