Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop dependency on lexical_cast and add more tests
- Loading branch information
Showing
21 changed files
with
172 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright Antony Polukhin, 2016-2018. | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. (See | ||
// accompanying file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#ifndef BOOST_STACKTRACE_DETAIL_TO_DEC_ARRAY_HPP | ||
#define BOOST_STACKTRACE_DETAIL_TO_DEC_ARRAY_HPP | ||
|
||
#include <boost/config.hpp> | ||
#ifdef BOOST_HAS_PRAGMA_ONCE | ||
# pragma once | ||
#endif | ||
|
||
#include <boost/array.hpp> | ||
|
||
namespace boost { namespace stacktrace { namespace detail { | ||
|
||
// We do not use boost::lexical_cast in this function to reduce module dependencies | ||
inline boost::array<char, 40> to_dec_array(std::size_t value) BOOST_NOEXCEPT { | ||
boost::array<char, 40> ret; | ||
if (!value) { | ||
ret[0] = '0'; | ||
ret[1] = '\0'; | ||
return ret; | ||
} | ||
|
||
std::size_t digits = 0; | ||
for (std::size_t value_copy = value; value_copy; value_copy /= 10) { | ||
++ digits; | ||
} | ||
|
||
for (std::size_t i = 1; i <= digits; ++i) { | ||
ret[digits - i] = '0' + (value % 10); | ||
value /= 10; | ||
} | ||
|
||
ret[digits] = '\0'; | ||
|
||
return ret; | ||
} | ||
|
||
|
||
}}} // namespace boost::stacktrace::detail | ||
|
||
#endif // BOOST_STACKTRACE_DETAIL_TO_DEC_ARRAY_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright Antony Polukhin, 2016-2018. | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. (See | ||
// accompanying file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#ifndef BOOST_STACKTRACE_DETAIL_TRY_DEC_CONVERT_HPP | ||
#define BOOST_STACKTRACE_DETAIL_TRY_DEC_CONVERT_HPP | ||
|
||
#include <boost/config.hpp> | ||
#ifdef BOOST_HAS_PRAGMA_ONCE | ||
# pragma once | ||
#endif | ||
|
||
#include <cstdlib> | ||
|
||
namespace boost { namespace stacktrace { namespace detail { | ||
|
||
// We do not use boost::lexical_cast in this function to reduce module dependencies | ||
inline bool try_dec_convert(const char* s, std::size_t& res) BOOST_NOEXCEPT { | ||
char* end_ptr = 0; | ||
res = std::strtoul(s, &end_ptr, 10); | ||
return *end_ptr == '\0'; | ||
} | ||
|
||
|
||
}}} // namespace boost::stacktrace::detail | ||
|
||
#endif // BOOST_STACKTRACE_DETAIL_TRY_DEC_CONVERT_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright Antony Polukhin, 2016-2018. | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. (See | ||
// accompanying file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#include <boost/stacktrace/detail/to_dec_array.hpp> | ||
#include <boost/stacktrace/detail/to_hex_array.hpp> | ||
#include <boost/stacktrace/detail/try_dec_convert.hpp> | ||
|
||
#include <boost/core/lightweight_test.hpp> | ||
|
||
|
||
void test_to_hex_array() { | ||
const void* ptr = 0; | ||
BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("0x0") != std::string::npos); | ||
|
||
ptr = reinterpret_cast<const void*>(0x10); | ||
BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("10") != std::string::npos); | ||
|
||
ptr = reinterpret_cast<void*>(0x19); | ||
BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("19") != std::string::npos); | ||
|
||
ptr = reinterpret_cast<void*>(0x999999); | ||
BOOST_TEST(std::string(boost::stacktrace::detail::to_hex_array(ptr).data()).find("999999") != std::string::npos); | ||
} | ||
|
||
void test_to_dec_array() { | ||
BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(0).data()), std::string("0")); | ||
BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(10).data()), std::string("10")); | ||
BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(19).data()), std::string("19")); | ||
BOOST_TEST_EQ(std::string(boost::stacktrace::detail::to_dec_array(999999).data()), std::string("999999")); | ||
} | ||
|
||
void test_try_dec_convert() { | ||
std::size_t res = 0; | ||
|
||
BOOST_TEST(boost::stacktrace::detail::try_dec_convert("0", res)); | ||
BOOST_TEST(res == 0); | ||
|
||
BOOST_TEST(boost::stacktrace::detail::try_dec_convert("+0", res)); | ||
BOOST_TEST(res == 0); | ||
|
||
BOOST_TEST(boost::stacktrace::detail::try_dec_convert("10", res)); | ||
BOOST_TEST(res == 10); | ||
|
||
BOOST_TEST(boost::stacktrace::detail::try_dec_convert("19", res)); | ||
BOOST_TEST(res == 19); | ||
|
||
BOOST_TEST(boost::stacktrace::detail::try_dec_convert("+19", res)); | ||
BOOST_TEST(res == 19); | ||
|
||
BOOST_TEST(boost::stacktrace::detail::try_dec_convert("9999", res)); | ||
BOOST_TEST(res == 9999); | ||
|
||
BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("q", res)); | ||
BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("0z", res)); | ||
BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("0u", res)); | ||
BOOST_TEST(!boost::stacktrace::detail::try_dec_convert("+0u", res)); | ||
} | ||
|
||
|
||
int main() { | ||
test_to_hex_array(); | ||
test_to_dec_array(); | ||
test_try_dec_convert(); | ||
|
||
return boost::report_errors(); | ||
} |