diff --git a/CMakeLists.txt b/CMakeLists.txt index 6048b23..3ad35ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ include(cmake/fetch_content.cmake) # in code coverage computation as they are test programs themselves. set(EXTRA_COVERAGE_EXCLUSION "\'${CMAKE_CURRENT_SOURCE_DIR}/integration/*\'") -project(bofstd VERSION 5.7.3.2) +project(bofstd VERSION 5.7.3.3) if (EMSCRIPTEN) message("Force pthread detection for BofStd compilation under EMSCRIPTEN") diff --git a/lib/include/bofstd/boffs.h b/lib/include/bofstd/boffs.h index d36477e..7b62216 100644 --- a/lib/include/bofstd/boffs.h +++ b/lib/include/bofstd/boffs.h @@ -181,6 +181,7 @@ BOFSTD_EXPORT int64_t Bof_SetFileIoPosition(uintptr_t _Io, int64_t _Offset_S64, BOFSTD_EXPORT int64_t Bof_GetFileIoPosition(uintptr_t _Io); BOFSTD_EXPORT BOFERR Bof_ReadLine(uintptr_t _Io, uint32_t &_rNb_U32, char *_pBuffer_c); +BOFSTD_EXPORT BOFERR Bof_ReadLine(const BOF::BofPath &_rPath, std::vector &_rLineCollection); BOFSTD_EXPORT BOFERR Bof_ReadLine(uintptr_t _Io, std::string &_rLine_S); BOFSTD_EXPORT BOFERR Bof_WriteLine(uintptr_t _Io, const std::string &_rLine_S); diff --git a/lib/include/bofstd/bofstring.h b/lib/include/bofstd/bofstring.h index 9fc91c7..ca61e70 100644 --- a/lib/include/bofstd/bofstring.h +++ b/lib/include/bofstd/bofstring.h @@ -133,6 +133,8 @@ BOFSTD_EXPORT std::string Bof_StringReplace(const std::string &_rStr_S, const st // @return The new string with the 'replaced' substring // @remarks None BOFSTD_EXPORT std::string Bof_StringReplace(const std::string &_rStr_S, const std::string &_rStringToReplace_S, const std::string &_rReplaceString_S); +//_rTokenKey_S = "{reqNum}"; +BOFSTD_EXPORT std::string Bof_StringTokenReplace(const std::string &_rStr_S, const std::string &_rTokenKey_S, const std::string &_rTokenValue_S); // @brief Check if a string contains some specific characters // @param _rStr_S : Specifies the string to process diff --git a/lib/src/boffs.cpp b/lib/src/boffs.cpp index 8474617..1f951a1 100644 --- a/lib/src/boffs.cpp +++ b/lib/src/boffs.cpp @@ -781,6 +781,34 @@ BOFERR Bof_ReadLine(uintptr_t _Io, uint32_t &_rNb_U32, char *_pBuffer_c) return (Rts_E); } + +BOFERR Bof_ReadLine(const BOF::BofPath &_rPath, std::vector &_rLineCollection) +{ + BOFERR Rts_E = BOF_ERR_ENOENT; + FILE *pIo_X; + int Len_i; + char pBuffer_c[0x1000]; + std::stringstream Output; + + pIo_X = fopen(_rPath.FullPathName(false).c_str(), "rb"); + if (pIo_X != nullptr) + { + Rts_E = BOF_ERR_NO_ERROR; + while (!feof(pIo_X)) + { + Len_i = fread(pBuffer_c, 1, sizeof(pBuffer_c) - 1, pIo_X); //-1 for extra 0 + if (Len_i > 0) + { + pBuffer_c[Len_i] = 0; + Output << pBuffer_c; + } + } + fclose(pIo_X); + _rLineCollection = BOF::Bof_StringSplit(Output.str(), "\n"); + } + return (Rts_E); +} + BOFERR Bof_ReadLine(uintptr_t _Io, std::string &_rLine_S) { BOFERR Rts_E; diff --git a/lib/src/bofprocess.cpp b/lib/src/bofprocess.cpp index 35708ac..b1d19f3 100644 --- a/lib/src/bofprocess.cpp +++ b/lib/src/bofprocess.cpp @@ -547,7 +547,7 @@ BOFERR BofProcess::S_Execute_popen(const std::string &_rCommand_S, std::string & int Len_i; std::string Command_S; char pBuffer_c[0x1000]; - std::stringstream Output_S; + std::stringstream Output; _rOutput_S = ""; _rExitCode_i = 127; @@ -565,10 +565,10 @@ BOFERR BofProcess::S_Execute_popen(const std::string &_rCommand_S, std::string & if (Len_i > 0) { pBuffer_c[Len_i] = 0; - Output_S << pBuffer_c; + Output << pBuffer_c; } } - _rOutput_S = Output_S.str(); + _rOutput_S = Output.str(); //printf("Output: %zd:%s\n", _rOutput_S.size(), _rOutput_S.c_str()); // Grab the forked status _rExitCode_i = pclose(pPipe_X); diff --git a/lib/src/bofstring.cpp b/lib/src/bofstring.cpp index 0cdf051..9d3e592 100644 --- a/lib/src/bofstring.cpp +++ b/lib/src/bofstring.cpp @@ -157,7 +157,24 @@ std::string Bof_StringReplace(const std::string &_rStr_S, const std::string &_rS } return Rts_S; } +//_rTokenKey_S = "{reqNum}"; +std::string Bof_StringTokenReplace(const std::string &_rStr_S, const std::string &_rTokenKey_S, const std::string &_rTokenValue_S) +{ + std::string Rts_S, Tag_S; + size_t Pos, LenTag, LenValue; + + Rts_S = _rStr_S; + LenTag = _rTokenKey_S.size(); + LenValue = _rTokenValue_S.size(); + Pos = 0; + while ((Pos = Rts_S.find(_rTokenKey_S, Pos)) != std::string::npos) + { + Rts_S.replace(Pos, LenTag, _rTokenValue_S); + Pos += LenValue; + } + return Rts_S; +} bool Bof_StringIsPresent(const std::string &_rStr_S, const std::string &_rCharToLookFor_S) { return (_rStr_S.find_first_of(_rCharToLookFor_S) != std::string::npos); @@ -701,4 +718,7 @@ std::string Bof_Sprintf(const char *_pFormat_c, ...) } return Rts_S; } + + + END_BOF_NAMESPACE() \ No newline at end of file diff --git a/vcpkg.json b/vcpkg.json index 1550868..3e60728 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,6 +1,6 @@ { "name": "bofstd", - "version": "5.7.3.2", + "version": "5.7.3.3", "description": "The onbings general purpose C++ Multiplatform library", "dependencies": [ {