diff --git a/plugins/libimhex/include/hex/helpers/utils.hpp b/plugins/libimhex/include/hex/helpers/utils.hpp index 0846f74ca..e02a49621 100644 --- a/plugins/libimhex/include/hex/helpers/utils.hpp +++ b/plugins/libimhex/include/hex/helpers/utils.hpp @@ -76,6 +76,38 @@ namespace hex { namespace hex { + std::string to_string(u128 value) { + char data[45] = { 0 }; + + u8 index = sizeof(data) - 2; + while (value != 0 && index != 0) { + data[index] = '0' + value % 10; + value /= 10; + index--; + } + + return std::string(data + index + 1); + } + + std::string to_string(s128 value) { + char data[45] = { 0 }; + + u128 unsignedValue = value < 0 ? -value : value; + + u8 index = sizeof(data) - 2; + while (unsignedValue != 0 && index != 0) { + data[index] = '0' + unsignedValue % 10; + unsignedValue /= 10; + index--; + } + + if (value < 0) { + data[index] = '-'; + return std::string(data + index); + } else + return std::string(data + index + 1); + } + template inline std::string format(const char *format, Args ... args) { ssize_t size = snprintf( nullptr, 0, format, args ... ); diff --git a/plugins/libimhex/source/lang/builtin_functions.cpp b/plugins/libimhex/source/lang/builtin_functions.cpp index eab1c268b..5e6e74830 100644 --- a/plugins/libimhex/source/lang/builtin_functions.cpp +++ b/plugins/libimhex/source/lang/builtin_functions.cpp @@ -122,8 +122,8 @@ namespace hex::lang { case Token::ValueType::Signed32Bit: message += std::to_string(std::get(integerLiteral->getValue())); break; case Token::ValueType::Unsigned64Bit: message += std::to_string(std::get(integerLiteral->getValue())); break; case Token::ValueType::Signed64Bit: message += std::to_string(std::get(integerLiteral->getValue())); break; - case Token::ValueType::Unsigned128Bit: message += "A lot"; break; // TODO: Implement u128 to_string - case Token::ValueType::Signed128Bit: message += "A lot"; break; // TODO: Implement s128 to_string + case Token::ValueType::Unsigned128Bit: message += hex::to_string(std::get(integerLiteral->getValue())); break; + case Token::ValueType::Signed128Bit: message += hex::to_string(std::get(integerLiteral->getValue())); break; case Token::ValueType::Float: message += std::to_string(std::get(integerLiteral->getValue())); break; case Token::ValueType::Double: message += std::to_string(std::get(integerLiteral->getValue())); break; case Token::ValueType::Boolean: message += std::get(integerLiteral->getValue()) ? "true" : "false"; break;