From a055933e10b65ea35817ff2dddf63a9b96ee25fe Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Tue, 12 Aug 2014 13:33:25 +0900 Subject: [PATCH] Unified the same debug messages. --- taglib/toolkit/tstring.cpp | 47 ++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index 9bed6180..b311cfbb 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -52,14 +52,11 @@ namespace inline size_t UTF16toUTF8( const wchar_t *src, size_t srcLength, char *dst, size_t dstLength) { + size_t len = 0; + #ifdef _WIN32 - const int len = ::WideCharToMultiByte( - CP_UTF8, 0, src, srcLength, dst, dstLength, NULL, NULL); - if(len == 0) { - debug("String::UTF16toUTF8() - Unicode conversion error."); - } - return len; + len = ::WideCharToMultiByte(CP_UTF8, 0, src, srcLength, dst, dstLength, NULL, NULL); #else @@ -74,29 +71,25 @@ namespace ConversionResult result = ConvertUTF16toUTF8( &srcBegin, srcEnd, &dstBegin, dstEnd, lenientConversion); - if(result == conversionOK) { - return (dstBegin - reinterpret_cast(dst)); - } - else - { - debug("String::UTF16toUTF8() - Unicode conversion error."); - return 0; - } + if(result == conversionOK) + len = dstBegin - reinterpret_cast(dst); #endif + + if(len == 0) + debug("String::UTF16toUTF8() - Unicode conversion error."); + + return len; } inline size_t UTF8toUTF16( const char *src, size_t srcLength, wchar_t *dst, size_t dstLength) { + size_t len = 0; + #ifdef _WIN32 - const int len = ::MultiByteToWideChar( - CP_UTF8, 0, src, srcLength, dst, dstLength); - if(len == 0) { - debug("String::UTF8toUTF16() - Unicode conversion error."); - } - return len; + len = ::MultiByteToWideChar(CP_UTF8, 0, src, srcLength, dst, dstLength); #else @@ -111,15 +104,15 @@ namespace ConversionResult result = ConvertUTF8toUTF16( &srcBegin, srcEnd, &dstBegin, dstEnd, lenientConversion); - if(result == conversionOK) { - return (dstBegin - dst); - } - else { - debug("String::UTF8toUTF16() - Unicode conversion error."); - return 0; - } + if(result == conversionOK) + len = dstBegin - dst; #endif + + if(len == 0) + debug("String::UTF8toUTF16() - Unicode conversion error."); + + return len; } }