// From the current file location look for the matching key int8_t IniFile::findKey(const char* section, const char* key, char* buffer, int len, char** keyptr, IniFileState &state) const { if (key == NULL || *key == '\0') return errorKeyNotFound; int8_t done = IniFile::readLine(_file, buffer, len, state.readLinePosition); if (done < 0) return done; char *cp = skipWhiteSpace(buffer); if (isCommentChar(*cp)) return (done ? errorKeyNotFound : 0); if (section && *cp == '[') // Stat of a new section return errorKeyNotFound; // Find '=' char *ep = strchr(cp, '='); if (ep != NULL) { *ep = '\0'; // make = be the end of string removeTrailingWhiteSpace(cp); if (_caseSensitive) { if (strcmp(cp, key) == 0) { *keyptr = ep + 1; return 1; } } else { if (strcasecmp(cp, key) == 0) { *keyptr = ep + 1; return 1; } } } return (done ? errorKeyNotFound : 0); }
int8_t IniFile::findSection(const char* section, char* buffer, int len, IniFileState &state) const { if (section == NULL) return errorSectionNotFound; int8_t done = IniFile::readLine(_file, buffer, len, state.readLinePosition); if (done < 0) return done; char *cp = skipWhiteSpace(buffer); if (isCommentChar(*cp)) return (done ? errorSectionNotFound : 0); if (*cp == '[') { // Start of section ++cp; cp = skipWhiteSpace(cp); char *ep = strchr(cp, ']'); if (ep != NULL) { *ep = '\0'; // make ] be end of string removeTrailingWhiteSpace(cp); if (_caseSensitive) { if (strcmp(cp, section) == 0) return 1; } else { if (strcasecmp(cp, section) == 0) return 1; } } } // Not a valid section line return (done ? errorSectionNotFound : 0); }
// From the current file location look for the matching key. If // section is non-NULL don't look in the next section bool IniFile::findKey(const char* section, const char* key, char* buffer, size_t len, char** keyptr, IniFileState &state) const { if (key == NULL || *key == '\0') { _error = errorKeyNotFound; return true; } error_t err = IniFile::readLine(_file, buffer, len, state.readLinePosition); if (err != errorNoError && err != errorEndOfFile) { _error = err; return true; } char *cp = skipWhiteSpace(buffer); // if (isCommentChar(*cp)) // return (done ? errorKeyNotFound : 0); if (isCommentChar(*cp)) { if (err == errorEndOfFile) { _error = errorKeyNotFound; return true; } else return false; // Continue searching } if (section && *cp == '[') { // Start of a new section _error = errorKeyNotFound; return true; } // Find '=' char *ep = strchr(cp, '='); if (ep != NULL) { *ep = '\0'; // make = be the end of string removeTrailingWhiteSpace(cp); if (_caseSensitive) { if (strcmp(cp, key) == 0) { *keyptr = ep + 1; _error = errorNoError; return true; } } else { if (strcasecmp(cp, key) == 0) { *keyptr = ep + 1; _error = errorNoError; return true; } } } // Not the valid key line if (err == errorEndOfFile) { _error = errorKeyNotFound; return true; } return false; }
bool IniFile::findSection(const char* section, char* buffer, size_t len, IniFileState &state) const { if (section == NULL) { _error = errorSectionNotFound; return true; } error_t err = IniFile::readLine(_file, buffer, len, state.readLinePosition); if (err != errorNoError && err != errorEndOfFile) { // Signal to caller to stop looking and any error value _error = err; return true; } char *cp = skipWhiteSpace(buffer); //if (isCommentChar(*cp)) //return (done ? errorSectionNotFound : 0); if (isCommentChar(*cp)) { // return (err == errorEndOfFile ? errorSectionNotFound : errorNoError); if (err == errorEndOfFile) { _error = errorSectionNotFound; return true; } else return false; // Continue searching } if (*cp == '[') { // Start of section ++cp; cp = skipWhiteSpace(cp); char *ep = strchr(cp, ']'); if (ep != NULL) { *ep = '\0'; // make ] be end of string removeTrailingWhiteSpace(cp); if (_caseSensitive) { if (strcmp(cp, section) == 0) { _error = errorNoError; return true; } } else { if (strcasecmp(cp, section) == 0) { _error = errorNoError; return true; } } } } // Not a valid section line //return (done ? errorSectionNotFound : 0); if (err == errorEndOfFile) { _error = errorSectionNotFound; return true; } return false; }