]> git.lyx.org Git - lyx.git/blob - src/support/textutils.h
7e9d9fc8e73a77c845017468fe80a07d312e984f
[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 word separator
19 inline
20 bool IsSeparatorChar(char c)
21 {
22         return (c == ' ');
23 }
24
25
26 /// return true if the char is a line separator
27 inline
28 bool IsLineSeparatorChar(char c)
29 {
30         return (c == ' ');
31 }
32
33
34 /// return true if the char is "punctuation"
35 inline
36 bool IsKommaChar(char c)
37 {
38         return (c == ','
39                 || c == '('
40                 || c == ')'
41                 || c == '['
42                 || c == ']'
43                 || c == '{'
44                 || c == '}'
45                 || c == ';'
46                 || c == '.'
47                 || c == ':'
48                 || 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                 );
62 }
63
64
65 /// return true if a char is alphabetical (including accented chars)
66 inline
67 bool IsLetterChar(unsigned char c)
68 {
69         return ((c >= 'A' && c <= 'Z')
70                 || (c >= 'a' && c <= 'z')
71                 || (c >= 192)); // in iso-8859-x these are accented chars
72 }
73
74
75 /// return true if the char is printable (masked to 7-bit ASCII)
76 inline
77 bool IsPrintable(unsigned char c)
78 {
79         return ((c & 127) >= ' ');
80 }
81
82
83 /// return true if the char is printable and not a space (masked to 7-bit ASCII)
84 inline
85 bool IsPrintableNonspace(unsigned char c)
86 {
87         return IsPrintable(c) && (c != ' ');
88 }
89
90
91 /// completely pointless FIXME
92 inline
93 bool IsDigit(unsigned char ch)
94 {
95         return ch >= '0' && ch <= '9';
96 }
97
98
99 /// return true if the char is alphanumeric
100 inline
101 bool IsLetterCharOrDigit(unsigned char ch)
102 {
103         return IsLetterChar(ch) || IsDigit(ch);
104 }
105
106 #endif // TEXTUTILS_H