• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

libbitcoin / libbitcoin-system / 13069453084

31 Jan 2025 08:55AM UTC coverage: 82.728% (-0.007%) from 82.735%
13069453084

push

github

web-flow
Merge pull request #1604 from evoskuil/master

Set _CRTDBG_MAP_ALLOC for vc++ debug mode leak tracking.

2 of 2 new or added lines in 1 file covered. (100.0%)

15 existing lines in 11 files now uncovered.

10039 of 12135 relevant lines covered (82.73%)

3871639.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.3
/src/unicode/conversion.cpp
1
/**
2
 * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
3
 *
4
 * This file is part of libbitcoin.
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Affero General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
#include <bitcoin/system/unicode/conversion.hpp>
20

21
#include <algorithm>
22
#include <string>
23

24
namespace libbitcoin {
25
namespace system {
26

27
template <typename CharOut, typename CharIn>
28
static std::basic_string<CharOut> to_utf(
171,040✔
29
    const std::basic_string<CharIn>& in) NOEXCEPT
30
{
31
    using namespace boost::locale;
32
    std::basic_string<CharOut> out;
33

34
    // method_type::stop throws conv::conversion_error.
35
    // Other stop methods skip characters, resulting in hidden failure.
36
    // So use method_type::stop and trap conversion exceptions.
37
    try
38
    {
39
        // This does not honor BOOST_EXCEPTION_DISABLE.
40
        // This is a mathematical conversion that could be reimplemented here.
41
        out = conv::utf_to_utf<CharOut>(in, conv::method_type::stop);
342,079✔
42
    }
43
    catch (const conv::conversion_error&)
1✔
44
    {
45
        out.clear();
46
    }
47

48
    return out;
171,040✔
49
}
50

51
template <typename CharOut, typename CharIn>
52
static std::vector<std::basic_string<CharOut>> to_utf(
37✔
53
    const std::vector<std::basic_string<CharIn>>& in) NOEXCEPT
54
{
55
    std::vector<std::basic_string<CharOut>> out(in.size());
37✔
56
    std::transform(in.begin(), in.end(), out.begin(),
37✔
57
        [](const std::basic_string<CharIn>& word) NOEXCEPT
47,478✔
58
        {
59
            return to_utf<CharOut>(word);
47,478✔
60
        });
61

62
    return out;
37✔
UNCOV
63
}
×
64

65
// char32_t is the only 1:1 char encoding.
66
std::string to_utf8(char32_t point) NOEXCEPT
46✔
67
{
68
    return to_utf8(std::u32string{ point });
92✔
69
}
70

71
std::string to_utf8(const std::wstring& text) NOEXCEPT
7✔
72
{
73
    return to_utf<char>(text);
7✔
74
}
75

76
std::string to_utf8(const std::u32string& text) NOEXCEPT
59,717✔
77
{
78
    return to_utf<char>(text);
59,717✔
79
}
80

81
std::wstring to_utf16(const std::string& text) NOEXCEPT
18✔
82
{
83
    return to_utf<wchar_t>(text);
18✔
84
}
85

86
std::wstring to_utf16(const std::u32string& text) NOEXCEPT
2✔
87
{
88
    return to_utf<wchar_t>(text);
2✔
89
}
90

91
std::u32string to_utf32(const std::string& text) NOEXCEPT
63,817✔
92
{
93
    return to_utf<char32_t>(text);
63,817✔
94
}
95

96
std::u32string to_utf32(const std::wstring& text) NOEXCEPT
1✔
97
{
98
    return to_utf<char32_t>(text);
1✔
99
}
100

101
string_list to_utf8(const wstring_list& text) NOEXCEPT
2✔
102
{
103
    return to_utf<char>(text);
2✔
104
}
105

106
string_list to_utf8(const u32string_list& text) NOEXCEPT
2✔
107
{
108
    return to_utf<char>(text);
2✔
109
}
110

111
wstring_list to_utf16(const string_list& text) NOEXCEPT
14✔
112
{
113
    return to_utf<wchar_t>(text);
14✔
114
}
115

116
wstring_list to_utf16(const u32string_list& text) NOEXCEPT
3✔
117
{
118
    return to_utf<wchar_t>(text);
3✔
119
}
120

121
u32string_list to_utf32(const string_list& text) NOEXCEPT
15✔
122
{
123
    return to_utf<char32_t>(text);
15✔
124
}
125

126
u32string_list to_utf32(const wstring_list& text) NOEXCEPT
1✔
127
{
128
    return to_utf<char32_t>(text);
1✔
129
}
130

131
} // namespace system
132
} // namespace libbitcoin
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc