+namespace {
+
+bool canInsertChar(Cursor const & cur, char_type c)
+{
+ Paragraph const & par = cur.paragraph();
+ // If not in free spacing mode, check if there will be two blanks together or a blank at
+ // the beginning of a paragraph.
+ if (!par.isFreeSpacing() && isLineSeparatorChar(c)) {
+ if (cur.pos() == 0) {
+ cur.message(_(
+ "You cannot insert a space at the "
+ "beginning of a paragraph. Please read the Tutorial."));
+ return false;
+ }
+ // If something is wrong, ignore this character.
+ LASSERT(cur.pos() > 0, return false);
+ if ((par.isLineSeparator(cur.pos() - 1) || par.isNewline(cur.pos() - 1))
+ && !par.isDeleted(cur.pos() - 1)) {
+ cur.message(_(
+ "You cannot type two spaces this way. "
+ "Please read the Tutorial."));
+ return false;
+ }
+ }
+
+ // Prevent to insert uncodable characters in verbatim and ERT.
+ // The encoding is inherited from the context here.
+ if (par.isPassThru() && cur.getEncoding()) {
+ Encoding const * e = cur.getEncoding();
+ if (!e->encodable(c)) {
+ cur.message(_("Character is uncodable in this verbatim context."));
+ return false;
+ }
+ }
+ return true;
+}
+
+} // namespace
+
+