Loading...
Searching...
No Matches
ml::FileReader Class Reference

Read text or JSON data from a file. More...

#include <Malena/Utilities/FileReader.h>

Static Public Member Functions

static std::optional< jsonreadJson (const std::string &path)
 Parse a JSON file.
static std::optional< std::string > readText (const std::string &path)
 Read the entire contents of a file as a string.

Detailed Description

Read text or JSON data from a file.

Usage

// Read JSON
auto data = ml::FileReader::readJson(path);
if (data) {
std::string title = (*data)["title"];
}
// Read plain text
auto text = ml::FileReader::readText(path);
if (text) { ... }
static std::optional< std::string > readText(const std::string &path)
Read the entire contents of a file as a string.
static std::optional< json > readJson(const std::string &path)
Parse a JSON file.

Definition at line 29 of file FileReader.h.

Member Function Documentation

◆ readJson()

std::optional< json > ml::FileReader::readJson ( const std::string & path)
static

Parse a JSON file.

Returns
The parsed ml::json, or std::nullopt if the file could not be opened or contains invalid JSON.

◆ readText()

std::optional< std::string > ml::FileReader::readText ( const std::string & path)
static

Read the entire contents of a file as a string.

Returns
The file contents, or std::nullopt if the file could not be opened.

The documentation for this class was generated from the following file: