mirror of
https://github.com/kiwix/libkiwix.git
synced 2025-06-27 21:39:37 +00:00
Move back used helper functions to the public API.
- Add docstring - Move the declaration in kiwix namespace. - Adapt our include to include the right headers.
This commit is contained in:
@ -6,10 +6,10 @@
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <tools/otherTools.h>
|
||||
#include <tools/pathTools.h>
|
||||
#include <tools/stringTools.h>
|
||||
#include <downloader.h> // For AriaError
|
||||
#include "tools.h"
|
||||
#include "tools/pathTools.h"
|
||||
#include "tools/stringTools.h"
|
||||
#include "downloader.h" // For AriaError
|
||||
|
||||
#ifdef _WIN32
|
||||
# define ARIA2_CMD "aria2c.exe"
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "book.h"
|
||||
#include "reader.h"
|
||||
|
||||
#include "tools.h"
|
||||
#include "tools/base64.h"
|
||||
#include "tools/regexTools.h"
|
||||
#include "tools/networkTools.h"
|
||||
|
@ -9,6 +9,7 @@
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "tools.h"
|
||||
#include "tools/pathTools.h"
|
||||
#include "tools/stringTools.h"
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "reader.h"
|
||||
#include "libxml_dumper.h"
|
||||
|
||||
#include "tools.h"
|
||||
#include "tools/base64.h"
|
||||
#include "tools/regexTools.h"
|
||||
#include "tools/pathTools.h"
|
||||
|
@ -20,10 +20,10 @@
|
||||
#include "libxml_dumper.h"
|
||||
#include "book.h"
|
||||
|
||||
#include "tools.h"
|
||||
#include "tools/base64.h"
|
||||
#include "tools/stringTools.h"
|
||||
#include "tools/otherTools.h"
|
||||
#include "tools/pathTools.h"
|
||||
|
||||
namespace kiwix
|
||||
{
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "manager.h"
|
||||
|
||||
#include "tools.h"
|
||||
#include "tools/pathTools.h"
|
||||
|
||||
#include <pugixml.hpp>
|
||||
|
@ -24,8 +24,8 @@
|
||||
#include <zim/item.h>
|
||||
#include <zim/error.h>
|
||||
|
||||
#include "tools.h"
|
||||
#include "tools/stringTools.h"
|
||||
#include "tools/pathTools.h"
|
||||
#include "tools/otherTools.h"
|
||||
#include "tools/archiveTools.h"
|
||||
|
||||
|
@ -43,7 +43,7 @@ extern "C" {
|
||||
#include "microhttpd_wrapper.h"
|
||||
}
|
||||
|
||||
#include "tools/otherTools.h"
|
||||
#include "tools.h"
|
||||
#include "tools/pathTools.h"
|
||||
#include "tools/regexTools.h"
|
||||
#include "tools/stringTools.h"
|
||||
|
@ -18,6 +18,8 @@
|
||||
*/
|
||||
|
||||
#include "archiveTools.h"
|
||||
|
||||
#include "tools.h"
|
||||
#include "pathTools.h"
|
||||
#include "otherTools.h"
|
||||
#include "stringTools.h"
|
||||
|
@ -17,7 +17,11 @@
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
// Implement function declared in tools.h and tools/otherTools.h
|
||||
#include "tools.h"
|
||||
#include "tools/otherTools.h"
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
|
||||
|
@ -32,9 +32,7 @@ namespace pugi {
|
||||
|
||||
namespace kiwix
|
||||
{
|
||||
void sleep(unsigned int milliseconds);
|
||||
std::string nodeToString(const pugi::xml_node& node);
|
||||
std::string converta2toa3(const std::string& a2code);
|
||||
|
||||
/*
|
||||
* Convert all format tag string to new format
|
||||
|
@ -17,7 +17,10 @@
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
// Implement method defined in <kiwix/tools.h> and "tools/pathTools.h"
|
||||
#include "tools.h"
|
||||
#include "tools/pathTools.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#ifdef __APPLE__
|
||||
@ -59,7 +62,6 @@
|
||||
#define PATH_MAX 1024
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
std::string WideToUtf8(const std::wstring& wstr)
|
||||
{
|
||||
@ -78,7 +80,7 @@ std::wstring Utf8ToWide(const std::string& str)
|
||||
}
|
||||
#endif
|
||||
|
||||
bool isRelativePath(const std::string& path)
|
||||
bool kiwix::isRelativePath(const std::string& path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (path.size() < 3 ) {
|
||||
@ -173,7 +175,7 @@ std::vector<std::string> normalizeParts(std::vector<std::string>& parts, bool ab
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string computeRelativePath(const std::string& path, const std::string& absolutePath)
|
||||
std::string kiwix::computeRelativePath(const std::string& path, const std::string& absolutePath)
|
||||
{
|
||||
auto parts = kiwix::split(path, SEPARATOR, false);
|
||||
auto pathParts = normalizeParts(parts, false);
|
||||
@ -198,11 +200,11 @@ std::string computeRelativePath(const std::string& path, const std::string& abso
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string computeAbsolutePath(const std::string& path, const std::string& relativePath)
|
||||
std::string kiwix::computeAbsolutePath(const std::string& path, const std::string& relativePath)
|
||||
{
|
||||
std::string absolutePath = path;
|
||||
if (path.empty()) {
|
||||
absolutePath = getCurrentDirectory();
|
||||
absolutePath = kiwix::getCurrentDirectory();
|
||||
}
|
||||
|
||||
auto parts = kiwix::split(absolutePath, SEPARATOR, false);
|
||||
@ -215,7 +217,7 @@ std::string computeAbsolutePath(const std::string& path, const std::string& rela
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string removeLastPathElement(const std::string& path)
|
||||
std::string kiwix::removeLastPathElement(const std::string& path)
|
||||
{
|
||||
auto parts_ = kiwix::split(path, SEPARATOR, false);
|
||||
auto parts = normalizeParts(parts_, false);
|
||||
@ -226,7 +228,7 @@ std::string removeLastPathElement(const std::string& path)
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string appendToDirectory(const std::string& directoryPath, const std::string& filename)
|
||||
std::string kiwix::appendToDirectory(const std::string& directoryPath, const std::string& filename)
|
||||
{
|
||||
std::string newPath = directoryPath;
|
||||
if (!directoryPath.empty() && directoryPath.back() != SEPARATOR[0]) {
|
||||
@ -236,7 +238,7 @@ std::string appendToDirectory(const std::string& directoryPath, const std::strin
|
||||
return newPath;
|
||||
}
|
||||
|
||||
std::string getLastPathElement(const std::string& path)
|
||||
std::string kiwix::getLastPathElement(const std::string& path)
|
||||
{
|
||||
auto parts_ = kiwix::split(path, SEPARATOR);
|
||||
auto parts = normalizeParts(parts_, false);
|
||||
@ -366,7 +368,7 @@ bool copyFile(const std::string& sourcePath, const std::string& destPath)
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string getExecutablePath(bool realPathOnly)
|
||||
std::string kiwix::getExecutablePath(bool realPathOnly)
|
||||
{
|
||||
if (!realPathOnly) {
|
||||
char* cAppImage = ::getenv("APPIMAGE");
|
||||
@ -420,7 +422,7 @@ bool writeTextFile(const std::string& path, const std::string& content)
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string getCurrentDirectory()
|
||||
std::string kiwix::getCurrentDirectory()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
wchar_t* a_cwd = _wgetcwd(NULL, 0);
|
||||
@ -434,7 +436,7 @@ std::string getCurrentDirectory()
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string getDataDirectory()
|
||||
std::string kiwix::getDataDirectory()
|
||||
{
|
||||
// Try to get the dataDir from the `KIWIX_DATA_DIR` env var
|
||||
#ifdef _WIN32
|
||||
@ -524,4 +526,3 @@ std::string getMimeTypeForFile(const std::string& filename)
|
||||
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
|
@ -26,11 +26,6 @@
|
||||
std::string WideToUtf8(const std::wstring& wstr);
|
||||
std::wstring Utf8ToWide(const std::string& str);
|
||||
#endif
|
||||
bool isRelativePath(const std::string& path);
|
||||
std::string computeAbsolutePath(const std::string& path, const std::string& relativePath);
|
||||
std::string computeRelativePath(const std::string& path, const std::string& absolutePath);
|
||||
std::string removeLastPathElement(const std::string& path);
|
||||
std::string appendToDirectory(const std::string& directoryPath, const std::string& filename);
|
||||
|
||||
unsigned int getFileSize(const std::string& path);
|
||||
std::string getFileSizeAsString(const std::string& path);
|
||||
@ -39,10 +34,8 @@ bool fileExists(const std::string& path);
|
||||
bool makeDirectory(const std::string& path);
|
||||
std::string makeTmpDirectory();
|
||||
bool copyFile(const std::string& sourcePath, const std::string& destPath);
|
||||
std::string getLastPathElement(const std::string& path);
|
||||
std::string getExecutablePath(bool realPathOnly = false);
|
||||
std::string getCurrentDirectory();
|
||||
std::string getDataDirectory();
|
||||
bool writeTextFile(const std::string& path, const std::string& content);
|
||||
std::string getMimeTypeForFile(const std::string& filename);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -17,9 +17,11 @@
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <tools/stringTools.h>
|
||||
// Implement function declared in tools.h and tools/stringTools.h
|
||||
#include "tools.h"
|
||||
#include "tools/stringTools.h"
|
||||
|
||||
#include <tools/pathTools.h>
|
||||
#include "tools/pathTools.h"
|
||||
#include <unicode/normlzr.h>
|
||||
#include <unicode/rep.h>
|
||||
#include <unicode/translit.h>
|
||||
|
@ -43,7 +43,6 @@ void loadICUExternalTables();
|
||||
std::string urlEncode(const std::string& value, bool encodeReserved = false);
|
||||
std::string urlDecode(const std::string& value, bool component = false);
|
||||
|
||||
std::vector<std::string> split(const std::string& str, const std::string& delims, bool trimEmpty = true, bool keepDelim = false);
|
||||
std::string join(const std::vector<std::string>& list, const std::string& sep);
|
||||
|
||||
std::string ucAll(const std::string& word);
|
||||
|
Reference in New Issue
Block a user