Strip all trailing 0s in AsciiValue::write

v0.27.3
Andreas Huggel 22 years ago
parent f6c0f9371a
commit c1ff9cd64c

@ -20,14 +20,14 @@
*/
/*
File: value.cpp
Version: $Name: $ $Revision: 1.2 $
Version: $Name: $ $Revision: 1.3 $
Author(s): Andreas Huggel (ahu) <ahuggel@gmx.net>
History: 26-Jan-04, ahu: created
11-Feb-04, ahu: isolated as a component
*/
// *****************************************************************************
#include "rcsid.hpp"
EXIV2_RCSID("@(#) $Name: $ $Revision: 1.2 $ $RCSfile: value.cpp,v $")
EXIV2_RCSID("@(#) $Name: $ $Revision: 1.3 $ $RCSfile: value.cpp,v $")
// *****************************************************************************
// included header files
@ -187,14 +187,9 @@ namespace Exif {
std::ostream& AsciiValue::write(std::ostream& os) const
{
// Strip trailing '\0', if any
if (value_.size() > 0 && value_[value_.size() - 1] == '\0') {
os << value_.substr(0, value_.size() - 1);
}
else {
os << value_;
}
return os;
// Strip all trailing '\0's (if any)
std::string::size_type pos = value_.find_last_not_of('\0');
return os << value_.substr(0, pos + 1);
}
} // namespace Exif

@ -21,7 +21,7 @@
/*!
@file value.hpp
@brief Value interface and concrete subclasses
@version $Name: $ $Revision: 1.4 $
@version $Name: $ $Revision: 1.5 $
@author Andreas Huggel (ahu)
<a href="mailto:ahuggel@gmx.net">ahuggel@gmx.net</a>
@date 09-Jan-04, ahu: created
@ -268,9 +268,9 @@ namespace Exif {
virtual long size() const;
virtual Value* clone() const;
/*!
@brief Write the value to an output stream. One trailing '\\0'
character of the ASCII value is stripped if present and not
written to the output stream.
@brief Write the value to an output stream. Any trailing '\\0'
characters of the ASCII value are stripped and not written to
the output stream.
*/
virtual std::ostream& write(std::ostream& os) const;
virtual long toLong(long n =0) const { return value_[n]; }

Loading…
Cancel
Save