mirror of https://github.com/kiwix/libkiwix.git
Merge pull request #442 from kiwix/better-taskbar-insertion
Better taskbar insertion
This commit is contained in:
commit
e0bcafd89a
|
@ -29,5 +29,8 @@ std::string replaceRegex(const std::string& content,
|
||||||
std::string appendToFirstOccurence(const std::string& content,
|
std::string appendToFirstOccurence(const std::string& content,
|
||||||
const std::string& regex,
|
const std::string& regex,
|
||||||
const std::string& replacement);
|
const std::string& replacement);
|
||||||
|
std::string prependToFirstOccurence(const std::string& content,
|
||||||
|
const std::string& regex,
|
||||||
|
const std::string& replacement);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,5 +1,21 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019 Matthieu Gautier <mgautier@kymeria.fr>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "response.h"
|
#include "response.h"
|
||||||
#include "request_context.h"
|
#include "request_context.h"
|
||||||
|
@ -187,9 +203,9 @@ void ContentResponse::introduce_taskbar()
|
||||||
data.set("title", m_bookTitle);
|
data.set("title", m_bookTitle);
|
||||||
data.set("withlibrarybutton", m_withLibraryButton);
|
data.set("withlibrarybutton", m_withLibraryButton);
|
||||||
auto head_content = render_template(RESOURCE::templates::head_part_html, data);
|
auto head_content = render_template(RESOURCE::templates::head_part_html, data);
|
||||||
m_content = appendToFirstOccurence(
|
m_content = prependToFirstOccurence(
|
||||||
m_content,
|
m_content,
|
||||||
"<head[^>]*>",
|
"</head[ \\t]*>",
|
||||||
head_content);
|
head_content);
|
||||||
|
|
||||||
auto taskbar_part = render_template(RESOURCE::templates::taskbar_part_html, data);
|
auto taskbar_part = render_template(RESOURCE::templates::taskbar_part_html, data);
|
||||||
|
|
|
@ -95,3 +95,22 @@ std::string appendToFirstOccurence(const std::string& content,
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string prependToFirstOccurence(const std::string& content,
|
||||||
|
const std::string& regex,
|
||||||
|
const std::string& replacement)
|
||||||
|
{
|
||||||
|
ucnv_setDefaultName("UTF-8");
|
||||||
|
icu::UnicodeString ucontent(content.c_str());
|
||||||
|
icu::UnicodeString ureplacement(replacement.c_str());
|
||||||
|
auto matcher = buildMatcher(regex, ucontent);
|
||||||
|
if (matcher->find()) {
|
||||||
|
UErrorCode status = U_ZERO_ERROR;
|
||||||
|
ucontent.insert(matcher->start(status), ureplacement);
|
||||||
|
std::string tmp;
|
||||||
|
ucontent.toUTF8String(tmp);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue