16#pragma comment(user,"T-Coverage Disable")
47 static bool IsKanji(
int c)
49 return ((c >= 0x81 && c <= 0x9F) || (c >= 0xE0 && c <= 0xFC));
52 static bool IsHankaku(
int c)
54 return (c >= 0xa0 && c <= 0xdf);
63 static int ms_HanToZen(WORD& _zenkaku,
const BYTE* P)
65 const static WORD z[64] =
67 0x2121, 0x2123, 0x2156, 0x2157, 0x2122, 0x2126, 0x2572, 0x2521,
68 0x2523, 0x2525, 0x2527, 0x2529, 0x2563, 0x2565, 0x2567, 0x2543,
69 0x213c, 0x2522, 0x2524, 0x2526, 0x2528, 0x252a, 0x252b, 0x252d,
70 0x252f, 0x2531, 0x2533, 0x2535, 0x2537, 0x2539, 0x253b, 0x253d,
71 0x253f, 0x2541, 0x2544, 0x2546, 0x2548, 0x254a, 0x254b, 0x254c,
72 0x254d, 0x254e, 0x254f, 0x2552, 0x2555, 0x2558, 0x255b, 0x255e,
73 0x255f, 0x2560, 0x2561, 0x2562, 0x2564, 0x2566, 0x2568, 0x2569,
74 0x256a, 0x256b, 0x256c, 0x256d, 0x256f, 0x2573, 0x212b, 0x212c
83 const static TMark marks1[] =
85 {0xb3, 0x2574}, {0xb6, 0x252c}, {0xb7, 0x252e}, {0xb8, 0x2530},
86 {0xb9, 0x2532}, {0xba, 0x2534}, {0xbb, 0x2536}, {0xbc, 0x2538},
87 {0xbd, 0x253a}, {0xbe, 0x253c}, {0xbf, 0x253e}, {0xc0, 0x2540},
88 {0xc1, 0x2542}, {0xc2, 0x2545}, {0xc3, 0x2547}, {0xc4, 0x2549},
89 {0xca, 0x2550}, {0xcb, 0x2553}, {0xcc, 0x2556}, {0xcd, 0x2559},
90 {0xce, 0x255c}, {0, 0}
93 const static TMark marks2[] =
95 {0xca, 0x2551}, {0xcb, 0x2554}, {0xcc, 0x2557}, {0xcd, 0x255a},
96 {0xce, 0x255d}, {0, 0}
100 loop ( i, countof(marks1) )
102 if ( P[0] == marks1[i].han )
104 _zenkaku = marks1[i].zen;
109 else if ( P[1] == 0xdf )
111 loop ( i, countof(marks2) )
113 if ( P[0] == marks2[i].han )
115 _zenkaku = marks2[i].zen;
121 ASSERT( r >= 0 && r < countof(z) );
130 static void ms_SjisToJis(UINT *ph, UINT *pl)
138 *ph = (*ph << 1) - 0xE1;
142 *ph = (*ph << 1) - 0xE0;
149 *ph = (*ph << 1) - 0x161;
153 *ph = (*ph << 1) - 0x160;
160 else if ( *pl < 0x9F )
176 static INT_PTR ms_SjisToIso2022jp(LPCSTR pSjis, LPSTR pIso2022)
178 const BYTE* p =
reinterpret_cast<const BYTE*
>(pSjis);
179 BYTE* r =
reinterpret_cast<BYTE*
>(pIso2022);
180 bool isKanji =
false;
182 while ( (c = *(p++)) !=
'\0')
186 if ( IsKanji(c) || IsHankaku(c) )
194 ms_SjisToJis(&c, &d);
195 *(r++) =
static_cast<BYTE
>(c);
196 *(r++) =
static_cast<BYTE
>(d);
201 int rc = ms_HanToZen(e, p - 1);
206 *(r++) =
static_cast<BYTE
>((e >> 8) & 0xff);
207 *(r++) =
static_cast<BYTE
>(e & 0xff);
213 *(r++) =
static_cast<BYTE
>(c);
218 if ( ! IsKanji(c) && ! IsHankaku(c) )
223 *(r++) =
static_cast<BYTE
>(c);
231 ms_SjisToJis(&c, &d);
232 *(r++) =
static_cast<BYTE
>(c);
233 *(r++) =
static_cast<BYTE
>(d);
238 int rc = ms_HanToZen(e, p - 1);
243 *(r++) =
static_cast<BYTE
>((e >> 8) & 0xff);
244 *(r++) =
static_cast<BYTE
>(e & 0xff);
256 return r -
reinterpret_cast<BYTE*
>(pIso2022);
263 static void ms_JisToSjis(UINT* ph, UINT* pl)
265 if ( (*ph & 1) != 0 )
282 *ph = (*ph + 0xE1) >> 1;
286 *ph = (*ph + 0x161) >> 1;
295 static INT_PTR ms_Iso2022jpToSjis(LPCSTR pIso2022, LPSTR pSjis)
300 bool jiskanji =
false;
301 bool hankaku =
false;
313 if ( (c = *(p++)) ==
'$' )
315 if ( (c = *(p++)) ==
'@' || c ==
'B' )
325 *(r++) =
static_cast<BYTE
>(c);
331 if ( (c = *(p++)) ==
'H' || c ==
'J' || c ==
'B' )
342 *(r++) =
static_cast<BYTE
>(c);
348 if ( (c = *(p++)) ==
'B' )
357 else if ( hankaku && c ==
'N' )
360 *(r++) =
static_cast<BYTE
>(c + 0x80);
375 *(r++) =
static_cast<BYTE
>(c);
379 else if ( jiskanji && (c ==
'\r' || c ==
'\n') )
382 *(r++) =
static_cast<BYTE
>(c);
384 else if ( jiskanji && c >= 0x21 && c <= 0x7E )
390 if ( (d = *(p++)) >= 0x21 && d <= 0x7E )
392 ms_JisToSjis(&c, &d);
394 *(r++) =
static_cast<BYTE
>(c);
397 *(r++) =
static_cast<BYTE
>(d);
400 else if ( c >= 0xA1 && c <= 0xFE )
406 if ( (d = *(p++)) >= 0xA1 && d <= 0xFE )
410 ms_JisToSjis(&c, &d);
412 *(r++) =
static_cast<BYTE
>(c);
415 *(r++) =
static_cast<BYTE
>(d);
418 else if ( c == 0x0E )
420 while ( *p !=
'\0' && *p != 0x0F && *p !=
'\r' && *p !=
'\n' && *p != ESC )
422 *(r++) =
static_cast<BYTE
>(*(p++) + 0x80);
431 *(r++) =
static_cast<BYTE
>(c);
486 m_vtcText = other.m_vtcText;
526 if ( lpszJis == NULL )
553 TTRACE0(
"SJIS 文字列を JIS 文字列に変換\n");
554 if ( lpszAscii != NULL )
559 INT_PTR r = ms_SjisToIso2022jp(lpszAscii, m_vtcText.
GetBuffer(len * 4 + 1));
560 ASSERT( r <
static_cast<INT_PTR
>(len * 4 + 1));
576 m_vtcText += j.m_vtcText;
614 TTRACE0(
"Jis 文字列を S-JIS文字列に変換\n");
617 size_t r = ms_Iso2022jpToSjis(m_vtcText, asc.
GetBuffer(len));
642 operator LPCSTR (
void)
const
670 m_vtcText = s.m_vtcText;
693#pragma comment(user,"T-Coverage Enable")
#define loop(VAR, CNT)
loop構文.
virtual INT_PTR Compare(const CJisStr &t) const
[確認] 比較
CJisStr(const CJisStr &other)
コピーコンストラクタ
void SetOfUnicode(LPCWSTR lpszUnicode)
[設定] 代入(UNICODE用)
bool IsEmpty(void) const
[確認] 空か
CJisStr(const CUnicode &unicode)
代入コンストラクタ(UNICODE用)
CJisStr(const CAscii &ascii)
代入コンストラクタ(ASCII用)
void ReleaseBuffer(void)
[操作] 割り当てたバッファを開放.
CJisStr & operator+=(const CJisStr &j)
[追加] 追加オペレータ
size_t GetLength(void) const
[取得] JIS文字列長さ
CUnicode ToUnicode(void) const
[取得] UNICODE文字列取得
CJisStr & operator=(const CJisStr &other)
[代入] コピーオペレータ
static CJisStr ToJis(LPCSTR lpszAscii)
[変換] JISに変換
void SetOfJis(LPCSTR lpszJis)
[設定] 代入(JIS用)
CStr ToStr(void) const
[取得] 文字列取得
void SetOfAscii(LPCSTR lpszAscii)
[設定] 代入(ASCII用)
CAscii ToAscii(void) const
[取得] ASCII文字列取得
CJisStr(LPCSTR lpszJis)
代入コンストラクタ(JIS用)
LPSTR GetBuffer(int iLength)
[操作] 書き込みバッファ要求
LPCSTR ReferBuffer(void) const
[取得] JIS文字列参照取得
CJisStr operator+(const CJisStr &j) const
[作成] 加算オペレータ
void ReleaseBuffer(void)
[操作] 割り当てたバッファを開放.
size_t GetLength(void) const
[取得] 文字列長
TYP * GetBuffer(size_t iLength=0)
[操作] 書き込みバッファ要求.
int Compare(LPCSTR P1, LPCSTR P2, INT_PTR len=-1, DWORD dwCmpFlags=0)
[比較] 文字列比較(ASCII/SJIS用)
size_t GetLen(LPCSTR lpsz)
[計算] 文字列長計算(ASCII/SJIS用)
TNB::CStrT< char > CAscii
ASCII文字列クラス
TNB::CStrT< WCHAR > CUnicode
UNICODE文字列クラス
TNB::CStrT< TCHAR > CStr
文字列クラス
void MemCopy(T *_pDst, const void *pSrc, size_t len)
[複製] メモリコピー