mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 20:51:16 +00:00
Make SettingChange and StreamCharSourcemove constructors and assignment operators noexcept (#808)
The explicitly defaulted or implemented move constructors and assignment operators are made "noexcept". Bugfix: * src/stream.cpp Stream::Stream() char_traits::int_type intro[4] is now aggregate-initialized (to zero) to avoid UB. Minor changes: * Using std::isinf() and std::signbit() instead of comparing for equality with infinity. * src/streamcharsource.h: Added #include "stream.h". * src/stream.h: Forward declaring "class StreamCharSource". * Some implicit casting changed into static_cast's. Signed-off-by: Ted Lyngmo <ted@lyncon.se>
This commit is contained in:
@@ -151,7 +151,7 @@ inline UtfIntroCharType IntroCharTypeOf(std::istream::int_type ch) {
|
||||
|
||||
inline char Utf8Adjust(unsigned long ch, unsigned char lead_bits,
|
||||
unsigned char rshift) {
|
||||
const unsigned char header = ((1 << lead_bits) - 1) << (8 - lead_bits);
|
||||
const unsigned char header = static_cast<unsigned char>(((1 << lead_bits) - 1) << (8 - lead_bits));
|
||||
const unsigned char mask = (0xFF >> (lead_bits + 1));
|
||||
return static_cast<char>(
|
||||
static_cast<unsigned char>(header | ((ch >> rshift) & mask)));
|
||||
@@ -196,7 +196,7 @@ Stream::Stream(std::istream& input)
|
||||
|
||||
// Determine (or guess) the character-set by reading the BOM, if any. See
|
||||
// the YAML specification for the determination algorithm.
|
||||
char_traits::int_type intro[4];
|
||||
char_traits::int_type intro[4]{};
|
||||
int nIntroUsed = 0;
|
||||
UtfIntroState state = uis_start;
|
||||
for (; !s_introFinalState[state];) {
|
||||
@@ -273,9 +273,11 @@ char Stream::get() {
|
||||
// . Extracts 'n' characters from the stream and updates our position
|
||||
std::string Stream::get(int n) {
|
||||
std::string ret;
|
||||
ret.reserve(n);
|
||||
for (int i = 0; i < n; i++)
|
||||
ret += get();
|
||||
if(n > 0) {
|
||||
ret.reserve(static_cast<std::string::size_type>(n));
|
||||
for (int i = 0; i < n; i++)
|
||||
ret += get();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -326,7 +328,7 @@ bool Stream::_ReadAheadTo(size_t i) const {
|
||||
void Stream::StreamInUtf8() const {
|
||||
unsigned char b = GetNextByte();
|
||||
if (m_input.good()) {
|
||||
m_readahead.push_back(b);
|
||||
m_readahead.push_back(static_cast<char>(b));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user