[SCM] exiv2 packaging branch, master, updated. debian/0.25-3.1-3734-gdcbc29a
Maximiliano Curia
maxy at moszumanska.debian.org
Thu Jul 13 17:41:06 UTC 2017
Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/exiv2.git;a=commitdiff;h=41b3365
The following commit has been merged in the master branch:
commit 41b3365ad13de8092374526f5826a4081acc9ff8
Author: Andreas Huggel <ahuggel at gmx.net>
Date: Thu Jan 14 16:54:57 2010 +0000
#662: Charset conversion on read and write (and if needed on copy).
---
src/tags.cpp | 2 +-
src/value.cpp | 138 +++++++++++++++++++++++-----------------------------------
src/value.hpp | 26 ++++-------
3 files changed, 64 insertions(+), 102 deletions(-)
diff --git a/src/tags.cpp b/src/tags.cpp
index 318f09c..315f710 100644
--- a/src/tags.cpp
+++ b/src/tags.cpp
@@ -2519,7 +2519,7 @@ namespace Exiv2 {
{
const CommentValue* pcv = dynamic_cast<const CommentValue*>(&value);
if (pcv) {
- os << pcv->value_;
+ os << pcv->comment();
}
else {
os << value;
diff --git a/src/value.cpp b/src/value.cpp
index 7715b35..81ae29d 100644
--- a/src/value.cpp
+++ b/src/value.cpp
@@ -34,8 +34,8 @@ EXIV2_RCSID("@(#) $Id$")
// included header files
#include "value.hpp"
#include "types.hpp"
-#include "convert.hpp"
#include "error.hpp"
+#include "convert.hpp"
// + standard includes
#include <iostream>
@@ -441,12 +441,12 @@ namespace Exiv2 {
}
CommentValue::CommentValue()
- : StringValueBase(Exiv2::undefined)
+ : StringValueBase(Exiv2::undefined), byteOrder_(littleEndian)
{
}
CommentValue::CommentValue(const std::string& comment)
- : StringValueBase(Exiv2::undefined)
+ : StringValueBase(Exiv2::undefined), byteOrder_(littleEndian)
{
read(comment);
}
@@ -458,16 +458,15 @@ namespace Exiv2 {
int CommentValue::read(const std::string& comment)
{
std::string c = comment;
- charsetId_ = undefined;
+ CharsetId charsetId = undefined;
if (comment.length() > 8 && comment.substr(0, 8) == "charset=") {
std::string::size_type pos = comment.find_first_of(' ');
std::string name = comment.substr(8, pos-8);
// Strip quotes (so you can also specify the charset without quotes)
if (name[0] == '"') name = name.substr(1);
if (name[name.length()-1] == '"') name = name.substr(0, name.length()-1);
- charsetId_ = CharsetInfo::charsetIdByName(name);
- if (charsetId_ == invalidCharsetId) {
- charsetId_ = undefined;
+ charsetId = CharsetInfo::charsetIdByName(name);
+ if (charsetId == invalidCharsetId) {
#ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " << Error(28, name) << "
";
#endif
@@ -476,108 +475,79 @@ namespace Exiv2 {
c.clear();
if (pos != std::string::npos) c = comment.substr(pos+1);
}
- value_ = c;
- return 0;
- }
-
- int CommentValue::read(const byte* buf, long len, ByteOrder byteOrder)
- {
- if (!buf || len == 0) {
- return 0;
- }
- std::string rawValue(reinterpret_cast<const char*>(buf), len);
- if (rawValue.length() < 8) {
- return 0;
- }
- charsetId_ = CharsetInfo::charsetIdByCode(rawValue.substr(0, 8));
- value_ = rawValue.substr(8);
- switch (charsetId_) {
- case unicode:
- if (byteOrder == littleEndian) {
- Exiv2::convertStringCharset(value_, "UCS-2LE", "UTF-8");
+ if (charsetId == unicode) {
+ if (byteOrder_ == littleEndian) {
+ convertStringCharset(c, "UTF-8", "UCS-2LE");
}
else {
- Exiv2::convertStringCharset(value_, "UCS-2BE", "UTF-8");
+ convertStringCharset(c, "UTF-8", "UCS-2BE");
}
- break;
- case ascii:
- case undefined:
- case jis:
- // JIS: The Exif 2.2 specification mentions JIS X 208-1990 as the
- // encoding for "jis". The problem is that JIS X 208-1990 isn't
- // a character encoding - that is, it doesn't specify how to
- // encode a character set into bytes. Candidates (iconv names) are:
- // EUC-JP, SHIFT_JIS, CP932, ISO-2022-JP, ISO-2022-JP-2 and ISO-2022-JP-1.
- // Pending a definitive resolution to this, we'll just leave any JIS
- // comment as we found it.
- break;
- case invalidCharsetId:
- case lastCharsetId:
- charsetId_ = undefined;
- break;
}
- return 0;
+ const std::string code(CharsetInfo::code(charsetId), 8);
+ return StringValueBase::read(code + c);
}
- std::ostream& CommentValue::write(std::ostream& os) const
+ int CommentValue::read(const byte* buf, long len, ByteOrder byteOrder)
{
- if (charsetId_ != undefined) {
- os << "charset=\"" << CharsetInfo::name(charsetId_) << "\" ";
- }
- return os << value_;
+ byteOrder_ = byteOrder;
+ return StringValueBase::read(buf, len, byteOrder);
}
long CommentValue::copy(byte* buf, ByteOrder byteOrder) const
{
- std::string encoded = encode(byteOrder);
- memcpy(buf, encoded.data(), encoded.length());
- return encoded.length();
- }
-
- long CommentValue::count() const
- {
- return size();
+ std::string c = value_;
+ if (charsetId() == unicode) {
+ c = value_.substr(8);
+ std::string::size_type l = c.size();
+ if (byteOrder_ == littleEndian && byteOrder == bigEndian) {
+ convertStringCharset(c, "UCS-2LE", "UCS-2BE");
+ assert(c.size() == l);
+ }
+ else if (byteOrder_ == bigEndian && byteOrder == littleEndian) {
+ convertStringCharset(c, "UCS-2BE", "UCS-2LE");
+ assert(c.size() == l);
+ }
+ c = value_.substr(0, 8) + c;
+ }
+ if (c.size() == 0) return 0;
+ assert(buf != 0);
+ return static_cast<long>(c.copy(reinterpret_cast<char*>(buf), c.size()));
}
- long CommentValue::size() const
+ std::ostream& CommentValue::write(std::ostream& os) const
{
- return encode(littleEndian).length();
+ CharsetId csId = charsetId();
+ if (csId != undefined) {
+ os << "charset=\"" << CharsetInfo::name(csId) << "\" ";
+ }
+ return os << comment();
}
- std::string CommentValue::encode(ByteOrder byteOrder) const
+ std::string CommentValue::comment() const
{
- std::string result(CharsetInfo::code(charsetId_), 8);
- switch (charsetId_) {
- case unicode: {
- std::string copyOfComment = value_;
- if (byteOrder == littleEndian) {
- Exiv2::convertStringCharset(copyOfComment, "UTF-8", "UCS-2LE");
+ if (value_.length() < 8) {
+ return value_; // Todo: return "" ?
+ }
+ std::string c = value_.substr(8);
+ if (charsetId() == unicode) {
+ if (byteOrder_ == littleEndian) {
+ convertStringCharset(c, "UCS-2LE", "UTF-8");
}
else {
- Exiv2::convertStringCharset(copyOfComment, "UTF-8", "UCS-2BE");
+ convertStringCharset(c, "UCS-2BE", "UTF-8");
}
- result.append(copyOfComment);
- break;
}
- case ascii:
- case jis:
- case undefined:
- case invalidCharsetId:
- case lastCharsetId:
- result.append(value_);
- break;
- }
- return result;
- }
-
- std::string CommentValue::comment() const
- {
- return value_;
+ return c;
}
CommentValue::CharsetId CommentValue::charsetId() const
{
- return charsetId_;
+ CharsetId charsetId = undefined;
+ if (value_.length() >= 8) {
+ const std::string code = value_.substr(0, 8);
+ charsetId = CharsetInfo::charsetIdByCode(code);
+ }
+ return charsetId;
}
CommentValue* CommentValue::clone_() const
diff --git a/src/value.hpp b/src/value.hpp
index 7bd51f8..19af3c6 100644
--- a/src/value.hpp
+++ b/src/value.hpp
@@ -508,12 +508,10 @@ namespace Exiv2 {
/*!
@brief %Value for an Exif comment.
- The Exif specification provides several charset specifiers to indicate
- the encoding of the comment string. If charset is
--
exiv2 packaging
More information about the pkg-kde-commits
mailing list