logic: implemented support for non-ascii characters in fulltext search
* fixed non-ascii characters not working in normal symbol search * implemented support for non-ascii characters in fulltext search * fixed fulltext search not working for symbols with lowest and highest character codes in a file * using wstring in FullTextSearchIndex (causes this index to be dependent on text encoding selected in app settings) * implemented rebuilding FullTextSearchIndex if used text encoding changed in app settings * added utility lib
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
|
||||
add_files(
|
||||
LIB_UTILITY_FILES
|
||||
|
||||
utility/TextCodec.cpp
|
||||
utility/TextCodec.h
|
||||
)
|
||||
@@ -0,0 +1,46 @@
|
||||
#include "utility/TextCodec.h"
|
||||
|
||||
#include <QTextCodec>
|
||||
|
||||
TextCodec::TextCodec(const std::string& name)
|
||||
: m_name(name)
|
||||
{
|
||||
}
|
||||
|
||||
std::string TextCodec::getName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
bool TextCodec::isValid() const
|
||||
{
|
||||
QTextCodec* codec = QTextCodec::codecForName(m_name.c_str());
|
||||
if (codec)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::wstring TextCodec::decode(const std::string& unicodeString) const
|
||||
{
|
||||
QTextCodec* codec = QTextCodec::codecForName(m_name.c_str());
|
||||
if (codec)
|
||||
{
|
||||
QTextDecoder decoder(codec);
|
||||
return decoder.toUnicode(unicodeString.c_str()).toStdWString();
|
||||
}
|
||||
return QString::fromStdString(unicodeString).toStdWString();
|
||||
}
|
||||
|
||||
std::string TextCodec::encode(const std::wstring& string) const
|
||||
{
|
||||
QTextCodec* codec = QTextCodec::codecForName(m_name.c_str());
|
||||
if (codec)
|
||||
{
|
||||
QTextEncoder encoder(codec);
|
||||
return encoder.fromUnicode(QString::fromStdWString(string)).toStdString();
|
||||
}
|
||||
|
||||
return QString::fromStdWString(string).toStdString();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef TEXT_CODEC_H
|
||||
#define TEXT_CODEC_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class TextCodec
|
||||
{
|
||||
public:
|
||||
TextCodec(const std::string& name);
|
||||
|
||||
std::string getName() const;
|
||||
bool isValid() const;
|
||||
|
||||
std::wstring decode(const std::string& unicodeString) const;
|
||||
|
||||
std::string encode(const std::wstring& string) const;
|
||||
|
||||
private:
|
||||
const std::string m_name;
|
||||
};
|
||||
|
||||
#endif // TEXT_CODEC_H
|
||||
Reference in New Issue
Block a user