mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Fixed issues with unsigned to signed conversion.
Added format.h to VS2022 project. Added format.h to syntax check CMakeLists.txt
This commit is contained in:
parent
8c90eb8ba8
commit
d98c3ac903
@ -914,17 +914,17 @@ namespace etl
|
||||
{
|
||||
if (value <= 9)
|
||||
{
|
||||
*it = '0' + value;
|
||||
*it = static_cast<char_type>('0' + static_cast<typename etl::make_unsigned<T>::type>(value));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (spec.type.has_value() && is_uppercase(spec.type.value()))
|
||||
{
|
||||
*it = 'A' + (value - 10);
|
||||
*it = static_cast<char_type>('A' + static_cast<typename etl::make_unsigned<T>::type>(value - 10));
|
||||
}
|
||||
else
|
||||
{
|
||||
*it = 'a' + (value - 10);
|
||||
*it = static_cast<char_type>('a' + static_cast<typename etl::make_unsigned<T>::type>(value - 10));
|
||||
}
|
||||
}
|
||||
++it;
|
||||
@ -955,7 +955,7 @@ namespace etl
|
||||
{
|
||||
using UnsignedT = typename etl::make_unsigned<T>::type;
|
||||
|
||||
UnsignedT unsigned_value = static_cast<UnsignedT>(value < 0 ? -value : value);
|
||||
UnsignedT unsigned_value = etl::absolute_unsigned(value);
|
||||
|
||||
size_t base = base_from_spec<default_base>(spec);
|
||||
UnsignedT highest_digit = get_highest_digit<UnsignedT>(unsigned_value, base);
|
||||
@ -2195,10 +2195,7 @@ namespace etl
|
||||
{
|
||||
private_format::output<OutputIt>(fmt_context, c);
|
||||
}
|
||||
};
|
||||
|
||||
// plain strings need it, back insert iterators don't:
|
||||
//*fmt_context.out() = '\0';
|
||||
}
|
||||
|
||||
return fmt_context.out();
|
||||
}
|
||||
|
||||
@ -199,6 +199,7 @@ target_sources(tests PRIVATE
|
||||
flat_multiset.h.t.cpp
|
||||
flat_set.h.t.cpp
|
||||
fnv_1.h.t.cpp
|
||||
format.h.t.cpp
|
||||
format_spec.h.t.cpp
|
||||
forward_list.h.t.cpp
|
||||
frame_check_sequence.h.t.cpp
|
||||
|
||||
29
test/syntax_check/format.h.t.cpp
Normal file
29
test/syntax_check/format.h.t.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2025 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#include <etl/format.h>
|
||||
@ -80,8 +80,8 @@ namespace
|
||||
CHECK_EQUAL("1 2", test_format(s, "{} {}", 1, 2));
|
||||
CHECK_EQUAL("-123", test_format(s, "{}", -123));
|
||||
CHECK_EQUAL("-314748364", test_format(s, "{}", (int)-314748364));
|
||||
CHECK_EQUAL("2147483647", test_format(s, "{}", (int)2147483647));
|
||||
CHECK_EQUAL("-2147483648", test_format(s, "{}", (int)-2147483648));
|
||||
CHECK_EQUAL("2147483647", test_format(s, "{}", INT32_MAX));
|
||||
CHECK_EQUAL("-2147483648", test_format(s, "{}", INT32_MIN));
|
||||
CHECK_EQUAL("0", test_format(s, "{}", 0));
|
||||
CHECK_EQUAL("-1", test_format(s, "{}", -1));
|
||||
}
|
||||
|
||||
@ -3465,6 +3465,7 @@
|
||||
<ClInclude Include="..\..\include\etl\buffer_descriptors.h" />
|
||||
<ClInclude Include="..\..\include\etl\byte.h" />
|
||||
<ClInclude Include="..\..\include\etl\byte_stream.h" />
|
||||
<ClInclude Include="..\..\include\etl\callback.h" />
|
||||
<ClInclude Include="..\..\include\etl\callback_timer.h" />
|
||||
<ClInclude Include="..\..\include\etl\callback_timer_atomic.h" />
|
||||
<ClInclude Include="..\..\include\etl\callback_timer_deferred_locked.h" />
|
||||
@ -6772,6 +6773,26 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - Force C++03|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - Force C++03 - No virtual messages|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\syntax_check\format.h.t.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - No virtual imessage|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++ 20 - No Tests|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++23 - No STL|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++23|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - No STL|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++14|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release MSVC C++20 - No STL - Optimised -O2|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release MSVC C++20 - No STL - Optimised -O2 - Sanitiser|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - Force C++03 - No virtual messages|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++17|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++17 - No STL|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release MSVC C++20 - Optimised O2|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - No virtual messages|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++14 - No STL|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - Force C++03|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Clang C++20|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Clang C++20 - Optimised -O2|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\syntax_check\format_spec.h.t.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Clang C++20|Win32'">true</ExcludedFromBuild>
|
||||
@ -10321,6 +10342,7 @@
|
||||
<ClCompile Include="..\test_delegate_observable.cpp" />
|
||||
<ClCompile Include="..\test_etl_assert.cpp" />
|
||||
<ClCompile Include="..\test_expected.cpp" />
|
||||
<ClCompile Include="..\test_format.cpp" />
|
||||
<ClCompile Include="..\test_function_traits.cpp" />
|
||||
<ClCompile Include="..\test_hfsm_recurse_to_inner_state_on_start.cpp" />
|
||||
<ClCompile Include="..\test_hfsm_transition_on_enter.cpp" />
|
||||
|
||||
@ -1527,6 +1527,9 @@
|
||||
<ClInclude Include="..\..\include\etl\crc64_iso.h">
|
||||
<Filter>ETL\Maths\CRC</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\callback.h">
|
||||
<Filter>ETL\Utilities</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\test_string_char.cpp">
|
||||
@ -3737,6 +3740,12 @@
|
||||
<ClCompile Include="..\test_signal.cpp">
|
||||
<Filter>Tests\Callbacks & Delegates</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\syntax_check\format.h.t.cpp">
|
||||
<Filter>Tests\Syntax Checks\Source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_format.cpp">
|
||||
<Filter>Tests\Strings</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\library.properties">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user