int32_t ejson::internal::Value::countWhiteChar(const std::string& _data, size_t _pos, ejson::FilePos& _filePos) const { _filePos.clear(); size_t white=0; for (size_t iii=_pos; iii<_data.size(); iii++) { _filePos.check(_data[iii]); if(true == isWhiteChar(_data[iii])) { white++; } else { break; } } --_filePos; return white; }
// returns false if there are no more characters to read, true otherwise void ConfFile::skipWhiteCharactersExpectNoEolNoEof(byte& statusRes) {// skip all white characters (except EOL), positions on the first non-white character. Expect no EOL or EOF! initStatus(); int skippedChars = 0; while (_confFile.available()) { char c = _confFile.peek(); if (c == 0x0A || c == 0x0D) { logDebug("unexpected EOL"); returnStatus(ERR(0x22)); // unexpected EOL } else { if (!isWhiteChar(c)) { return; } } _confFile.read(); skippedChars++; } logDebug("unexpected EOF"); returnStatus(ERR(0x22));//unexpected EOF }
// returns false if there are no more characters to read, true otherwise boolean ConfFile::skipWhiteCharacters(byte& statusRes) {// skip all white characters (including EOL), positions on the first non-white character initStatus(); int skippedChars = 0; while (_confFile.available()) { char c = _confFile.peek(); if (c == 0x0A) { // Linux EOL, also a white char, so skip it } else if (c == 0x0D) { // Windows EOL, two chars _confFile.read(); skippedChars++; if (!_confFile.available() || _confFile.peek() != 0x0A) { logDebug("skipWhiteChars:no 0A after 0D"); returnStatusV(ERR(0x21),false);// no 0A after 0D } } else { if (!isWhiteChar(c)) { return true; } } _confFile.read(); skippedChars++; } return false; }
void ConfFile::readRootConfFile(const char* progId, char* mcuModel, char* filePath, byte& statusRes) { initStatus(); mcuModel[0] = '\0'; filePath[0] = '\0'; byte pos = 0; boolean eol; char c; byte progIdLength = strLength(progId); logDebugD("l:", progIdLength); boolean matchDetected = false; while (!matchDetected && skipToValidData(statusRes)) { // loop for every valid line checkStatus(); // for skipToValidData logDebug("skipped"); // read PROG_ID and match it pos = 0; while(true) { if (!_confFile.available()) { logDebug("readRootConfFile:unexp EOF"); returnStatus(ERR(0x22)); // unexpected EOF } logDebug("avail"); c = readCharSafe(eol, statusRes); checkStatus(); logDebugC("readChar",c); if (eol) { logDebug("readRootConfFile:unexp EOF"); returnStatus(ERR(0x22)); // unexpected EOL } if ((pos >= progIdLength) || (progId[pos] != c) || isWhiteChar(c)) { // if we are above expected progId length, no need to continue this line, or // if char at pos didn't match progId[pos], or // if white char break; } pos++; } logDebugD("step1:",pos); if (pos != progIdLength) { goto _skipLine; } else { matchDetected = true; } logDebugD("step2:",pos); // read MCU_MODEL skipWhiteCharactersExpectNoEolNoEof(statusRes); checkStatus(); pos = 0; while (true) { if (pos >= UtilsAVR::MCU_MODEL_BUFFER_SIZE) {// too long MCU_MODEL in conf file! mcuModel[UtilsAVR::MCU_MODEL_BUFFER_SIZE-1] = '\0'; returnStatus(ERR(0x23)); } if (!_confFile.available()) { logDebug("!EOF"); returnStatus(ERR(0x22)); // unexpected EOF } mcuModel[pos] = readCharSafe(eol, statusRes); checkStatus(); if (eol) { logDebug("!EOL"); returnStatus(ERR(0x22)); // unexpected EOL } if (isWhiteChar(mcuModel[pos])) { mcuModel[pos] = '\0'; break; } pos++; } logDebugD("step3:",pos); // read FILE_PATH skipWhiteCharactersExpectNoEolNoEof(statusRes); checkStatus(); pos = 0; while (true) { if (pos >= Utils::FILE_PATH_BUFFER_SIZE) {// too long FILE_PATH in conf file! filePath[Utils::FILE_PATH_BUFFER_SIZE-1] = '\0'; returnStatus(ERR(0x24)); } if (!_confFile.available()) { logDebug("!EOF"); returnStatus(ERR(0x22)); // unexpected EOF } filePath[pos] = readCharSafe(eol, statusRes); checkStatus(); if (eol || isWhiteChar(filePath[pos])) { filePath[pos] = '\0'; break; } pos++; } logDebugD("step4:",pos); // Skip this line and proceed to next line _skipLine: skipLine(statusRes); checkStatus(); // skip the line, and continue to next one } }