#include "support/debug.h"
#include "support/gettext.h"
#include "support/lstrings.h"
#include "support/debug.h"
#include "support/gettext.h"
#include "support/lstrings.h"
Encoding::Encoding(string const & n, string const & l, string const & g,
string const & i, bool f, bool u, Encoding::Package p)
: name_(n), latexName_(l), guiName_(g), iconvName_(i), fixedwidth_(f),
Encoding::Encoding(string const & n, string const & l, string const & g,
string const & i, bool f, bool u, Encoding::Package p)
: name_(n), latexName_(l), guiName_(g), iconvName_(i), fixedwidth_(f),
+ // Since the the constructor is the only method which sets complete_
+ // to false the test for complete_ is thread-safe without mutex.
+ if (complete_)
+ return;
+
+ static Mutex mutex;
+ Mutex::Locker lock(&mutex);
+
+ // We need to test again for complete_, since another thread could
+ // have set it to true while we were waiting for the lock and we must
+ // not modify an encoding which is already complete.
+ // We do not make any member mutable so that it can be easily verified
+ // that all const methods are thread-safe: init() is the only const
+ // method which changes complete_, encodable_ and start_encodable_, and
+ // it uses a mutex to ensure thread-safety.
+ CharSet & encodable = const_cast<Encoding *>(this)->encodable_;
+ char_type & start_encodable = const_cast<Encoding *>(this)->start_encodable_;
+
+ start_encodable = 0;
char_type const uc = ucs4[0];
CharInfoMap::const_iterator const it = unicodesymbols.find(uc);
if (it == unicodesymbols.end())
char_type const uc = ucs4[0];
CharInfoMap::const_iterator const it = unicodesymbols.find(uc);
if (it == unicodesymbols.end())
- CharSet::iterator it = encodable_.find(start_encodable_);
- while (it != encodable_.end()) {
- encodable_.erase(it);
- ++start_encodable_;
- it = encodable_.find(start_encodable_);
+ CharSet::iterator it = encodable.find(start_encodable);
+ while (it != encodable.end()) {
+ encodable.erase(it);
+ ++start_encodable;
+ it = encodable.find(start_encodable);
CharInfoMap::const_iterator const end = unicodesymbols.end();
CharInfoMap::const_iterator it = unicodesymbols.begin();
for (combining = false; it != end; ++it) {
CharInfoMap::const_iterator const end = unicodesymbols.end();
CharInfoMap::const_iterator it = unicodesymbols.begin();
for (combining = false; it != end; ++it) {
docstring const math = it->second.mathcommand();
docstring const text = it->second.textcommand();
if ((cmdtype & MATH_CMD) && math == cmd) {
docstring const math = it->second.mathcommand();
docstring const text = it->second.textcommand();
if ((cmdtype & MATH_CMD) && math == cmd) {
docstring const math = mathmode ? it->second.mathcommand()
: docstring();
docstring const text = textmode ? it->second.textcommand()
docstring const math = mathmode ? it->second.mathcommand()
: docstring();
docstring const text = textmode ? it->second.textcommand()
+bool Encodings::isUnicodeTextOnly(char_type c)
+{
+ if (isASCII(c) || isMathAlpha(c))
+ return false;
+
+ CharInfoMap::const_iterator const it = unicodesymbols.find(c);
+ return it == unicodesymbols.end() || it->second.mathcommand().empty();
+}
+
+
Encoding const *
Encodings::fromLyXName(string const & name, bool allowUnsafe) const
{
EncodingList::const_iterator const it = encodinglist.find(name);
Encoding const *
Encodings::fromLyXName(string const & name, bool allowUnsafe) const
{
EncodingList::const_iterator const it = encodinglist.find(name);
flags &= ~CharInfoMathNoTermination;
} else if (contains(flag, "tipashortcut=")) {
tipashortcut = split(flag, '=');
flags &= ~CharInfoMathNoTermination;
} else if (contains(flag, "tipashortcut=")) {
tipashortcut = split(flag, '=');