// -*- C++ -*-
-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright (C) 1995 Matthias Ettrich
+/**
+ * \file textutils.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- *======================================================*/
-#ifndef _TEXTUTILS_H
-#define _TEXTUTILS_H
+ * \author Matthias Ettrich
+ * \author Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
-#include "definitions.h"
+// FIXME: I can think of a better name for this file ...
-///
-inline bool IsNewlineChar(char c) {
- return (c == LYX_META_NEWLINE);
-}
-///
-inline bool IsSeparatorChar(char c) {
- return (c == ' ' || c == LYX_META_PROTECTED_SEPARATOR);
-}
-///
-inline bool IsHfillChar(char c) {
- return (c == LYX_META_HFILL);
-}
-///
-inline bool IsInsetChar(char c) {
- return (c == LYX_META_INSET);
-}
-///
-inline bool IsFloatChar(char c) {
- return (c == LYX_META_FOOTNOTE
- || c == LYX_META_MARGIN
- || c == LYX_META_FIG
- || c == LYX_META_TAB
- || c == LYX_META_ALGORITHM
- || c == LYX_META_WIDE_FIG
- || c == LYX_META_WIDE_TAB);
-}
-///
-inline bool IsLineSeparatorChar(char c) {
- return (c == ' ');
-}
-///
-inline bool IsKommaChar(char c) {
- return (c == ','
- || c=='('
- || c==')'
- || c=='['
- || c==']'
- || c=='{'
- || c=='}'
- || c==';'
- || c=='.'
- || c==':'
- || c=='-'
- || c=='?'
- || c=='!'
- || c=='&'
- || c=='@'
- || c=='+'
- || c=='-'
- || c=='~'
- || c=='#'
- || c=='%'
- || c=='^'
- || c=='/'
- || c=='\\'
- || c==LYX_META_NEWLINE
- || c==LYX_META_PROTECTED_SEPARATOR
- );
+#ifndef TEXTUTILS_H
+#define TEXTUTILS_H
+
+#include "support/types.h"
+
+#ifdef LIBC_WCTYPE_USES_UCS4
+// We can use the libc ctype functions because we unset the LC_CTYPE
+// category of the current locale in gettext.C
+#include <wctype.h>
+#else
+// Steal some code from somewhere else, e.g. glib (look at gunicode.h)
+// The code that we currently use does not really work.
+#endif
+
+
+namespace lyx {
+
+/// return true if the char is a line separator
+inline
+bool isLineSeparatorChar(char_type c)
+{
+ return c == ' ';
}
-///
-inline bool IsLetterChar(unsigned char c) {
- return ((c>='A' && c<='Z')
- || (c>='a' && c<='z')
- || (c>=192)); // in iso-8859-x these are accented chars
+
+
+/// return true if a char is alphabetical (including accented chars)
+inline
+bool isLetterChar(char_type c)
+{
+#ifdef LIBC_WCTYPE_USES_UCS4
+ return iswalpha(c);
+#else
+ // FIXME UNICODE This is wrong!
+ return (c >= 'A' && c <= 'Z')
+ || (c >= 'a' && c <= 'z')
+ || (c >= 192 && c < 256); // in iso-8859-x these are accented chars
+#endif
}
-///
-inline bool IsPrintable(unsigned char c) {
- return (c>=' ');
+
+
+/// return true if the char is printable
+inline
+bool isPrintable(char_type c)
+{
+#ifdef LIBC_WCTYPE_USES_UCS4
+ return iswprint(c);
+#else
+ // FIXME UNICODE This is wrong!
+ return (c & 127) >= ' ';
+#endif
}
-/// Word is not IsSeparator or IsKomma or IsHfill or IsFloat or IsInset.
-inline bool IsWordChar(unsigned char c) {
- return !( IsSeparatorChar( c )
- || IsKommaChar( c )
- || IsHfillChar( c )
- || IsFloatChar( c )
- || IsInsetChar( c ) ) ;
+
+
+/// return true if the char is printable and not a space
+inline
+bool isPrintableNonspace(char_type c)
+{
+#ifdef LIBC_WCTYPE_USES_UCS4
+ return iswprint(c) && !iswspace(c);
+#else
+ // FIXME UNICODE This is wrong!
+ return (c & 127) > ' ';
+#endif
}
+
+
+/// return true if a unicode char is a digit.
+inline
+bool isDigit(char_type c)
+{
+#ifdef LIBC_WCTYPE_USES_UCS4
+ return iswdigit(c);
+#else
+ // FIXME UNICODE This is wrong!
+ return c >= '0' && c <= '9';
#endif
+}
+
+
+
+} // namespace lyx
+
+#endif // TEXTUTILS_H