]> git.lyx.org Git - lyx.git/blob - src/support/textutils.h
Collapse all those LFUN_XYZ_APPLY to a single LFUN_INSET_APPLY.
[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 /// return true if the char is a meta-character newline
19 inline
20 bool IsNewlineChar(char c)
21 {
22         return (c == Paragraph::META_NEWLINE);
23 }
24
25
26 /// return true if the char is a word separator
27 inline
28 bool IsSeparatorChar(char c)
29 {
30         return (c == ' ');
31 }
32
33
34 /// return true if the char is a line separator
35 inline
36 bool IsLineSeparatorChar(char c)
37 {
38         return (c == ' ');
39 }
40
41
42 /// return true if the char is a meta-character for hfill
43 inline
44 bool IsHfillChar(char c)
45 {
46         return (c == Paragraph::META_HFILL);
47 }
48
49
50 /// return true if the char is a meta-character for an inset
51 inline
52 bool IsInsetChar(char c)
53 {
54         return (c == Paragraph::META_INSET);
55 }
56
57
58 /// return true if the char is "punctuation"
59 inline
60 bool IsKommaChar(char c)
61 {
62         return (c == ','
63                 || c == '('
64                 || c == ')'
65                 || c == '['
66                 || c == ']'
67                 || c == '{'
68                 || c == '}'
69                 || c == ';'
70                 || c == '.'
71                 || c == ':'
72                 || c == '-'
73                 || c == '?'
74                 || c == '!'
75                 || c == '&'
76                 || c == '@'
77                 || c == '+'
78                 || c == '-'
79                 || c == '~'
80                 || c == '#'
81                 || c == '%'
82                 || c == '^'
83                 || c == '/'
84                 || c == '\\'
85                 || c == Paragraph::META_NEWLINE
86                 );
87 }
88
89
90 /// return true if a char is alphabetical (including accented chars)
91 inline
92 bool IsLetterChar(unsigned char c)
93 {
94         return ((c >= 'A' && c <= 'Z')
95                 || (c >= 'a' && c <= 'z')
96                 || (c >= 192)); // in iso-8859-x these are accented chars
97 }
98
99
100 /// return true if the char is printable (masked to 7-bit ASCII)
101 inline
102 bool IsPrintable(unsigned char c)
103 {
104         return ((c & 127) >= ' ');
105 }
106
107
108 /// return true if the char is printable and not a space (masked to 7-bit ASCII)
109 inline
110 bool IsPrintableNonspace(unsigned char c)
111 {
112         return IsPrintable(c) && (c != ' ');
113 }
114
115
116 /// return true if the char forms part of a word
117 inline
118 bool IsWordChar(unsigned char c)
119 {
120         return !(IsSeparatorChar(c)
121                   || IsKommaChar(c)
122                   || IsHfillChar(c)
123                   || IsInsetChar(c));
124 }
125
126
127 /// completely pointless FIXME
128 inline
129 bool IsDigit(unsigned char ch)
130 {
131         return ch >= '0' && ch <= '9';
132 }
133
134
135 /// return true if the char is alphanumeric
136 inline
137 bool IsLetterCharOrDigit(unsigned char ch)
138 {
139         return IsLetterChar(ch) || IsDigit(ch);
140 }
141
142 #endif // TEXTUTILS_H