From 344e77d8bf1369441c12118954f1ed2a5620749e Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 20 May 2019 10:44:27 +0200 Subject: [PATCH] Replace more characters for tag-anchors. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Asciidoctor doesn't like ₀-₉ and ⁰-⁹. --- CMakeLists.txt | 2 +- src/adoc.cpp | 31 +++++++++++++++++++++++++++---- src/export.hpp | 4 ++-- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 671f525..24c7454 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.2) project(remwharead - VERSION 0.2.1 + VERSION 0.2.2 LANGUAGES CXX ) diff --git a/src/adoc.cpp b/src/adoc.cpp index f193cb8..a3ce442 100644 --- a/src/adoc.cpp +++ b/src/adoc.cpp @@ -95,7 +95,7 @@ void export_adoc(const vector &entries, ostream &out) alltags.insert({ tag, { entry } }); } - out << "xref:" << replace_spaces(tag) << "[" << tag << ']'; + out << "xref:" << replace_in_tags(tag) << "[" << tag << ']'; if (tag != *(entry.tags.rbegin())) { out << ", "; @@ -143,7 +143,7 @@ void export_adoc(const vector &entries, ostream &out) for (const auto &tag : sortedtags) { - out << "=== [[" << replace_spaces(tag.first) << "]]" + out << "=== [[" << replace_in_tags(tag.first) << "]]" << tag.first << endl; for (const Database::entry &entry : tag.second) { @@ -161,7 +161,30 @@ void export_adoc(const vector &entries, ostream &out) } } -const string replace_spaces(const string &text) +const string replace_in_tags(string text) { - return regex_replace(text, regex(" "), "-"); + // TODO: Find a better solution. + const std::map searchreplace = + { + { " ", "-" }, + { "₀", "0" }, { "⁰", "0" }, + { "₁", "1" }, { "¹", "1" }, + { "₂", "2" }, { "²", "2" }, + { "₃", "3" }, { "³", "3" }, + { "₄", "4" }, { "⁴", "4" }, + { "₅", "5" }, { "⁵", "5" }, + { "₆", "6" }, { "⁶", "6" }, + { "₇", "7" }, { "⁷", "7" }, + { "₈", "8" }, { "⁸", "8" }, + { "₉", "9" }, { "⁹", "9" } + }; + for (const std::pair &sr : searchreplace) + { + size_t pos = 0; + while ((pos = text.find(sr.first, pos)) != std::string::npos) + { + text.replace(pos, sr.first.length(), sr.second); + } + } + return text; } diff --git a/src/export.hpp b/src/export.hpp index 3e4e253..c7547a2 100644 --- a/src/export.hpp +++ b/src/export.hpp @@ -30,7 +30,7 @@ void export_csv(const vector &entries, ostream &out = cout); const string quote_csv(const string &field); void export_adoc(const vector &entries, ostream &out = cout); -//! Replaces spaces with -. -const string replace_spaces(const string &text); +//! Replaces characters in tags that asciidoctor doesn't like. +const string replace_in_tags(string text); #endif // REMWHAREAD_EXPORT_HPP