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

STEllAR-GROUP / hpx / #856

28 Dec 2022 02:00AM UTC coverage: 86.602% (+0.05%) from 86.55%
#856

push

StellarBot
Merge #6119

6119: Update CMakeLists.txt r=hkaiser a=khuck

updating the default APEX version


Co-authored-by: Kevin Huck <khuck@cs.uoregon.edu>

174566 of 201573 relevant lines covered (86.6%)

1876093.78 hits per line

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

31.58
/libs/core/program_options/include/hpx/program_options/detail/utf8_codecvt_facet.hpp
1
// Copyright (c) 2001 Ronald Garcia, Indiana University (garcia@osl.iu.edu)
2
// Andrew Lumsdaine, Indiana University (lums@osl.iu.edu).
3
//  SPDX-License-Identifier: BSL-1.0
4
// Distributed under the Boost Software License, Version 1.0. (See accompany-
5
// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
#pragma once
8

9
// MS compatible compilers support #pragma once
10
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
11
#pragma once
12
#endif
13

14
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
15
// utf8_codecvt_facet.hpp
16

17
// This header defines class utf8_codecvt_facet, derived from
18
// std::codecvt<wchar_t, char>, which can be used to convert utf8 data in
19
// files into wchar_t strings in the application.
20
//
21
// The header is NOT STANDALONE, and is not to be included by the USER.
22
// There are at least two libraries which want to use this functionality, and
23
// we want to avoid code duplication. It would be possible to create utf8
24
// library, but:
25
// - this requires review process first
26
// - in the case, when linking the a library which uses utf8
27
//   (say 'program_options'), user should also link to the utf8 library.
28
//   This seems inconvenient, and asking a user to link to an unrevieved
29
//   library is strange.
30
// Until the above points are fixed, a library which wants to use utf8 must:
31
// - include this header in one of it's headers or sources
32
// - include the corresponding boost/detail/utf8_codecvt_facet.ipp file in one
33
//   of its sources
34
// - before including either file, the library must define
35
//   - BOOST_UTF8_BEGIN_NAMESPACE to the namespace declaration that must be used
36
//   - BOOST_UTF8_END_NAMESPACE to the code to close the previous namespace
37
//     declaration.
38
//   - BOOST_UTF8_DECL -- to the code which must be used for all 'exportable'
39
//     symbols.
40
//
41
// For example, program_options library might contain:
42
//    #define BOOST_UTF8_BEGIN_NAMESPACE <backslash character>
43
//             namespace boost { namespace program_options {
44
//    #define BOOST_UTF8_END_NAMESPACE }}
45
//    #define BOOST_UTF8_DECL BOOST_PROGRAM_OPTIONS_DECL
46
//    #include <boost/detail/utf8_codecvt_facet.ipp>
47
//
48
// Essentially, each library will have its own copy of utf8 code, in
49
// different namespaces.
50

51
// Note:(Robert Ramey).  I have made the following alterations in the original
52
// code.
53
// a) Rendered utf8_codecvt<wchar_t, char>  with using templates
54
// b) Move longer functions outside class definition to prevent inlining
55
// and make code smaller
56
// c) added on a derived class to permit translation to/from current
57
// locale to utf8
58

59
//  See http://www.boost.org for updates, documentation, and revision history.
60

61
// archives stored as text - note these ar templated on the basic
62
// stream templates to accommodate wide (and other?) kind of characters
63
//
64
// note the fact that on libraries without wide characters, ostream is
65
// is not a specialization of basic_ostream which in fact is not defined
66
// in such cases.   So we can't use basic_ostream<OStream::char_type> but rather
67
// use two template parameters
68
//
69
// utf8_codecvt_facet
70
//   This is an implementation of a std::codecvt facet for translating
71
//   from UTF-8 externally to UCS-4.  Note that this is not tied to
72
//   any specific types in order to allow customization on platforms
73
//   where wchar_t is not big enough.
74
//
75
// NOTES:  The current implementation jumps through some unpleasant hoops in
76
// order to deal with signed character types.  As a std::codecvt_base::result,
77
// it is necessary  for the ExternType to be convertible to unsigned  char.
78
// I chose not to tie the extern_type explicitly to char. But if any combination
79
// of types other than <wchar_t,char_t> is used, then std::codecvt must be
80
// specialized on those types for this to work.
81

82
#include <hpx/program_options/config.hpp>
83

84
#include <cstddef>    // for std::size_t
85
#include <cwchar>     // for mbstate_t
86
#include <locale>
87

88
// maximum length of a multibyte string
89
#define MB_LENGTH_MAX 8
90

91
//----------------------------------------------------------------------------//
92
//                                                                            //
93
//                          utf8_codecvt_facet                                //
94
//                                                                            //
95
//            See utf8_codecvt_facet.cpp for the implementation.              //
96
//----------------------------------------------------------------------------//
97

98
namespace hpx::program_options::detail {
99

100
    struct HPX_CORE_EXPORT utf8_codecvt_facet
101
      : public std::codecvt<wchar_t, char, std::mbstate_t>
102
    {
103
    public:
104
        explicit utf8_codecvt_facet(std::size_t no_locale_manage = 0);
105
        virtual ~utf8_codecvt_facet();
106

107
    protected:
108
        std::codecvt_base::result do_in(std::mbstate_t& state, char const* from,
109
            char const* from_end, char const*& from_next, wchar_t* to,
110
            wchar_t* to_end, wchar_t*& to_next) const override;
111

112
        std::codecvt_base::result do_out(std::mbstate_t& state,
113
            wchar_t const* from, wchar_t const* from_end,
114
            wchar_t const*& from_next, char* to, char* to_end,
115
            char*& to_next) const override;
116

117
        bool invalid_continuing_octet(unsigned char octet_1) const noexcept
14✔
118
        {
119
            return (octet_1 < 0x80 || 0xbf < octet_1);
14✔
120
        }
121

122
        bool invalid_leading_octet(unsigned char octet_1) const noexcept
67✔
123
        {
124
            return (0x7f < octet_1 && octet_1 < 0xc0) || (octet_1 > 0xfd);
67✔
125
        }
126

127
        // continuing octets = octets except for the leading octet
128
        static unsigned int get_cont_octet_count(
67✔
129
            unsigned char lead_octet) noexcept
130
        {
131
            return get_octet_count(lead_octet) - 1;
67✔
132
        }
133

134
        static unsigned int get_octet_count(unsigned char lead_octet) noexcept;
135

136
        // How many "continuing octets" will be needed for this word
137
        // ==   total octets - 1.
138
        int get_cont_octet_out_count(wchar_t word) const noexcept;
139

140
        bool do_always_noconv() const noexcept override
×
141
        {
142
            return false;
×
143
        }
144

145
        // UTF-8 isn't really stateful since we rewind on partial conversions
146
        std::codecvt_base::result do_unshift(std::mbstate_t&, char* from,
×
147
            char* /*to*/, char*& next) const override
148
        {
149
            next = from;
×
150
            return ok;
×
151
        }
152

153
        int do_encoding() const noexcept override
×
154
        {
155
            int const variable_byte_external_encoding = 0;
×
156
            return variable_byte_external_encoding;
×
157
        }
158

159
        // How many char objects can I process to get <= max_limit
160
        // wchar_t objects?
161
        int do_length(std::mbstate_t&, char const* from, char const* from_end,
162
            std::size_t max_limit) const noexcept override;
163

164
        // Nonstandard override
165
        virtual int do_length(std::mbstate_t const& s, char const* from,
×
166
            char const* from_end, std::size_t max_limit) const noexcept
167
        {
168
            return do_length(
×
169
                const_cast<std::mbstate_t&>(s), from, from_end, max_limit);
×
170
        }
171

172
        // Largest possible value do_length(state,from,from_end,1) could return.
173
        int do_max_length() const noexcept override
×
174
        {
175
            return 6;    // largest UTF-8 encoding of a UCS-4 character
×
176
        }
177
    };
178
}    // namespace hpx::program_options::detail
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

© 2026 Coveralls, Inc