]> git.lyx.org Git - lyx.git/blob - src/support/textutils.h
* src/text2.C: deleteEmptyParagraphMechanism(): fix a crash in
[lyx.git] / src / support / textutils.h
1 // -*- C++ -*-
2 /**
3  * \file textutils.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Matthias Ettrich
8  * \author Lars Gullik Bjønnes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 // FIXME: I can think of a better name for this file ...
14
15 #ifndef TEXTUTILS_H
16 #define TEXTUTILS_H
17
18 #include "support/types.h"
19
20 #ifdef LIBC_WCTYPE_USES_UCS4
21 // We can use the libc ctype functions because we unset the LC_CTYPE
22 // category of the current locale in gettext.C
23 #include <wctype.h>
24 #else
25 // Steal some code from somewhere else, e.g. glib (look at gunicode.h)
26 // The code that we currently use does not really work.
27 #endif
28
29
30 namespace lyx {
31
32 /// return true if the char is a line separator
33 inline
34 bool isLineSeparatorChar(char_type c)
35 {
36         return c == ' ';
37 }
38
39
40 /// return true if a char is alphabetical (including accented chars)
41 inline
42 bool isLetterChar(char_type c)
43 {
44 #ifdef LIBC_WCTYPE_USES_UCS4
45         return iswalpha(c);
46 #else
47         // FIXME UNICODE This is wrong!
48         return (c >= 'A' && c <= 'Z')
49                 || (c >= 'a' && c <= 'z')
50                 || (c >= 192 && c < 256); // in iso-8859-x these are accented chars
51 #endif
52 }
53
54
55 /// return true if the char is printable
56 inline
57 bool isPrintable(char_type c)
58 {
59 #ifdef LIBC_WCTYPE_USES_UCS4
60         return iswprint(c);
61 #else
62         // FIXME UNICODE This is wrong!
63         return (c & 127) >= ' ';
64 #endif
65 }
66
67
68 /// return true if the char is printable and not a space
69 inline
70 bool isPrintableNonspace(char_type c)
71 {
72 #ifdef LIBC_WCTYPE_USES_UCS4
73         return iswprint(c) && !iswspace(c);
74 #else
75         // FIXME UNICODE This is wrong!
76         return (c & 127) > ' ';
77 #endif
78 }
79
80
81 /// return true if a unicode char is a digit.
82 inline
83 bool isDigit(char_type c)
84 {
85 #ifdef LIBC_WCTYPE_USES_UCS4
86         return iswdigit(c);
87 #else
88         // FIXME UNICODE This is wrong!
89         return c >= '0' && c <= '9';
90 #endif
91 }
92
93
94
95 } // namespace lyx
96
97 #endif // TEXTUTILS_H