OSDN Git Service

4c3c371e3feb50b96ebd4306ed73bc1da0172b5e
[dokopop/dokopop.git] / DCHookTest / StringLib.h
1 //---------------------------------------------------------------------------
2 #ifndef StringLibH
3 #define StringLibH
4 //---------------------------------------------------------------------------
5
6 #include <mbctype.h>
7
8 // Constants //
9 #define CODE_APOSTROPHE 0x9188  // \81f
10
11 // typedefs and macros //
12 #ifdef USE_UNICODE
13 typedef wchar_t tuchar;
14 typedef wchar_t tchar;
15 #define LD_CHAR(c,p)    c = *p++;
16 #define ST_CHAR(c,p)    *p++ = c;
17 #define MOV_CHAR(p,q)   *p++ = *q++;
18 #define IS_ENDCHAR(c)   (!(c))
19 #define NEXT_CHAR(p)    CharNextW(p)
20 #undef _tcslen
21 #define _tcslen                 wcslen
22 #define _t(x)                   L##x
23 #define mustr                           __mustr
24 #include "mustr.h"
25 #else
26 typedef unsigned char tuchar;
27 typedef char tchar;
28 #define LD_CHAR(c, p)   {c = (unsigned char)*(*(unsigned char**)&p)++; if(_ismbblead(c)) c = (unsigned short)(((unsigned short)c << 8) + (unsigned char)*(*(unsigned char**)&p)++);}
29 #define ST_CHAR(c, p)   {if ((unsigned short)c > 0x100) *(*(unsigned char**)&p)++ = (unsigned char)(c >> 8); *(*(unsigned char**)&p)++ = (unsigned char)c;}
30 #define MOV_CHAR(p, q)  { unsigned char c = *(*(unsigned char**)&q)++ = *(*(unsigned char**)&p)++; if ( _ismbblead( c ) ) *(*(unsigned char**)&q)++ = *(*(unsigned char**)&p)++; }
31 #define IS_ENDCHAR(c)   (!((unsigned char)(c)))
32 #define NEXT_CHAR(p)    CharNextA(p)
33 #define _tcslen                 strlen
34 #define _t(x)                   x
35 #define mustr(s)                        (s)
36 #endif
37
38 typedef unsigned int uint;
39 typedef unsigned short ushort;
40
41 #define STR_DIFF( p1, p2 )      ( (uint)( (tchar*)(p1) - (tchar*)(p2) ) )
42
43 // prototypes //
44 int isalphanum( tuchar c );
45 bool mbIsWordChar( unsigned short c );
46 BOOL GetWord( const tchar *str, int pos, int &start, int &end, int &prevstart, bool fLongest, int wordcount, bool about, bool alnum );
47 bool mbGetWord( const tchar *str, int pos, int &start, int &end, bool fLongest, int wordcount );
48
49 // inlines //
50 inline bool IsWordChar( tuchar c )
51 {
52 #ifdef _UNICODE
53         WORD ct;
54         GetStringTypeW(CT_CTYPE1,&c,1,&ct);
55         return (ct & (C1_ALPHA|C1_DIGIT)) || c=='-' || c==CODE_JPROLONG || c=='\'' || c=='_';
56 #else
57         return isalphanum( c ) || c == '-' || c == '\'' || c >= 0xc0;
58 #endif
59 }
60 #if 0
61 inline bool IsNotWordChar( tuchar c )
62 {
63 #ifdef USE_UNICODE
64         WORD ct;
65         GetStringTypeW(CT_CTYPE1,&c,1,&ct);
66         return (ct & (C1_SPACE|C1_PUNCT|C1_CNTRL|C1_BLANK)) ? true : false;
67 #else
68         return !IsWordChar(c);
69 #endif
70 }
71 #endif
72
73 #endif
74