]> git.lyx.org Git - lyx.git/blob - src/support/textutils.h
fe07ee7c2c910930b191b415fa7932b09cb10309
[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 an inset
43 inline
44 bool IsInsetChar(char c)
45 {
46         return (c == Paragraph::META_INSET);
47 }
48
49
50 /// return true if the char is "punctuation"
51 inline
52 bool IsKommaChar(char c)
53 {
54         return (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                 || c == '~'
72                 || c == '#'
73                 || c == '%'
74                 || c == '^'
75                 || c == '/'
76                 || c == '\\'
77                 || c == Paragraph::META_NEWLINE
78                 );
79 }
80
81
82 /// return true if a char is alphabetical (including accented chars)
83 inline
84 bool IsLetterChar(unsigned char c)
85 {
86         return ((c >= 'A' && c <= 'Z')
87                 || (c >= 'a' && c <= 'z')
88                 || (c >= 192)); // in iso-8859-x these are accented chars
89 }
90
91
92 /// return true if the char is printable (masked to 7-bit ASCII)
93 inline
94 bool IsPrintable(unsigned char c)
95 {
96         return ((c & 127) >= ' ');
97 }
98
99
100 /// return true if the char is printable and not a space (masked to 7-bit ASCII)
101 inline
102 bool IsPrintableNonspace(unsigned char c)
103 {
104         return IsPrintable(c) && (c != ' ');
105 }
106
107
108 /// return true if the char forms part of a word
109 inline
110 bool IsWordChar(unsigned char c)
111 {
112         return !(IsSeparatorChar(c)
113                   || IsKommaChar(c)
114                   || IsInsetChar(c));
115 }
116
117
118 /// completely pointless FIXME
119 inline
120 bool IsDigit(unsigned char ch)
121 {
122         return ch >= '0' && ch <= '9';
123 }
124
125
126 /// return true if the char is alphanumeric
127 inline
128 bool IsLetterCharOrDigit(unsigned char ch)
129 {
130         return IsLetterChar(ch) || IsDigit(ch);
131 }
132
133 #endif // TEXTUTILS_H