]> git.lyx.org Git - lyx.git/blob - src/support/textutils.cpp
remove lyxrc dependence from support/*
[lyx.git] / src / support / textutils.cpp
1 // -*- C++ -*-
2 /**
3  * \file textutils.cpp
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 isAlphaASCII(char_type c)
41 {
42         return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
43 }
44
45
46 bool isPrintable(char_type c)
47 {
48         if (!is_utf16(c)) {
49                 if (c > ucs4_max)
50                         // outside the UCS4 range
51                         return false;
52                 // assume that all non-utf16 characters are printable
53                 return true;
54         }
55         return ucs4_to_qchar(c).isPrint();
56 }
57
58
59 bool isPrintableNonspace(char_type c)
60 {
61         if (!is_utf16(c)) {
62                 if (c > ucs4_max)
63                         // outside the UCS4 range
64                         return false;
65                 // assume that all non-utf16 characters are printable and
66                 // no space
67                 return true;
68         }
69         QChar const qc = ucs4_to_qchar(c);
70         return qc.isPrint() && !qc.isSpace();
71 }
72
73
74 bool isSpace(char_type c)
75 {
76         if (!is_utf16(c)) {
77                 // assume that no non-utf16 character is a space
78                 // c outside the UCS4 range is catched as well
79                 return false;
80         }
81         QChar const qc = ucs4_to_qchar(c);
82         return qc.isSpace();
83 }
84
85
86 bool isDigit(char_type c)
87 {
88         if (!is_utf16(c))
89                 // assume that no non-utf16 character is a digit
90                 // c outside the UCS4 range is catched as well
91                 return false;
92         return ucs4_to_qchar(c).isDigit();
93 }
94
95
96 bool isDigitASCII(char_type c)
97 {
98         return '0' <= c && c <= '9';
99 }
100
101 } // namespace lyx