Skip to content

Commit

Permalink
Add missing STRING_TO_CHAR function
Browse files Browse the repository at this point in the history
  • Loading branch information
mx990 authored and azoitl committed Mar 21, 2024
1 parent 8289181 commit f916f46
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/core/datatypes/convert/StringToConvertFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ inline const CIEC_LREAL func_STRING_AS_LREAL(const CIEC_STRING &paVal){
return func_STRING_AS_X_helper<CIEC_LREAL>(paVal);
}

inline const CIEC_CHAR func_STRING_TO_CHAR(const CIEC_STRING &paVal){
return paVal.length() > 0 ? paVal[1] : 0_CHAR;
}

#ifdef FORTE_USE_WSTRING_DATATYPE
inline const CIEC_WSTRING func_STRING_TO_WSTRING(const CIEC_STRING &paVal){
return func_STRING_AS_X_helper<CIEC_WSTRING>(paVal);
Expand Down
8 changes: 7 additions & 1 deletion tests/core/datatypes/convert/convert_functionstests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,13 @@ BOOST_AUTO_TEST_SUITE(convert_functions)
BOOST_TEST(
static_cast<CIEC_LREAL::TValueType>(timeInNs) == static_cast<CIEC_LREAL::TValueType>(INT64_C(172800000000000) + INT64_C(18000000000000) + INT64_C(2580000000000) + INT64_C(12000000000) + INT64_C(44000000) + INT64_C(27000) + INT64_C(31)));
}


BOOST_AUTO_TEST_CASE(CONVERT_STRING_TO_CHAR) {
BOOST_TEST(static_cast<CIEC_CHAR::TValueType>(func_STRING_TO_CHAR(""_STRING)) == '\0');
BOOST_TEST(static_cast<CIEC_CHAR::TValueType>(func_STRING_TO_CHAR("a"_STRING)) == 'a');
BOOST_TEST(static_cast<CIEC_CHAR::TValueType>(func_STRING_TO_CHAR("abc"_STRING)) == 'a');
}

/**** BYTE_BCD_TO_* ****/
BOOST_AUTO_TEST_CASE(BYTE_BCD_TO_USINT) {
using SourceType = CIEC_BYTE;
Expand Down

0 comments on commit f916f46

Please sign in to comment.