]> git.lyx.org Git - lyx.git/blob - src/support/textutils.h
lots of small stuff
[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 /// return true if a char is alphabetical (including accented chars)
65 inline
66 bool IsLetterChar(unsigned char c)
67 {
68         return (c >= 'A' && c <= 'Z')
69                 || (c >= 'a' && c <= 'z')
70                 || (c >= 192); // in iso-8859-x these are accented chars
71 }
72
73
74 /// return true if the char is printable (masked to 7-bit ASCII)
75 inline
76 bool IsPrintable(unsigned char c)
77 {
78         return (c & 127) >= ' ';
79 }
80
81
82 /// return true if the char is printable and not a space (masked to 7-bit ASCII)
83 inline
84 bool IsPrintableNonspace(unsigned char c)
85 {
86         return IsPrintable(c) && c != ' ';
87 }
88
89
90 /// completely pointless FIXME
91 inline
92 bool IsDigit(unsigned char ch)
93 {
94         return ch >= '0' && ch <= '9';
95 }
96
97
98 /// return true if the char is alphanumeric
99 inline
100 bool IsLetterCharOrDigit(unsigned char ch)
101 {
102         return IsLetterChar(ch) || IsDigit(ch);
103 }
104
105 #endif // TEXTUTILS_H