78 lines
1.5 KiB
C++
78 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "File.h"
|
|
|
|
#include <string>
|
|
#include <optional>
|
|
|
|
class MarkdownContentParser
|
|
{
|
|
public:
|
|
|
|
using FileMetadataItem = std::pair<std::string, std::string>;
|
|
using FileMetadata = std::vector<FileMetadataItem>;
|
|
using FileContentBody = std::vector<std::string>;
|
|
|
|
void run(const std::string& path)
|
|
{
|
|
FileMetadata metadata;
|
|
|
|
unsigned metadata_end_loc = 0;
|
|
const auto lines = File(path).readLines();
|
|
for (const auto& line : lines)
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::string getContentBody() const
|
|
{
|
|
return mContentBody;
|
|
}
|
|
|
|
FileMetadata getFileMetadata() const
|
|
{
|
|
return mMetadata;
|
|
}
|
|
|
|
|
|
private:
|
|
|
|
std::optional<FileMetadataItem> checkForMetadataItem(const std::string& line) const
|
|
{
|
|
unsigned char_count = 0;
|
|
std::string prefix;
|
|
std::string suffix;
|
|
bool building_prefix = true;
|
|
for (const auto c : line)
|
|
{
|
|
if (c == ':' && char_count > 0 && building_prefix)
|
|
{
|
|
building_prefix = false;
|
|
}
|
|
else if (building_prefix)
|
|
{
|
|
prefix += c;
|
|
}
|
|
else
|
|
{
|
|
suffix += c;
|
|
}
|
|
char_count ++;
|
|
}
|
|
|
|
if (!prefix.empty() && !suffix.empty())
|
|
{
|
|
return FileMetadataItem{prefix, suffix};
|
|
}
|
|
else
|
|
{
|
|
return std::nullopt;
|
|
}
|
|
}
|
|
|
|
|
|
FileMetadata mMetadata;
|
|
FileContentBody mContentBody;
|
|
};
|