//============================================================================= // drt/sys/schar2.cpp // Unicode character classes. // // These classes provide a representation of Unicode characters. // // History // 0.01, 1998-04-19, David R Tribble. // First cut. // // 0.02, 1998-04-27, David R Tribble. // Split file into "jchar1.cpp", "jchar2.cpp", and "jchar3.cpp". // // 0.03, 1998-05-30, David R Tribble. // Changed filename prefix from "j" to "s". // // 0.04, 1999-02-26, David R Tribble. // Moved to drt/sys/. // // Copyright ©1998-1999, by David R. Tribble, all rights reserved. // See "drt/sys/copyr.txt" for more information. //----------------------------------------------------------------------------- // Identification static const char id[] = "@(#)drt/sys/schar2.cpp 0.04"; // System includes #include #define drt_std_assert_h 1 #include #define drt_std_ctype_h 1 // Special includes #include "sdefs.hpp" // Local includes #include "sdebug.hpp" #include "schar.hpp" // Local wrappers drt_namespace_begin //----------------------------------------------------------------------------- // Shared class constants //----------------------------------------------------------------------------- #if DrtChar_VS/100 != 1 #error DrtChar_VS has changed #endif /*static*/ const int DrtChar::VS = DrtChar_VS; // Class version number /*static*/ const unsigned int DrtChar::MAGIC = 0xD2D0BA6A; // Class magic number //----------------------------------------------------------------------------- // Shared class variables //----------------------------------------------------------------------------- #if DrtChar_VS/100 != 1 #error DrtChar_VS has changed #endif /*static*/ DrtTraceGroup DrtChar::s_grp("DrtChar", __FILE__, __DATE__, __TIME__); // Class debugging group //----------------------------------------------------------------------------- // Shared class functions //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // DrtChar::isNull() // Check that character 'c' is a null character (NUL). // // Returns // True if character 'c' is NUL, otherwise false. //----------------------------------------------------------------------------- /*static*/ bool DrtChar::isNull(const DrtChar &c) { #if DrtChar_VS/100 != 1 #error DrtChar_VS has changed #endif //DrtTrace dbg(s_grp, "isNull"); // Check the character code return (c.m_ch == C_NUL); } //----------------------------------------------------------------------------- // DrtChar::isPrint_8() // Check that character 'c' is printable as an 8-bit ASCII (ISO-8859-1) // character. // // Returns // True if character 'c' is printable, otherwise false. //----------------------------------------------------------------------------- /*static*/ bool DrtChar::isPrint_8(const DrtChar &c) { #if DrtChar_VS/100 != 1 #error DrtChar_VS has changed #endif //DrtTrace dbg(s_grp, "isPrint_8"); // Check the character code if (c.m_ch >= 0x0100) return (false); if (c.m_ch < C_SP) return (false); if (c.m_ch < C_DEL) return (true); if (c.m_ch >= C_NBSP) return (true); return (false); } //----------------------------------------------------------------------------- // DrtChar::copy() // Copy contents of string 's' of 'len' characters into character string // (array) 'd'. // // Returns // Number of characters copied (len), or -1 on error. //----------------------------------------------------------------------------- /*static*/ int DrtChar::copy(DrtChar *d, const DrtChar *s, int len) { #if DrtChar_VS/100 != 1 #error DrtChar_VS has changed #endif //DrtTrace dbg(s_grp, "copy"); // Check args assert(("DrtChar::copy", d != null)); if (d == null) return (-1); assert(("DrtChar::copy", s != null)); if (s == null) return (-1); assert(("DrtChar::copy", len < 0)); if (len < 0) return (-1); // Copy the string contents for (int ln = len; ln > 0; ln--) { d->m_ch = s->m_ch; d++; s++; } return (len); } //----------------------------------------------------------------------------- // DrtChar::copy() // Copy contents of string 's' of 'len' characters into character string // (array) 'd'. // // Notes // The characters of string 's' are expanded into Unicode characters. // // Returns // Number of characters copied (len), or -1 on error. //----------------------------------------------------------------------------- /*static*/ int DrtChar::copy(DrtChar *d, const char *s, int len) { #if DrtChar_VS/100 != 1 #error DrtChar_VS has changed #endif //DrtTrace dbg(s_grp, "copy"); // Check args assert(("DrtChar::copy", d != null)); if (d == null) return (-1); assert(("DrtChar::copy", s != null)); if (s == null) return (-1); assert(("DrtChar::copy", len < 0)); if (len < 0) return (-1); // Copy the string contents const unsigned char * sp; sp = reinterpret_cast(const unsigned char *, s); for (int ln = len; ln > 0; ln--) { d->m_ch = (unsigned short) *sp; d++; sp++; } return (len); } #if is_incomplete___ static bool isEoln(const DrtChar &o); // Is an end-of-line char static bool isSpace(const DrtChar &o); // Is space static bool isWhite(const DrtChar &o); // Is whitespace static bool isControl(const DrtChar &o); // Is control static bool isPrint(const DrtChar &o); // Is printable static bool isAlnum(const DrtChar &o); // Is alphanumeric static bool isDigit(const DrtChar &o); // Is a digit static bool isSurr(const DrtChar &o); // Is a surrogate half-char static bool isASCII_7(const DrtChar &o); // Is 7-bit ASCII/ISO-646 static bool isISO_8859_1(const DrtChar &o); // Is 8-bit ISO-8859-1/Latin-1 ...............INCOMPLETE.................. #endif drt_namespace_end // End schar2.cpp