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

xlnt-community / xlnt / b5325487-b953-4fb3-ae7c-12335ef12dcb

02 Feb 2025 07:13PM UTC coverage: 81.7% (-1.8%) from 83.482%
b5325487-b953-4fb3-ae7c-12335ef12dcb

Pull #55

circleci

doomlaur
Fix CI to use the correct Docker image for code coverage tests
Pull Request #55: Add support for C++20 and C++23, and experimental support for C++26

78 of 142 new or added lines in 8 files covered. (54.93%)

304 existing lines in 28 files now uncovered.

11460 of 14027 relevant lines covered (81.7%)

1191795.07 hits per line

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

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

24
#pragma once
25

26
#include <string>
27
#include <vector>
28

29
#include <detail/xlnt_config_impl.hpp>
30
#include <xlnt/internal/features.hpp>
31

32
#if XLNT_HAS_INCLUDE(<string_view>) && XLNT_HAS_FEATURE(U8_STRING_VIEW)
33
  #include <string_view>
34
#endif
35

36
namespace xlnt {
37
namespace detail {
38

39
// Prepends the string literal prefix to the provided string literal.
40
// Useful when defining a string literal once, then using it with multiple string types.
41
#define LSTRING_LITERAL2(a) L##a
42
#define U8STRING_LITERAL2(a) u8##a
43
#define U16STRING_LITERAL2(a) u##a
44
#define U32STRING_LITERAL2(a) U##a
45
#define LSTRING_LITERAL(a) LSTRING_LITERAL2(a)
46
#define U8STRING_LITERAL(a) U8STRING_LITERAL2(a)
47
#define U16STRING_LITERAL(a) U16STRING_LITERAL2(a)
48
#define U32STRING_LITERAL(a) U32STRING_LITERAL2(a)
49

50
// Casts a UTF-8 string literal to a narrow string literal without changing its encoding.
51
#ifdef __cpp_char8_t
52
// For C++20 and newer, interpret as UTF-8 and then cast to string literal
53
#define U8_TO_CHAR_PTR(a) xlnt::detail::to_char_ptr(a)
54
#else
55
// For C++11, C++14 and C++17, simply interpret as UTF-8, which works with classic string literals.
56
#define U8_TO_CHAR_PTR(a) a
57
#endif
58

59

60
// The following weird cast ensures that the string is UTF-8 encoded at all costs!
61
#define ENSURE_UTF8_LITERAL(a) U8_TO_CHAR_PTR(U8STRING_LITERAL(a))
62

63
#ifdef __cpp_char8_t
64
/// Casts const char8_t arrays from C++20 to const char arrays.
65
inline const char * to_char_ptr(const char8_t *utf8)
6✔
66
{
67
    return reinterpret_cast<const char *>(utf8);
6✔
68
}
69

70
/// Casts char8_t arrays from C++20 to char arrays.
71
inline char * to_char_ptr(char8_t *utf8)
72
{
73
    return reinterpret_cast<char *>(utf8);
74
}
75
#endif
76

77
#if XLNT_HAS_FEATURE(U8_STRING_VIEW)
78
/// Casts std::u8string_view from C++20 to std::string_view.
79
inline std::string_view to_string_view(std::u8string_view utf8)
80
{
81
    return std::string_view{to_char_ptr(utf8.data()), utf8.length()};
82
}
83

84
/// Copies std::u8string(_view) from C++20 to std::string.
85
inline std::string to_string_copy(std::u8string_view utf8)
4✔
86
{
87
    return std::string{utf8.begin(), utf8.end()};
12✔
88
}
89
#endif
90

91
/// <summary>
92
/// Return a vector containing string split at each delim.
93
/// If the input string is empty, an empty vector is returned.
94
/// </summary>
95
XLNT_API_INTERNAL std::vector<std::string> split_string(const std::string &string, char delim);
96

97
/// <summary>
98
/// Concatenate all the provided items by converting them to a string using its to_string member function.
99
/// </summary>
100
template<typename T>
101
XLNT_API_INTERNAL std::string join(const std::vector<T> &items, char delim)
62✔
102
{
103
    std::string refs;
62✔
104
    for (const auto& item : items)
131✔
105
    {
106
        if (!refs.empty())
69✔
107
            refs.push_back(delim);
7✔
108

109
        refs.append(item.to_string());
69✔
110
    }
111

112
    return refs;
62✔
UNCOV
113
}
×
114

115
} // namespace detail
116
} // 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