1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
2002-05-30 02:24:33 +00:00
|
|
|
/**
|
|
|
|
* \file textutils.h
|
|
|
|
* Copyright 1995-2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2002-05-30 02:24:33 +00:00
|
|
|
* \author unknown
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
// FIXME: I can think of a better name for this file ...
|
|
|
|
|
1999-11-15 10:54:16 +00:00
|
|
|
#ifndef TEXTUTILS_H
|
|
|
|
#define TEXTUTILS_H
|
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
/// return true if the char is a meta-character newline
|
2000-02-29 02:19:17 +00:00
|
|
|
inline
|
|
|
|
bool IsNewlineChar(char c) {
|
2001-06-25 00:06:33 +00:00
|
|
|
return (c == Paragraph::META_NEWLINE);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-15 10:54:16 +00:00
|
|
|
|
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
/// return true if the char is a word separator
|
2000-02-29 02:19:17 +00:00
|
|
|
inline
|
|
|
|
bool IsSeparatorChar(char c) {
|
|
|
|
return (c == ' ');
|
|
|
|
}
|
1999-11-15 10:54:16 +00:00
|
|
|
|
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
/// return true if the char is a line separator
|
|
|
|
inline
|
|
|
|
bool IsLineSeparatorChar(char c) {
|
|
|
|
return (c == ' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// return true if the char is a meta-character for hfill
|
2000-02-29 02:19:17 +00:00
|
|
|
inline
|
|
|
|
bool IsHfillChar(char c) {
|
2001-06-25 00:06:33 +00:00
|
|
|
return (c == Paragraph::META_HFILL);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-15 10:54:16 +00:00
|
|
|
|
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
/// return true if the char is a meta-character for an inset
|
2000-02-29 02:19:17 +00:00
|
|
|
inline
|
|
|
|
bool IsInsetChar(char c) {
|
2001-06-25 00:06:33 +00:00
|
|
|
return (c == Paragraph::META_INSET);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-15 10:54:16 +00:00
|
|
|
|
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
/// return true if the char is "punctuation"
|
2000-02-29 02:19:17 +00:00
|
|
|
inline
|
|
|
|
bool IsKommaChar(char c) {
|
2002-03-21 17:09:55 +00:00
|
|
|
return (c == ','
|
1999-11-15 10:54:16 +00:00
|
|
|
|| c == '('
|
|
|
|
|| c == ')'
|
|
|
|
|| c == '['
|
|
|
|
|| c == ']'
|
|
|
|
|| c == '{'
|
|
|
|
|| c == '}'
|
|
|
|
|| c == ';'
|
|
|
|
|| c == '.'
|
|
|
|
|| c == ':'
|
|
|
|
|| c == '-'
|
|
|
|
|| c == '?'
|
|
|
|
|| c == '!'
|
|
|
|
|| c == '&'
|
|
|
|
|| c == '@'
|
|
|
|
|| c == '+'
|
|
|
|
|| c == '-'
|
|
|
|
|| c == '~'
|
|
|
|
|| c == '#'
|
|
|
|
|| c == '%'
|
|
|
|
|| c == '^'
|
2002-03-21 17:09:55 +00:00
|
|
|
|| c == '/'
|
1999-11-15 10:54:16 +00:00
|
|
|
|| c == '\\'
|
2001-06-25 00:06:33 +00:00
|
|
|
|| c == Paragraph::META_NEWLINE
|
1999-09-27 18:44:28 +00:00
|
|
|
);
|
|
|
|
}
|
1999-11-15 10:54:16 +00:00
|
|
|
|
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
/// return true if a char is alphabetical (including accented chars)
|
2000-02-29 02:19:17 +00:00
|
|
|
inline
|
|
|
|
bool IsLetterChar(unsigned char c) {
|
1999-11-15 10:54:16 +00:00
|
|
|
return ((c >= 'A' && c <= 'Z')
|
|
|
|
|| (c >= 'a' && c <= 'z')
|
|
|
|
|| (c >= 192)); // in iso-8859-x these are accented chars
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-15 10:54:16 +00:00
|
|
|
|
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
/// return true if the char is printable (masked to 7-bit ASCII)
|
2000-02-29 02:19:17 +00:00
|
|
|
inline
|
|
|
|
bool IsPrintable(unsigned char c) {
|
2001-06-25 00:06:33 +00:00
|
|
|
return ((c & 127) >= ' ');
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-15 10:54:16 +00:00
|
|
|
|
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
/// return true if the char is printable and not a space (masked to 7-bit ASCII)
|
2000-07-04 20:32:37 +00:00
|
|
|
inline
|
|
|
|
bool IsPrintableNonspace(unsigned char c) {
|
2001-06-25 00:06:33 +00:00
|
|
|
return IsPrintable(c) && (c != ' ');
|
2000-07-04 20:32:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
/// return true if the char forms part of a word
|
2000-02-29 02:19:17 +00:00
|
|
|
inline
|
|
|
|
bool IsWordChar(unsigned char c) {
|
2002-02-16 15:59:55 +00:00
|
|
|
return !(IsSeparatorChar(c)
|
|
|
|
|| IsKommaChar(c)
|
|
|
|
|| IsHfillChar(c)
|
|
|
|
|| IsInsetChar(c));
|
1999-11-15 10:54:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
/// completely pointless FIXME
|
2000-02-29 02:19:17 +00:00
|
|
|
inline
|
2001-06-25 00:06:33 +00:00
|
|
|
bool IsDigit(unsigned char ch)
|
|
|
|
{
|
|
|
|
return ch >= '0' && ch <= '9';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
/// return true if the char is alphanumeric
|
2001-06-25 00:06:33 +00:00
|
|
|
inline
|
|
|
|
bool IsLetterCharOrDigit(unsigned char ch)
|
1999-11-15 10:54:16 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return IsLetterChar(ch) || IsDigit(ch);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2002-05-30 02:24:33 +00:00
|
|
|
|
|
|
|
#endif // TEXTUTILS_H
|