feat: epub bookmarks (#1337)
Co-authored-by: vedi0boy <nate@origin8publishing.com> Co-authored-by: Uri Tauber <uritaube@gmail.com>
This commit is contained in:
co-authored by
vedi0boy
Uri Tauber
parent
bbb3e06eb1
commit
36a3a0cc3a
@@ -0,0 +1,35 @@
|
||||
#include "BookmarkUtil.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
std::string BookmarkUtil::getBookmarksDir() { return "/.crosspoint/bookmarks/"; }
|
||||
|
||||
std::string BookmarkUtil::getBookmarkPath(const std::string& bookPath) {
|
||||
// remove leading slash and replace internal slashes to create a flat filename
|
||||
std::string bookName = std::string(bookPath).erase(0, 1);
|
||||
std::replace(bookName.begin(), bookName.end(), '/', '_');
|
||||
std::replace(bookName.begin(), bookName.end(), '\\', '_');
|
||||
const size_t lastDot = bookName.find_last_of('.');
|
||||
if (lastDot != std::string::npos) {
|
||||
bookName.erase(lastDot);
|
||||
}
|
||||
bookName += ".json";
|
||||
return getBookmarksDir() + bookName;
|
||||
}
|
||||
|
||||
std::string BookmarkUtil::sanitizeBookmarkSummary(std::string summary) {
|
||||
summary.erase(
|
||||
std::unique(summary.begin(), summary.end(), [](char a, char b) { return std::isspace(a) && std::isspace(b); }),
|
||||
summary.end());
|
||||
summary.erase(std::remove(summary.begin(), summary.end(), '\n'), summary.end());
|
||||
summary.erase(summary.begin(),
|
||||
std::find_if(summary.begin(), summary.end(), [](unsigned char ch) { return !std::isspace(ch); }));
|
||||
summary.erase(
|
||||
std::find_if(summary.rbegin(), summary.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(),
|
||||
summary.end());
|
||||
if (summary.size() > 72) {
|
||||
summary.resize(72);
|
||||
}
|
||||
return summary;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
class BookmarkUtil {
|
||||
public:
|
||||
static std::string getBookmarksDir();
|
||||
static std::string getBookmarkPath(const std::string& bookPath);
|
||||
static std::string sanitizeBookmarkSummary(std::string summary);
|
||||
};
|
||||
Reference in New Issue
Block a user