MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / readLines

Function readLines

TactilityCore/Source/file/File.cpp:363–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

361}
362
363bool readLines(const std::string& filePath, bool stripNewLine, std::function<void(const char* line)> callback) {
364 auto lock = getLock(filePath)->asScopedLock();
365 lock.lock();
366
367 auto* file = fopen(filePath.c_str(), "r");
368 if (file == nullptr) {
369 return false;
370 }
371
372 char line[1024];
373
374 while (fgets(line, sizeof(line), file) != nullptr) {
375 // Strip newline
376 if (stripNewLine) {
377 size_t line_length = strlen(line);
378 if (line_length > 0 && line[line_length - 1] == '\n') {
379 line[line_length - 1] = '\0';
380 }
381 }
382 // Publish
383 callback(line);
384 }
385
386 bool success = feof(file);
387 fclose(file);
388 return success;
389}
390
391}

Callers 2

loadMethod · 0.85
loadPropertiesFileFunction · 0.85

Calls 3

getLockFunction · 0.85
asScopedLockMethod · 0.80
lockMethod · 0.45

Tested by

no test coverage detected