1999-09-27 18:44:28 +00:00
|
|
|
|
// -*- C++ -*-
|
2002-05-30 02:24:33 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file textutils.h
|
2002-09-25 10:03:41 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 10:03:41 +00:00
|
|
|
|
* \author Matthias Ettrich
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-05-30 02:24:33 +00:00
|
|
|
|
*/
|
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 ...
|
2002-08-14 17:15:18 +00:00
|
|
|
|
|
1999-11-15 10:54:16 +00:00
|
|
|
|
#ifndef TEXTUTILS_H
|
|
|
|
|
#define TEXTUTILS_H
|
|
|
|
|
|
2006-09-03 12:12:53 +00:00
|
|
|
|
#include "support/types.h"
|
1999-11-15 10:54:16 +00:00
|
|
|
|
|
2006-11-13 09:53:25 +00:00
|
|
|
|
#ifdef LIBC_WCTYPE_USES_UCS4
|
|
|
|
|
// We can use the libc ctype functions because we unset the LC_CTYPE
|
|
|
|
|
// category of the current locale in gettext.C
|
|
|
|
|
#include <wctype.h>
|
|
|
|
|
#else
|
|
|
|
|
// Steal some code from somewhere else, e.g. glib (look at gunicode.h)
|
|
|
|
|
// The code that we currently use does not really work.
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
|
/// return true if the char is a line separator
|
|
|
|
|
inline
|
2006-11-13 09:53:25 +00:00
|
|
|
|
bool isLineSeparatorChar(char_type c)
|
2002-08-14 17:15:18 +00:00
|
|
|
|
{
|
2003-10-28 11:18:40 +00:00
|
|
|
|
return c == ' ';
|
2002-05-30 02:24:33 +00:00
|
|
|
|
}
|
2002-08-14 17:15:18 +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
|
2006-11-13 09:53:25 +00:00
|
|
|
|
bool isLetterChar(char_type c)
|
2002-08-14 17:15:18 +00:00
|
|
|
|
{
|
2006-11-13 09:53:25 +00:00
|
|
|
|
#ifdef LIBC_WCTYPE_USES_UCS4
|
|
|
|
|
return iswalpha(c);
|
|
|
|
|
#else
|
|
|
|
|
// FIXME UNICODE This is wrong!
|
2003-10-28 11:18:40 +00:00
|
|
|
|
return (c >= 'A' && c <= 'Z')
|
1999-11-15 10:54:16 +00:00
|
|
|
|
|| (c >= 'a' && c <= 'z')
|
2006-09-03 12:12:53 +00:00
|
|
|
|
|| (c >= 192 && c < 256); // in iso-8859-x these are accented chars
|
2006-11-13 09:53:25 +00:00
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
1999-11-15 10:54:16 +00:00
|
|
|
|
|
|
|
|
|
|
2006-11-13 09:53:25 +00:00
|
|
|
|
/// return true if the char is printable
|
2000-02-29 02:19:17 +00:00
|
|
|
|
inline
|
2006-11-13 09:53:25 +00:00
|
|
|
|
bool isPrintable(char_type c)
|
2002-08-14 17:15:18 +00:00
|
|
|
|
{
|
2006-11-13 09:53:25 +00:00
|
|
|
|
#ifdef LIBC_WCTYPE_USES_UCS4
|
|
|
|
|
return iswprint(c);
|
|
|
|
|
#else
|
|
|
|
|
// FIXME UNICODE This is wrong!
|
2003-10-28 11:18:40 +00:00
|
|
|
|
return (c & 127) >= ' ';
|
2006-11-13 09:53:25 +00:00
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
1999-11-15 10:54:16 +00:00
|
|
|
|
|
|
|
|
|
|
2006-11-13 09:53:25 +00:00
|
|
|
|
/// return true if the char is printable and not a space
|
2000-07-04 20:32:37 +00:00
|
|
|
|
inline
|
2006-11-13 09:53:25 +00:00
|
|
|
|
bool isPrintableNonspace(char_type c)
|
2002-08-14 17:15:18 +00:00
|
|
|
|
{
|
2006-11-13 09:53:25 +00:00
|
|
|
|
#ifdef LIBC_WCTYPE_USES_UCS4
|
|
|
|
|
return iswprint(c) && !iswspace(c);
|
|
|
|
|
#else
|
|
|
|
|
// FIXME UNICODE This is wrong!
|
2006-10-22 13:51:37 +00:00
|
|
|
|
return (c & 127) > ' ';
|
2006-11-13 09:53:25 +00:00
|
|
|
|
#endif
|
2000-07-04 20:32:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-11-13 09:53:25 +00:00
|
|
|
|
|
2006-09-03 12:12:53 +00:00
|
|
|
|
/// return true if a unicode char is a digit.
|
2000-02-29 02:19:17 +00:00
|
|
|
|
inline
|
2006-11-13 09:53:25 +00:00
|
|
|
|
bool isDigit(char_type c)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2006-11-13 09:53:25 +00:00
|
|
|
|
#ifdef LIBC_WCTYPE_USES_UCS4
|
|
|
|
|
return iswdigit(c);
|
|
|
|
|
#else
|
|
|
|
|
// FIXME UNICODE This is wrong!
|
|
|
|
|
return c >= '0' && c <= '9';
|
|
|
|
|
#endif
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
|
#endif // TEXTUTILS_H
|