From 723497b7a0ee9d5c0865f52fc08a2cc88a6df979 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sat, 6 Aug 2016 12:27:58 +0200 Subject: [PATCH] Forgotten files in windows path insensitivity commit --- src/common/utf8fn.cpp | 24 ++++++++++++++++++++++++ src/common/utf8fn.h | 16 ++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/common/utf8fn.cpp create mode 100644 src/common/utf8fn.h diff --git a/src/common/utf8fn.cpp b/src/common/utf8fn.cpp new file mode 100644 index 00000000..e427f27c --- /dev/null +++ b/src/common/utf8fn.cpp @@ -0,0 +1,24 @@ +#include "utf8fn.h" +#include "rclconfig.h" +#include "transcode.h" +#include "log.h" + +using namespace std; + +string compute_utf8fn(const RclConfig *config, const string& ifn, bool simple) +{ + string charset = config->getDefCharset(true); + string utf8fn; + int ercnt; + string lfn(simple ? path_getsimple(ifn) : ifn); + if (!transcode(lfn, utf8fn, charset, "UTF-8", &ercnt)) { + LOGERR("compute_utf8fn: fn transcode failure from [" << charset << + "] to UTF-8 for: [" << lfn << "]\n"); + } else if (ercnt) { + LOGDEB("compute_utf8fn: " << ercnt << " transcode errors from [" << + charset << "] to UTF-8 for: [" << lfn << "]\n"); + } + LOGDEB1("compute_utf8fn: transcoded from [" << lfn << "] to [" << + utf8fn << "] (" << charset << "->" << "UTF-8)\n"); + return utf8fn; +} diff --git a/src/common/utf8fn.h b/src/common/utf8fn.h new file mode 100644 index 00000000..c4f70814 --- /dev/null +++ b/src/common/utf8fn.h @@ -0,0 +1,16 @@ +#ifndef _UTF8FN_H_ +#define _UTF8FN_H_ + +#include + +class RclConfig; + +// Translate file name/path to utf8 for indexing. +// +// @param simple If true we extract and process only the simple file name +// (ignore the path) +std::string compute_utf8fn(const RclConfig *config, const std::string& ifn, + bool simple); + +#endif // _UTF8FN_H_ +