docstring const GuiClipboard::getAsText() const
{
// text data from other applications
- QString const str = qApp->clipboard()->text(QClipboard::Clipboard);
+ QString const str = qApp->clipboard()->text(QClipboard::Clipboard)
+ .normalized(QString::NormalizationForm_KC);
LYXERR(Debug::ACTION) << "GuiClipboard::getAsText(): `"
<< fromqstr(str) << "'" << endl;
if (str.isNull())
docstring const GuiSelection::get() const
{
- QString const str = qApp->clipboard()->text(QClipboard::Selection);
+ QString const str = qApp->clipboard()->text(QClipboard::Selection)
+ .normalized(QString::NormalizationForm_KC);
LYXERR(Debug::ACTION) << "GuiSelection::get: " << fromqstr(str)
<< endl;
if (str.isNull())
case LFUN_FILE_INSERT_PLAINTEXT_PARA:
case LFUN_FILE_INSERT_PLAINTEXT: {
// FIXME UNICODE
- string const tmpstr = getContentsOfPlaintextFile(&cur.bv(), to_utf8(cmd.argument()), false);
- // FIXME: We don't know the encoding of the file
- if (!tmpstr.empty() && !insertPlaintextString(cur.bv(), from_utf8(tmpstr), false))
+ docstring const tmpstr = getContentsOfPlaintextFile(&cur.bv(), to_utf8(cmd.argument()), false);
+ if (!tmpstr.empty() && !insertPlaintextString(cur.bv(), tmpstr, false))
cur.undispatched();
break;
}
if (!bv->buffer())
return;
- // FIXME: We don't know the encoding of the file
- docstring const tmpstr = from_utf8(getContentsOfPlaintextFile(bv, f, asParagraph));
+ docstring const tmpstr = getContentsOfPlaintextFile(bv, f, asParagraph);
if (tmpstr.empty())
return;
}
-// Read plain text file (if filename is empty, prompt for one)
-string getContentsOfPlaintextFile(BufferView * bv, string const & f, bool asParagraph)
+docstring const getContentsOfPlaintextFile(BufferView * bv, string const & f,
+ bool asParagraph)
{
FileName fname(f);
FileFilterList(), docstring());
if (result.first == FileDialog::Later)
- return string();
+ return docstring();
fname = makeAbsPath(to_utf8(result.second));
if (fname.empty())
- return string();
+ return docstring();
}
if (!fs::is_readable(fname.toFilesystemEncoding())) {
docstring const text = bformat(_("Could not read the specified document\n"
"%1$s\ndue to the error: %2$s"), file, error);
Alert::error(_("Could not read file"), text);
- return string();
+ return docstring();
}
ifstream ifs(fname.toFilesystemEncoding().c_str());
docstring const text = bformat(_("Could not open the specified document\n"
"%1$s\ndue to the error: %2$s"), file, error);
Alert::error(_("Could not open file"), text);
- return string();
+ return docstring();
}
ifs.unsetf(ios::skipws);
copy(ii, end, back_inserter(tmpstr));
#endif
- return tmpstr;
+ // FIXME UNICODE: We don't know the encoding of the file
+ return normalize_kc(from_utf8(tmpstr));
}
#ifndef LYX_CB_H
#define LYX_CB_H
-#include <string>
+#include "support/docstring.h"
namespace lyx {
void newFile(BufferView * bv, std::string const & filename);
///
void insertPlaintextFile(BufferView * bv, std::string const & f, bool asParagraph);
-///
-std::string getContentsOfPlaintextFile(BufferView * bv, std::string const & f, bool asParagraph);
+/// read plain text file (if \p f is empty, prompt for a filename)
+docstring const getContentsOfPlaintextFile(BufferView * bv,
+ std::string const & f, bool asParagraph);
///
void reconfigure(LyXView & lv);
}
+docstring const normalize_kc(docstring const & s)
+{
+ return qstring_to_ucs4(toqstr(s).normalized(QString::NormalizationForm_KC));
+}
+
+
bool operator==(lyx::docstring const & l, char const * r)
{
int const len = l.length();
/// convert \p s from ucs4 to the encoding of the file system.
std::string const to_filesystem8bit(docstring const & s);
+/// normalize \p s to precomposed form kc
+docstring const normalize_kc(docstring const & s);
+
/// Compare a docstring with a C string of ASCII characters
bool operator==(lyx::docstring const &, char const *);
<< lyx_accent_table[accent].name << '.' << std::endl;
os << s.substr(1);
}
- // FIXME: We should normalize the result to precomposed form
- return os.str();
+ return normalize_kc(os.str());
}