mirror of
https://github.com/ETLCPP/etl.git
synced 2026-07-30 16:26:17 +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
e669709a87
commit
ee688e21e6
@ -914,17 +914,17 @@ namespace etl
|
|||||||
{
|
{
|
||||||
if (value <= 9)
|
if (value <= 9)
|
||||||
{
|
{
|
||||||
*it = '0' + value;
|
*it = static_cast<char_type>('0' + static_cast<typename etl::make_unsigned<T>::type>(value));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (spec.type.has_value() && is_uppercase(spec.type.value()))
|
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
|
else
|
||||||
{
|
{
|
||||||
*it = 'a' + (value - 10);
|
*it = static_cast<char_type>('a' + static_cast<typename etl::make_unsigned<T>::type>(value - 10));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++it;
|
++it;
|
||||||
@ -955,7 +955,7 @@ namespace etl
|
|||||||
{
|
{
|
||||||
using UnsignedT = typename etl::make_unsigned<T>::type;
|
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);
|
size_t base = base_from_spec<default_base>(spec);
|
||||||
UnsignedT highest_digit = get_highest_digit<UnsignedT>(unsigned_value, base);
|
UnsignedT highest_digit = get_highest_digit<UnsignedT>(unsigned_value, base);
|
||||||
@ -2195,10 +2195,7 @@ namespace etl
|
|||||||
{
|
{
|
||||||
private_format::output<OutputIt>(fmt_context, c);
|
private_format::output<OutputIt>(fmt_context, c);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// plain strings need it, back insert iterators don't:
|
|
||||||
//*fmt_context.out() = '\0';
|
|
||||||
|
|
||||||
return fmt_context.out();
|
return fmt_context.out();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -198,6 +198,7 @@ target_sources(tests PRIVATE
|
|||||||
flat_multiset.h.t.cpp
|
flat_multiset.h.t.cpp
|
||||||
flat_set.h.t.cpp
|
flat_set.h.t.cpp
|
||||||
fnv_1.h.t.cpp
|
fnv_1.h.t.cpp
|
||||||
|
format.h.t.cpp
|
||||||
format_spec.h.t.cpp
|
format_spec.h.t.cpp
|
||||||
forward_list.h.t.cpp
|
forward_list.h.t.cpp
|
||||||
frame_check_sequence.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("1 2", test_format(s, "{} {}", 1, 2));
|
||||||
CHECK_EQUAL("-123", test_format(s, "{}", -123));
|
CHECK_EQUAL("-123", test_format(s, "{}", -123));
|
||||||
CHECK_EQUAL("-314748364", test_format(s, "{}", (int)-314748364));
|
CHECK_EQUAL("-314748364", test_format(s, "{}", (int)-314748364));
|
||||||
CHECK_EQUAL("2147483647", test_format(s, "{}", (int)2147483647));
|
CHECK_EQUAL("2147483647", test_format(s, "{}", INT32_MAX));
|
||||||
CHECK_EQUAL("-2147483648", test_format(s, "{}", (int)-2147483648));
|
CHECK_EQUAL("-2147483648", test_format(s, "{}", INT32_MIN));
|
||||||
CHECK_EQUAL("0", test_format(s, "{}", 0));
|
CHECK_EQUAL("0", test_format(s, "{}", 0));
|
||||||
CHECK_EQUAL("-1", test_format(s, "{}", -1));
|
CHECK_EQUAL("-1", test_format(s, "{}", -1));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3465,6 +3465,7 @@
|
|||||||
<ClInclude Include="..\..\include\etl\buffer_descriptors.h" />
|
<ClInclude Include="..\..\include\etl\buffer_descriptors.h" />
|
||||||
<ClInclude Include="..\..\include\etl\byte.h" />
|
<ClInclude Include="..\..\include\etl\byte.h" />
|
||||||
<ClInclude Include="..\..\include\etl\byte_stream.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.h" />
|
||||||
<ClInclude Include="..\..\include\etl\callback_timer_atomic.h" />
|
<ClInclude Include="..\..\include\etl\callback_timer_atomic.h" />
|
||||||
<ClInclude Include="..\..\include\etl\callback_timer_deferred_locked.h" />
|
<ClInclude Include="..\..\include\etl\callback_timer_deferred_locked.h" />
|
||||||
@ -6750,6 +6751,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|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++20 - Force C++03 - No virtual messages|Win32'">true</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</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">
|
<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 MSVC C++20|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Clang C++20|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Clang C++20|Win32'">true</ExcludedFromBuild>
|
||||||
@ -10298,6 +10319,7 @@
|
|||||||
<ClCompile Include="..\test_delegate_observable.cpp" />
|
<ClCompile Include="..\test_delegate_observable.cpp" />
|
||||||
<ClCompile Include="..\test_etl_assert.cpp" />
|
<ClCompile Include="..\test_etl_assert.cpp" />
|
||||||
<ClCompile Include="..\test_expected.cpp" />
|
<ClCompile Include="..\test_expected.cpp" />
|
||||||
|
<ClCompile Include="..\test_format.cpp" />
|
||||||
<ClCompile Include="..\test_function_traits.cpp" />
|
<ClCompile Include="..\test_function_traits.cpp" />
|
||||||
<ClCompile Include="..\test_hfsm_recurse_to_inner_state_on_start.cpp" />
|
<ClCompile Include="..\test_hfsm_recurse_to_inner_state_on_start.cpp" />
|
||||||
<ClCompile Include="..\test_hfsm_transition_on_enter.cpp" />
|
<ClCompile Include="..\test_hfsm_transition_on_enter.cpp" />
|
||||||
|
|||||||
@ -1527,6 +1527,9 @@
|
|||||||
<ClInclude Include="..\..\include\etl\crc64_iso.h">
|
<ClInclude Include="..\..\include\etl\crc64_iso.h">
|
||||||
<Filter>ETL\Maths\CRC</Filter>
|
<Filter>ETL\Maths\CRC</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\include\etl\callback.h">
|
||||||
|
<Filter>ETL\Utilities</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\test_string_char.cpp">
|
<ClCompile Include="..\test_string_char.cpp">
|
||||||
@ -3737,6 +3740,12 @@
|
|||||||
<ClCompile Include="..\test_signal.cpp">
|
<ClCompile Include="..\test_signal.cpp">
|
||||||
<Filter>Tests\Callbacks & Delegates</Filter>
|
<Filter>Tests\Callbacks & Delegates</Filter>
|
||||||
</ClCompile>
|
</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>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\..\library.properties">
|
<None Include="..\..\library.properties">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user