On 11/12/2015 01:29 PM, Georg Baum wrote:
> Guillaume Munch wrote:
>
>> * Georg, you told us an old story of "FIXME: UNICODE"s being placed in
>> the source when the developers decided that docstring would be the only
>> place where we see Unicode. I am happy to fix these as I go through the
>> code, but I am not sure that I understood what's the problem typically.
>> Here have a look at operator>> in Author.cpp below. What's the problem
>> and what should typically be done there?
> The problem in this case is that you have an operator>>(std::istream &), not 
> operator>>(idocstream &). Therefore you need to look into the actual 
> implementation to find out that utf8 encoding is expected, and it is easy to 
> miss that, and feed contents that uses a different encoding
>
> The proper fix in this case would be to change the signature to 
> operator>>(idocstream &), and at the calling site use
>
> idocstringstream ss(lex.getDocString());
>
> Then everything is explicit, and it is not possible anymore to use a wrong 
> encoding by accident.

Like this?

Richard

>From 995f62422d83884977f46712bfbe80a1c5a12635 Mon Sep 17 00:00:00 2001
From: Richard Heck <rgh...@lyx.org>
Date: Thu, 12 Nov 2015 14:42:30 -0500
Subject: [PATCH] Fix a Unicode thing.

---
 src/Author.cpp       | 8 ++++----
 src/Author.h         | 5 +++--
 src/BufferParams.cpp | 2 +-
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/Author.cpp b/src/Author.cpp
index 79e7de0..8a643c6 100644
--- a/src/Author.cpp
+++ b/src/Author.cpp
@@ -58,14 +58,14 @@ ostream & operator<<(ostream & os, Author const & a)
 }
 
 
-istream & operator>>(istream & is, Author & a)
+idocstream & operator>>(idocstream & is, Author & a)
 {
-	string s;
+	docstring s;
 	is >> a.buffer_id_;
 	getline(is, s);
 	// FIXME UNICODE
-	a.name_ = from_utf8(trim(token(s, '\"', 1)));
-	a.email_ = from_utf8(trim(token(s, '\"', 2)));
+	a.name_ = trim(token(s, '\"', 1));
+	a.email_ = trim(token(s, '\"', 2));
 	return is;
 }
 
diff --git a/src/Author.h b/src/Author.h
index f798b04..b3f7b02 100644
--- a/src/Author.h
+++ b/src/Author.h
@@ -12,6 +12,7 @@
 #ifndef AUTHOR_H
 #define AUTHOR_H
 
+#include "support/docstream.h"
 #include "support/docstring.h"
 
 #include <vector>
@@ -38,7 +39,7 @@ public:
 	///
 	bool used() const { return used_; }
 	///
-	friend std::istream & operator>>(std::istream & os, Author & a);
+	friend idocstream & operator>>(idocstream & os, Author & a);
 	///
 	friend std::ostream & operator<<(std::ostream & os, Author const & a);
 
@@ -88,7 +89,7 @@ bool operator==(Author const & l, Author const & r);
 
 std::ostream & operator<<(std::ostream & os, Author const & a);
 
-std::istream & operator>>(std::istream & os, Author & a);
+idocstream & operator>>(idocstream & os, Author & a);
 
 
 } // namespace lyx
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index c7ec167..107a179 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -873,7 +873,7 @@ string BufferParams::readToken(Lexer & lex, string const & token,
 		}
 	} else if (token == "\\author") {
 		lex.eatLine();
-		istringstream ss(lex.getString());
+		idocstringstream ss(lex.getDocString());
 		Author a;
 		ss >> a;
 		author_map[a.bufferId()] = pimpl_->authorlist.record(a);
-- 
2.1.0

Reply via email to