]> git.lyx.org Git - lyx.git/blob - src/support/textutils.C
Scons: update_po should now work (missing dependency though)
[lyx.git] / src / support / textutils.C
1 // -*- C++ -*-
2 /**
3  * \file textutils.C
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Georg Baum
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 // FIXME: I can think of a better name for this file ...
13
14 #include <config.h>
15
16 #include "support/textutils.h"
17 #include "support/qstring_helpers.h"
18
19 namespace lyx {
20
21 namespace {
22         /// Maximum valid UCS4 code point
23         char_type const ucs4_max = 0x10ffff;
24 }
25
26
27 bool isLetterChar(char_type c)
28 {
29         if (!is_utf16(c)) {
30                 if (c > ucs4_max)
31                         // outside the UCS4 range
32                         return false;
33                 // assume that all non-utf16 characters are letters
34                 return true;
35         }
36         return ucs4_to_qchar(c).isLetter();
37 }
38
39
40 bool isPrintable(char_type c)
41 {
42         if (!is_utf16(c)) {
43                 if (c > ucs4_max)
44                         // outside the UCS4 range
45                         return false;
46                 // assume that all non-utf16 characters are printable
47                 return true;
48         }
49         return ucs4_to_qchar(c).isPrint();
50 }
51
52
53 bool isPrintableNonspace(char_type c)
54 {
55         if (!is_utf16(c)) {
56                 if (c > ucs4_max)
57                         // outside the UCS4 range
58                         return false;
59                 // assume that all non-utf16 characters are printable and
60                 // no space
61                 return true;
62         }
63         QChar const qc = ucs4_to_qchar(c);
64         return qc.isPrint() && !qc.isSpace();
65 }
66
67
68 bool isDigit(char_type c)
69 {
70         if (!is_utf16(c))
71                 // assume that no non-utf16 character is a digit
72                 // c outside the UCS4 range is catched as well
73                 return false;
74         return ucs4_to_qchar(c).isDigit();
75 }
76
77 } // namespace lyx