Skip to content

Commit af1837f

Browse files
authored
Merge pull request #2018 from gorogoro123/feature/remove_reinterpret_cast
reinterpret_cast 削除 (convert_util2.h)
2 parents 33641be + 4439c64 commit af1837f

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

sakura_core/convert/convert_util2.h

+20-20
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ int _DecodeQP( const CHAR_TYPE* pS, const int nLen, char* pDst )
9797

9898
while( pr < pS + nLen ){
9999
/* =XX の形式でない部分をデコード */
100-
if( sizeof(CHAR_TYPE) == 2 ){
100+
if constexpr ( sizeof(CHAR_TYPE) == 2 ){
101101
if( *pr != L'=' ){
102102
*pw = static_cast<char>( *pr );
103103
pw += 1;
@@ -221,7 +221,7 @@ int _DecodeBase64( const CHAR_TYPE *pSrc, const int nSrcLen, char *pDest )
221221
int i = 0;
222222
bool bret;
223223
for( ; i < nsrclen; i++ ){
224-
if( sizeof(CHAR_TYPE) == 2 ){
224+
if constexpr ( sizeof(CHAR_TYPE) == 2 ){
225225
bret = ( pSrc[nsrclen-1-i] == L'=' );
226226
}else{
227227
bret = ( pSrc[nsrclen-1-i] == '=' );
@@ -415,7 +415,7 @@ bool CheckUUHeader( const CHAR_TYPE *pSrc, const int nLen, WCHAR *pszFilename )
415415
// 先頭の空白・改行文字をスキップ
416416
for( nstartidx = 0; nstartidx < nLen; ++nstartidx ){
417417
CHAR_TYPE c = pSrc[nstartidx];
418-
if( sizeof(CHAR_TYPE) == 2 ){
418+
if constexpr ( sizeof(CHAR_TYPE) == 2 ){
419419
if( c != L'\r' && c != L'\n' && c != L' ' && c != L'\t' ){
420420
break;
421421
}
@@ -439,13 +439,13 @@ bool CheckUUHeader( const CHAR_TYPE *pSrc, const int nLen, WCHAR *pszFilename )
439439
// error.
440440
return false;
441441
}
442-
if( sizeof(CHAR_TYPE) == 2 ){
442+
if constexpr ( sizeof(CHAR_TYPE) == 2 ){
443443
if( wcsncmp_literal(pwstart, L"begin") != 0 ){
444444
// error.
445445
return false;
446446
}
447447
}else{
448-
if( strncmp_literal(reinterpret_cast<const char*>(pwstart), "begin") != 0 ){
448+
if( strncmp_literal(pwstart, "begin") != 0 ){
449449
// error.
450450
return false;
451451
}
@@ -459,7 +459,7 @@ bool CheckUUHeader( const CHAR_TYPE *pSrc, const int nLen, WCHAR *pszFilename )
459459
return false;
460460
}
461461
for( int i = 0; i < nwlen; i++ ){
462-
if( sizeof(CHAR_TYPE) == 2 ){
462+
if constexpr ( sizeof(CHAR_TYPE) == 2 ){
463463
// WCHAR の場合の処理
464464
if( !iswdigit(pwstart[i]) || (pwstart[i] == L'8' || pwstart[i] == L'9') ){
465465
// error.
@@ -480,7 +480,7 @@ bool CheckUUHeader( const CHAR_TYPE *pSrc, const int nLen, WCHAR *pszFilename )
480480
// 末尾の空白・改行文字をスキップ
481481
for( ; nwlen > 0; --nwlen ){
482482
CHAR_TYPE c = pwstart[nwlen-1];
483-
if( sizeof(CHAR_TYPE) == 2 ){
483+
if constexpr ( sizeof(CHAR_TYPE) == 2 ){
484484
if( !WCODE::IsLineDelimiterBasic(c) && c != L' ' && c != L'\t' ){
485485
break;
486486
}
@@ -521,7 +521,7 @@ bool CheckUUFooter( const CHAR_TYPE *pS, const int nLen )
521521
// 先頭の改行・空白文字をスキップ
522522
for( nstartidx = 0; nstartidx < nLen; ++nstartidx ){
523523
CHAR_TYPE c = pS[nstartidx];
524-
if( sizeof(CHAR_TYPE) == 2 ){
524+
if constexpr ( sizeof(CHAR_TYPE) == 2 ){
525525
// WCHAR の場合の処理
526526
if( c != L'\r' && c != L'\n' && c != L' ' && c != L'\t' ){
527527
break;
@@ -541,13 +541,13 @@ bool CheckUUFooter( const CHAR_TYPE *pS, const int nLen )
541541
if( nsrclen < 3 ){
542542
return false;
543543
}
544-
if( sizeof(CHAR_TYPE) == 2 ){
544+
if constexpr ( sizeof(CHAR_TYPE) == 2 ){
545545
if( wcsncmp_literal(&pS[nstartidx], L"end") != 0 ){
546546
// error.
547547
return false;
548548
}
549549
}else{
550-
if( strncmp_literal(reinterpret_cast<const char*>(&pS[nstartidx]), "end") != 0 ){
550+
if( strncmp_literal(&pS[nstartidx], "end") != 0 ){
551551
// error.
552552
return false;
553553
}
@@ -557,7 +557,7 @@ bool CheckUUFooter( const CHAR_TYPE *pS, const int nLen )
557557
// end の後が空白文字ばかりであることを確認
558558
for( ; i < nsrclen; ++i ){
559559
CHAR_TYPE c = psrc[i];
560-
if( sizeof(CHAR_TYPE) == 2 ){
560+
if constexpr ( sizeof(CHAR_TYPE) == 2 ){
561561
// WCHAR の場合の処理
562562
if( !WCODE::IsLineDelimiterBasic(c) && c != L' ' && c != L'\t' ){
563563
return false;
@@ -613,8 +613,8 @@ int _DecodeMimeHeader( const CHAR_TYPE* pSrc, const int nSrcLen, CMemory* pcMem_
613613

614614
if( pSrc+14 < pSrc+nSrcLen ){
615615
// JIS の場合
616-
if( sizeof(CHAR_TYPE) == 2 ){
617-
ncmpresult = wcsnicmp_literal( reinterpret_cast<const wchar_t*>(&pSrc[0]), L"=?ISO-2022-JP?" );
616+
if constexpr ( sizeof(CHAR_TYPE) == 2 ){
617+
ncmpresult = wcsnicmp_literal( &pSrc[0], L"=?ISO-2022-JP?" );
618618
}else{
619619
ncmpresult = strnicmp_literal( &pSrc[0], "=?ISO-2022-JP?" );
620620
}
@@ -626,8 +626,8 @@ int _DecodeMimeHeader( const CHAR_TYPE* pSrc, const int nSrcLen, CMemory* pcMem_
626626
}
627627
if( pSrc+8 < pSrc+nSrcLen ){
628628
// UTF-8 の場合
629-
if( sizeof(CHAR_TYPE) == 2 ){
630-
ncmpresult = wcsnicmp_literal( reinterpret_cast<const wchar_t*>(&pSrc[0]), L"=?UTF-8?" );
629+
if constexpr ( sizeof(CHAR_TYPE) == 2 ){
630+
ncmpresult = wcsnicmp_literal( &pSrc[0], L"=?UTF-8?" );
631631
}else{
632632
ncmpresult = strnicmp_literal( &pSrc[0], "=?UTF-8?" );
633633
}
@@ -660,9 +660,9 @@ finish_first_detect:;
660660
pcMem_alt->SetRawData( "", 0 );
661661
return 0;
662662
}
663-
if( sizeof(CHAR_TYPE) == 2 ){
664-
ncmpresult1 = wcsnicmp_literal( reinterpret_cast<const wchar_t*>(&pSrc[nLen_part1]), L"B?" );
665-
ncmpresult2 = wcsnicmp_literal( reinterpret_cast<const wchar_t*>(&pSrc[nLen_part1]), L"Q?" );
663+
if constexpr ( sizeof(CHAR_TYPE) == 2 ){
664+
ncmpresult1 = wcsnicmp_literal( &pSrc[nLen_part1], L"B?" );
665+
ncmpresult2 = wcsnicmp_literal( &pSrc[nLen_part1], L"Q?" );
666666
}else{
667667
ncmpresult1 = strnicmp_literal( &pSrc[nLen_part1], "B?" );
668668
ncmpresult2 = strnicmp_literal( &pSrc[nLen_part1], "Q?" );
@@ -684,8 +684,8 @@ finish_first_detect:;
684684
pr_base = pSrc + nLen_part1 + nLen_part2;
685685
pr = pSrc + nLen_part1 + nLen_part2;
686686
for( ; pr < pSrc+nSrcLen-1; ++pr ){
687-
if( sizeof(CHAR_TYPE) == 2 ){
688-
ncmpresult = wcsncmp_literal( reinterpret_cast<const wchar_t*>(pr), L"?=" );
687+
if constexpr ( sizeof(CHAR_TYPE) == 2 ){
688+
ncmpresult = wcsncmp_literal( pr, L"?=" );
689689
}else{
690690
ncmpresult = strncmp_literal( pr, "?=" );
691691
}

0 commit comments

Comments
 (0)