/* ctype.h 2000-10 writen by tenk* */ #ifndef _JCTYPE_H_ #define _JCTYPE_H_ #ifdef __cplusplus extern "C" { #endif /*#include */ #include "ctype.h" #if 0 /* inline が使える場合. */ inline int iskanji(int c) {return (int)((unsigned)(((unsigned char)c)^0x20) - 0xA1 < 0x3C);} /*inline int iskanji(int c) {c = (unsigned char)c; return (c >= 0x81 && (c <= 0x9F || (c >= 0xE0 && c <= 0xFC)));}*/ inline int iskanji2(int c) {c = (unsigned char)c; return (c >= 0x40 && c <= 0xfc && c != 0x7f);} inline int iskana(int c) {c = (unsigned char)c; return (c >= 0xA1 && c <= 0xDF);} inline int iskmoji(int c) {c = (unsigned char)c; return (c >= 0xA6 && c <= 0xDF);} inline int iskpun(int c) {c = (unsigned char)c; return (c >= 0xA1 && c <= 0xA5);} inline int isalkana(int c) {return iskmoji(c) || isalpha(c); } inline int isalnmkana(int c) {return iskmoji(c) || isalnum(c); } inline int isgrkana(int c) {return iskana(c) || isgraph(c); } inline int ispnkana(int c) {return iskpun(c) || ispunct(c); } inline int isprkana(int c) {return iskana(c) || isprint(c); } inline int jisspace(unsigned short c) {return c == 0x8140;} inline int jiskigou(unsigned short c) {return c <= 0x81ac && c >= 0x8141/*、*/ && c != 0x817f;} inline int jisdigit(unsigned short c) {return c <= 0x8258/*9*/ && c >= 0x824F/*0*/;} inline int jisupper(unsigned short c) {return c <= 0x8279/*Z*/ && c >= 0x8260/*A*/;} inline int jislower(unsigned short c) {return c <= 0x829a/*z*/ && c >= 0x8281/*a*/;} inline int jisalpha(unsigned short c) {return jisupper(c) || jislower(c);} inline int jishira(unsigned short c) {return c <= 0x82F1/*ん*/ && c >= 0x829f/*ぁ*/;} inline int jiskata(unsigned short c) {return c <= 0x8396/**/ && c >= 0x8340/*ァ*/ && c != 0x837f;} inline int jisl0(unsigned short c) {return c <= 0x889e && jiszen(c);} inline int jisl1(unsigned short c) {return 0x889f <= c && c <= 0x9872 && jiszen(c);} inline int jisl2(unsigned short c) {return 0x989f <= c && c <= 0xea9e && jiszen(c);} inline unsigned short jtolower(unsigned short c) {return (0x8279 >= c && c >= 0x8260) ? c+0x21 : (c < 0x80 && islower(c)) ? toupper(c) : c;} inline unsigned short jtoupper(unsigned short c) {return (0x829a >= c && c >= 0x8281) ? c-0x21 : (c < 0x80 && isupper(c)) ? tolower(c) : c;} inline unsigned short jtohira(unsigned short c) {return (0x8393 >= c && c >= 0x8380) ? c-0xa2 : (0x837e >= c && c >= 0x8340) ? c - 0xa1 : c; } inline unsigned short jtokata(unsigned short c) {return (0x8393-0xa2 >= c && c >= 0x8380-0xa2) ? c+0xa2 : (0x837e-0xa1 >= c && c >= 0x8340-0xa1) ? c + 0xa1 : c; } inline int jiszen(unsigned short c) {int a = c >> 8, b = (unsigned char)c; return (iskanji(a) && iskanji2(b));} inline int chkctype(char c, int ct) {return (ct != 1) ? (iskanji(c) ? CT_KJ1 : (c) ? CT_ANK : CT_ILGL) : (iskanji2(c) ? CT_KJ2 : CT_ILGL);} #define jiskana(c) jiskata(c) #else /* inline が使えない場合はマクロ。副作用があるので注意 */ #define iskanji(c) ((unsigned)(((unsigned char)(c))^0x20) - 0xA1 < 0x3C) /*#define iskanji(c) (((unsigned char)(c) >= 0x81 && ((unsigned char)(c) <= 0x9F || ((unsigned char)(c) >= 0xE0 && (unsigned char)(c) <= 0xFC))))*/ #define iskanji2(c) (((unsigned char)(c) >= 0x40 && (unsigned char)(c) <= 0xfc && (unsigned char)(c) != 0x7f)) #define iskana(c) (((unsigned char)(c) >= 0xA1 && (unsigned char)(c) <= 0xDF)) #define iskmoji(c) (((unsigned char)(c) >= 0xA6 && (unsigned char)(c) <= 0xDF)) #define iskpun(c) (((unsigned char)(c) >= 0xA1 && (unsigned char)(c) <= 0xA5)) #define isalkana(c) (iskmoji(c) || isalpha(c)) #define isalnmkana(c) (iskmoji(c) || isalnum(c)) #define isgrkana(c) (iskana(c) || isgraph(c)) #define ispnkana(c) (iskpun(c) || ispunct(c)) #define isprkana(c) (iskana(c) || isprint(c)) #define jisspace(c) ((c) == 0x8140) #define jiskigou(c) ((c) <= 0x81ac && (c) >= 0x8141/*、*/ && (c) != 0x817f) #define jisdigit(c) ((c) <= 0x8258/*9*/ && (c) >= 0x824F/*0*/) #define jisupper(c) ((c) <= 0x8279/*Z*/ && (c) >= 0x8260/*A*/) #define jislower(c) ((c) <= 0x829a/*z*/ && (c) >= 0x8281/*a*/) #define jisalpha(c) (jisupper(c) || jislower(c)) #define jishira(c) ((c) <= 0x82F1/*ん*/ && (c) >= 0x829f/*ぁ*/) #define jiskata(c) ((c) <= 0x8396/**/ && (c) >= 0x8340/*ァ*/ && (c) != 0x837f) #define jisl0(c) ((c) <= 0x889e && jiszen(c)) #define jisl1(c) (0x889f <= (c) && (c) <= 0x9872 && jiszen(c)) #define jisl2(c) (0x989f <= (c) && (c) <= 0xea9e && jiszen(c)) #define jtolower(c) ((0x8279 >= (c) && (c) >= 0x8260) ? (c)+0x21 : (((c) < 0x80) && isupper(c)) ? tolower(c) : (c)) #define jtoupper(c) ((0x829a >= (c) && (c) >= 0x8281) ? (c)-0x21 : (((c) < 0x80) && islower(c)) ? toupper(c) : (c)) #define jtohira(c) ((0x8393/*8396*/ >= (c) && (c) >= 0x8380) ? (c)-0xa2 : (0x837e >= (c) && (c) >= 0x8340) ? (c) - 0xa1 : (c)) #define jtokata(c) ((0x8393-0xa2 >= (c) && (c) >= 0x8380-0xa2) ? (c)+0xa2 : (0x837e-0xa1 >= (c) && (c) >= 0x8340-0xa1) ? (c) + 0xa1 : (c)) #define jiszen(c) (iskanji((unsigned char)((c)>>8)) && iskanji2((unsigned char)(c))) #define chkctype(c,ct) (((ct) != 1) ? (iskanji(c) ? CT_KJ1 : (c) ? CT_ANK : CT_ILGL) : (iskanji2(c) ? CT_KJ2 : CT_ILGL)) #define jiskana(c) jiskata(c) #endif unsigned short hantozen(unsigned short c); unsigned short zentohan(unsigned short ms); unsigned short mstojis(unsigned short ms); unsigned short jistoms(unsigned short jis); int nthctype(const char *src, int nbyte); #define CT_ANK (0) #define CT_KJ1 (1) #define CT_KJ2 (2) #define CT_ILGL (-1) #define jmstojis mstojis #define jistojms jistoms #ifdef __cplusplus } #endif #endif /* _JCTYPE_H_ */