]> git.lyx.org Git - lyx.git/blob - src/support/textutils.h
3a94a64367aa5f89daa8093482f8209b56011338
[lyx.git] / src / support / textutils.h
1 // -*- C++ -*-
2 /**
3  * \file textutils.h
4  * Copyright 1995-2002 the LyX Team
5  * Read the file COPYING
6  *
7  * \author unknown
8  */
9
10 // FIXME: I can think of a better name for this file ...
11  
12 #ifndef TEXTUTILS_H
13 #define TEXTUTILS_H
14
15 /// return true if the char is a meta-character newline
16 inline
17 bool IsNewlineChar(char c) {
18         return (c == Paragraph::META_NEWLINE);
19 }
20
21
22 /// return true if the char is a word separator
23 inline
24 bool IsSeparatorChar(char c) {
25         return (c == ' ');
26 }
27
28
29 /// return true if the char is a line separator
30 inline
31 bool IsLineSeparatorChar(char c) {
32         return (c == ' ');
33 }
34  
35
36 /// return true if the char is a meta-character for hfill
37 inline
38 bool IsHfillChar(char c) {
39         return (c == Paragraph::META_HFILL);
40 }
41
42
43 /// return true if the char is a meta-character for an inset
44 inline
45 bool IsInsetChar(char c) {
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         return (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                 || c == '#'
72                 || c == '%'
73                 || c == '^'
74                 || c == '/'
75                 || c == '\\'
76                 || c == Paragraph::META_NEWLINE
77                 );
78 }
79
80
81 /// return true if a char is alphabetical (including accented chars)
82 inline
83 bool IsLetterChar(unsigned char c) {
84         return ((c >= 'A' && c <= 'Z')
85                 || (c >= 'a' && c <= 'z')
86                 || (c >= 192)); // in iso-8859-x these are accented chars
87 }
88
89
90 /// return true if the char is printable (masked to 7-bit ASCII)
91 inline
92 bool IsPrintable(unsigned char c) {
93         return ((c & 127) >= ' ');
94 }
95
96
97 /// return true if the char is printable and not a space (masked to 7-bit ASCII) 
98 inline
99 bool IsPrintableNonspace(unsigned char c) {
100         return IsPrintable(c) && (c != ' ');
101 }
102
103
104 /// return true if the char forms part of a word
105 inline
106 bool IsWordChar(unsigned char c) {
107         return !(IsSeparatorChar(c)
108                   || IsKommaChar(c)
109                   || IsHfillChar(c)
110                   || IsInsetChar(c));
111 }
112
113
114 /// completely pointless FIXME
115 inline
116 bool IsDigit(unsigned char ch)
117 {
118         return ch >= '0' && ch <= '9';
119 }
120
121
122 /// return true if the char is alphanumeric
123 inline
124 bool IsLetterCharOrDigit(unsigned char ch)
125 {
126         return IsLetterChar(ch) || IsDigit(ch);
127 }
128  
129 #endif // TEXTUTILS_H