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

xlnt-community / xlnt / cfa83a57-8715-44c8-af36-c668df2f8551

03 Feb 2025 08:59PM UTC coverage: 81.814% (-0.2%) from 81.978%
cfa83a57-8715-44c8-af36-c668df2f8551

Pull #55

circleci

doomlaur
Removed TODO comment that is no longer true
Pull Request #55: Add support for C++20 and C++23, and experimental support for C++26

93 of 142 new or added lines in 8 files covered. (65.49%)

4 existing lines in 2 files now uncovered.

11476 of 14027 relevant lines covered (81.81%)

1192083.53 hits per line

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

50.0
./source/detail/serialization/open_stream.cpp
1
// Copyright (c) 2017-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
#include <xlnt/utils/path.hpp>
26
#include <detail/serialization/open_stream.hpp>
27

28
#if XLNT_HAS_INCLUDE(<filesystem>)
29
  #include <filesystem>
30
#endif
31

32
namespace xlnt {
33
namespace detail {
34

35
void open_stream(std::ifstream &stream, const std::string &path)
88✔
36
{
37
#ifdef _MSC_VER
38
    open_stream(stream, xlnt::path(path).wstring());
39
#else
40
    stream.open(path, std::ios::binary);
88✔
41
#endif
42
}
88✔
43

44
void open_stream(std::ofstream &stream, const std::string &path)
74✔
45
{
46
#ifdef _MSC_VER
47
    open_stream(stream, xlnt::path(path).wstring());
48
#else
49
    stream.open(path, std::ios::binary);
74✔
50
#endif
51
}
74✔
52

53
#ifdef _MSC_VER
54
void open_stream(std::ifstream &stream, const std::wstring &path)
55
{
56
    stream.open(path, std::ios::binary);
57
}
58

59
void open_stream(std::ofstream &stream, const std::wstring &path)
60
{
61
    stream.open(path, std::ios::binary);
62
}
63
#endif
64

65
#if XLNT_HAS_FEATURE(U8_STRING_VIEW)
NEW
66
void open_stream(std::ifstream &stream, std::u8string_view path)
×
67
{
68
#ifdef _MSC_VER
69
    open_stream(stream, xlnt::path(path).wstring());
70
#elif XLNT_HAS_FEATURE(FILESYSTEM)
NEW
71
    stream.open(std::filesystem::path(path), std::ios::binary);
×
72
#else
73
    // TODO: this cannot work if the user's locale is not UTF-8. In such cases we cannot ensure
74
    // that this always works - however, in such cases we can still attempt to do a conversion to
75
    // the locale encoding, which will still work if the string can be represented
76
    // with the user's locale encoding.
77
    // NOTE: this code will only run if C++17 is only partially implemented,
78
    // but C++17 string_view and C++20 char8_t are implemented, while C++17 filesystem is not.
79
    stream.open(to_char_ptr(path.data()), std::ios::binary);
80
#endif
UNCOV
81
}
×
82

NEW
83
void open_stream(std::ofstream &stream, std::u8string_view path)
×
84
{
85
#ifdef _MSC_VER
86
    open_stream(stream, xlnt::path(path).wstring());
87
#elif XLNT_HAS_FEATURE(FILESYSTEM)
NEW
88
    stream.open(std::filesystem::path(path), std::ios::binary);
×
89
#else
90
    // TODO: this cannot work if the user's locale is not UTF-8. In such cases we cannot ensure
91
    // that this always works - however, in such cases we can still attempt to do a conversion to
92
    // the locale encoding, which will still work if the string can be represented
93
    // with the user's locale encoding.
94
    // NOTE: this code will only run if C++17 is only partially implemented,
95
    // but C++17 string_view and C++20 char8_t are implemented, while C++17 filesystem is not.
96
    stream.open(to_char_ptr(path.data()), std::ios::binary);
97
#endif
UNCOV
98
}
×
99
#endif
100

101
} // namespace detail
102
} // 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