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