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

xlnt-community / xlnt / b094a147-3f46-489e-bc3f-faa90e2cd17e

04 Feb 2025 09:26PM UTC coverage: 81.87% (-0.1%) from 81.978%
b094a147-3f46-489e-bc3f-faa90e2cd17e

Pull #55

circleci

doomlaur
Added additional path and workbook saving unit tests
Pull Request #55: Add support for C++20 and C++23, and experimental support for C++26

107 of 149 new or added lines in 8 files covered. (71.81%)

4 existing lines in 2 files now uncovered.

11488 of 14032 relevant lines covered (81.87%)

1191666.72 hits per line

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

68.52
./source/detail/unicode.cpp
1
// Copyright (c) 2014-2022 Thomas Fussell
2
// Copyright (c) 2024-2025 xlnt-community
3
//
4
// Permission is hereby granted, free of charge, to any person obtaining a copy
5
// of this software and associated documentation files (the "Software"), to deal
6
// in the Software without restriction, including without limitation the rights
7
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
// copies of the Software, and to permit persons to whom the Software is
9
// furnished to do so, subject to the following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included in
12
// all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
// THE SOFTWARE
21
//
22
// @license: http://www.opensource.org/licenses/mit-license.php
23
// @author: see AUTHORS file
24

25
#pragma clang diagnostic push
26
#pragma clang diagnostic ignored "-Wdeprecated"
27
#pragma clang diagnostic ignored "-Wweak-vtables"
28
#pragma clang diagnostic ignored "-Wsign-conversion"
29
#pragma clang diagnostic ignored "-Wsuggest-override"
30
#include <utf8.h>
31
#pragma clang diagnostic pop
32

33
#include <xlnt/utils/exceptions.hpp>
34
#include <detail/unicode.hpp>
35

36
namespace xlnt {
37
namespace detail {
38

39
std::u16string utf8_to_utf16(const std::string &utf8_string)
28✔
40
{
41
    std::u16string result;
28✔
42
    utf8::utf8to16(utf8_string.begin(), utf8_string.end(), std::back_inserter(result));
28✔
43
    return result;
28✔
NEW
44
}
×
45

46
std::u32string utf8_to_utf32(const std::string &utf8_string)
1✔
47
{
48
    std::u32string result;
1✔
49
    utf8::utf8to32(utf8_string.begin(), utf8_string.end(), std::back_inserter(result));
1✔
50
    return result;
1✔
51
}
×
52

53
std::string utf16_to_utf8(const std::u16string &utf16_string)
265✔
54
{
55
    std::string result;
265✔
56
    utf8::utf16to8(utf16_string.begin(), utf16_string.end(), std::back_inserter(result));
265✔
57
    return result;
265✔
NEW
58
}
×
59

60
std::string utf32_to_utf8(const std::u32string &utf32_string)
1✔
61
{
62
    std::string result;
1✔
63
    utf8::utf32to8(utf32_string.begin(), utf32_string.end(), std::back_inserter(result));
1✔
64
    return result;
1✔
65
}
×
66

67
std::string latin1_to_utf8(const std::string &latin1)
×
68
{
69
    std::string utf8;
×
70

71
    for (auto character : latin1)
×
72
    {
73
        if (character >= 0)
×
74
        {
75
            utf8.push_back(character);
×
76
        }
77
        else
78
        {
79
            utf8.push_back(static_cast<char>(0xc0 + (character >> 6)));
×
80
            utf8.push_back(static_cast<char>(0x80 + (character & 0x3f)));
×
81
        }
82
    }
83

84
    return utf8;
×
85
}
×
86

87
size_t string_length(const std::string &utf8_string)
23✔
88
{
89
    auto end_it = utf8::find_invalid(utf8_string.begin(), utf8_string.end());
23✔
90
    if (end_it != utf8_string.end())
23✔
91
    {
92
        throw xlnt::exception("Invalid UTF-8 encoding detected");
3✔
93
    }
94

95
    return static_cast<std::size_t>(utf8::distance(utf8_string.begin(), end_it));
44✔
96
}
97

98
#if XLNT_HAS_FEATURE(U8_STRING_VIEW)
99
std::u16string utf8_to_utf16(std::u8string_view utf8_string)
5✔
100
{
101
    std::u16string result;
5✔
102
    utf8::utf8to16(utf8_string.begin(), utf8_string.end(), std::back_inserter(result));
5✔
103
    return result;
5✔
NEW
104
}
×
105

106
std::u32string utf8_to_utf32(std::u8string_view utf8_string)
1✔
107
{
108
    std::u32string result;
1✔
109
    utf8::utf8to32(utf8_string.begin(), utf8_string.end(), std::back_inserter(result));
1✔
110
    return result;
1✔
NEW
111
}
×
112

113
std::u8string utf16_to_utf8_u8(std::u16string_view utf16_string)
1✔
114
{
115
    std::u8string result;
1✔
116
    utf8::utf16to8(utf16_string.begin(), utf16_string.end(), std::back_inserter(result));
1✔
117
    return result;
1✔
NEW
118
}
×
119

120
std::u8string utf32_to_utf8_u8(std::u32string_view utf32_string)
1✔
121
{
122
    std::u8string result;
1✔
123
    utf8::utf32to8(utf32_string.begin(), utf32_string.end(), std::back_inserter(result));
1✔
124
    return result;
1✔
NEW
125
}
×
126
#endif
127

128
} // namespace detail
129
} // namespace xlnt
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