From a6141cd95ba3e0a377937cff09ae3e028b593133 Mon Sep 17 00:00:00 2001 From: Antoine ELIAS Date: Thu, 10 Nov 2016 08:33:02 +0100 Subject: [PATCH] utf: output_stream 3 Change-Id: I7d7e2cfc5ae1e6ce23f014d4a35847ed58d53eff --- .../output_stream/sci_gateway/cpp/sci_mprintf.cpp | 2 - scilab/modules/output_stream/src/cpp/Diary.cpp | 24 +----------- .../modules/output_stream/src/cpp/getDiaryDate.cpp | 6 +-- .../output_stream/src/cpp/scilab_sprintf.cpp | 40 +++++--------------- 4 files changed, 15 insertions(+), 57 deletions(-) diff --git a/scilab/modules/output_stream/sci_gateway/cpp/sci_mprintf.cpp b/scilab/modules/output_stream/sci_gateway/cpp/sci_mprintf.cpp index c55074b..e0335cd 100644 --- a/scilab/modules/output_stream/sci_gateway/cpp/sci_mprintf.cpp +++ b/scilab/modules/output_stream/sci_gateway/cpp/sci_mprintf.cpp @@ -29,8 +29,6 @@ extern "C" #include "os_wtoi.h" } -int new_sprintf(const std::string& funcname, const wchar_t* _pwstInput, types::typed_list &in, int* _piOutputRows, int* _piNewLine, wchar_t*** output); - /*--------------------------------------------------------------------------*/ types::Callable::ReturnValue sci_mprintf(types::typed_list &in, int _iRetCount, types::typed_list &out) { diff --git a/scilab/modules/output_stream/src/cpp/Diary.cpp b/scilab/modules/output_stream/src/cpp/Diary.cpp index 5d4d42e..482cbfa 100644 --- a/scilab/modules/output_stream/src/cpp/Diary.cpp +++ b/scilab/modules/output_stream/src/cpp/Diary.cpp @@ -115,14 +115,7 @@ void Diary::write(const std::string& _str, bool bInput) { if ((PrefixIoModeFilter == PREFIX_FILTER_INPUT_AND_OUTPUT) || (PrefixIoModeFilter == PREFIX_FILTER_ONLY_INPUT)) { - char *timeInfo = wide_string_to_UTF8((wchar_t *) getDiaryDate(PrefixTimeFormat).c_str()); - - if (timeInfo) - { - fileDiary << timeInfo << " "; - FREE(timeInfo); - timeInfo = NULL; - } + fileDiary << getDiaryDate(PrefixTimeFormat) << " "; } if (line) { @@ -136,14 +129,7 @@ void Diary::write(const std::string& _str, bool bInput) { if ((PrefixIoModeFilter == PREFIX_FILTER_INPUT_AND_OUTPUT) || (PrefixIoModeFilter == PREFIX_FILTER_ONLY_OUTPUT)) { - char *timeInfo = wide_string_to_UTF8((wchar_t *) getDiaryDate(PrefixTimeFormat).c_str()); - - if (timeInfo) - { - fileDiary << timeInfo << " "; - FREE(timeInfo); - timeInfo = NULL; - } + fileDiary << getDiaryDate(PrefixTimeFormat) << " "; } if (line) { @@ -151,12 +137,6 @@ void Diary::write(const std::string& _str, bool bInput) } } } - - if (line) - { - FREE(line); - line = NULL; - } } fileDiary.close(); } diff --git a/scilab/modules/output_stream/src/cpp/getDiaryDate.cpp b/scilab/modules/output_stream/src/cpp/getDiaryDate.cpp index f5631d3..164aac1 100644 --- a/scilab/modules/output_stream/src/cpp/getDiaryDate.cpp +++ b/scilab/modules/output_stream/src/cpp/getDiaryDate.cpp @@ -55,9 +55,9 @@ std::string getDiaryDate(int format_mode) unsigned int MINUTES = nowstruct->tm_min; unsigned int SECONDS = nowstruct->tm_sec; - StrStream << YEAR << L"-" << MONTH << L"-" << DAY_OF_MONTH; - StrStream << L" "; - StrStream << HOUR_OF_DAY << L":" << MINUTES << L":" << SECONDS; + StrStream << YEAR << "-" << MONTH << "-" << DAY_OF_MONTH; + StrStream << " "; + StrStream << HOUR_OF_DAY << ":" << MINUTES << ":" << SECONDS; strdate = StrStream.str(); } break; diff --git a/scilab/modules/output_stream/src/cpp/scilab_sprintf.cpp b/scilab/modules/output_stream/src/cpp/scilab_sprintf.cpp index 80850c3..036de68 100644 --- a/scilab/modules/output_stream/src/cpp/scilab_sprintf.cpp +++ b/scilab/modules/output_stream/src/cpp/scilab_sprintf.cpp @@ -32,8 +32,7 @@ extern "C" } static char* replaceAndCountLines(const char* _pstInput, int* _piLines, int* _piNewLine); -static char* addl(TokenDef* token); -static void updatel(TokenDef* token); +static char* replacebys(TokenDef* token); #define NanString "Nan" #define InfString "Inf" @@ -341,11 +340,6 @@ char** scilab_sprintf(const std::string& funcname, const char* _pwstInput, types return nullptr; } - if (tok->length == false) - { - updatel(tok); - } - tok->outputType = types::InternalType::ScilabString; tok->pos = p; tok->col = c; @@ -438,7 +432,7 @@ char** scilab_sprintf(const std::string& funcname, const char* _pwstInput, types } else { - char* newToken = addl(tok); + char* newToken = replacebys(tok); if (std::isnan(dblVal)) { @@ -453,7 +447,7 @@ char** scilab_sprintf(const std::string& funcname, const char* _pwstInput, types os_sprintf(pstTemp, bsiz, newToken, InfString); } - delete[] newToken; + FREE(newToken); } oFirstOutput << pstTemp; @@ -491,7 +485,7 @@ char** scilab_sprintf(const std::string& funcname, const char* _pwstInput, types } else { - char* newToken = addl(tok); + char* newToken = replacebys(tok); if (std::isnan(dblVal)) { @@ -509,7 +503,7 @@ char** scilab_sprintf(const std::string& funcname, const char* _pwstInput, types } } - delete[] newToken; + FREE(newToken); } oFirstOutput << pstTemp; @@ -548,7 +542,7 @@ char** scilab_sprintf(const std::string& funcname, const char* _pwstInput, types } else { - char* newToken = addl(tok); + char* newToken = replacebys(tok); if (std::isnan(dblVal)) { @@ -566,7 +560,7 @@ char** scilab_sprintf(const std::string& funcname, const char* _pwstInput, types } } - delete[] newToken; + FREE(newToken); } oFirstOutput << pstTemp; @@ -779,25 +773,11 @@ static char* replaceAndCountLines(const char* _pstInput, int* _piLines, int* _pi return pstFirstOutput; } /*--------------------------------------------------------------------------*/ -char* addl(TokenDef* token) +char* replacebys(TokenDef* token) { - //replace %s or %c by %ls or %lc to wide char compatibility int iPos = token->typePos; - int sizeTotal = (int)strlen(token->pstToken); - char* pstToken = new char[sizeTotal + 2]; - - strncpy(pstToken, token->pstToken, iPos); - pstToken[iPos] = 'l'; - pstToken[iPos + 1] = 's'; - strncpy(&pstToken[iPos + 2], token->pstToken + iPos + 1, sizeTotal - (iPos + 1)); - pstToken[sizeTotal + 1] = '\0'; - + char* pstToken = os_strdup(token->pstToken); + pstToken[iPos] = 's'; return pstToken; } /*--------------------------------------------------------------------------*/ -void updatel(TokenDef* token) -{ - char* newToken = addl(token); - delete[] token->pstToken; - token->pstToken = newToken; -} -- 1.7.9.5