]> git.lyx.org Git - lyx.git/blobdiff - src/Author.cpp
DocBook: properly escape PI in InsetMarginal.
[lyx.git] / src / Author.cpp
index d44af3df4994478716d10c6422b537a15411e7ed..e4f538da6d48a823828b30a0613246d2d71bf452 100644 (file)
@@ -13,6 +13,7 @@
 #include "Author.h"
 
 #include "support/convert.h"
+#include "support/gettext.h"
 #include "support/lassert.h"
 #include "support/lstrings.h"
 
@@ -36,18 +37,27 @@ static int computeHash(docstring const & name,
 }
 
 
-Author::Author(docstring const & name, docstring const & email)
-       : name_(name), email_(email), used_(true),
+Author::Author(docstring const & name, docstring const & email, docstring const & initials)
+       : name_(name), email_(email), initials_(initials), used_(true),
          buffer_id_(computeHash(name, email))
 {}
 
 
 Author::Author(int buffer_id)
-       : name_(convert<docstring>(buffer_id)), email_(docstring()), used_(false),
+       : name_(convert<docstring>(buffer_id)), email_(docstring()), initials_(docstring()), used_(false),
          buffer_id_(buffer_id)
 {}
 
 
+docstring Author::nameAndEmail() const
+{
+       if (email().empty())
+               return name();
+       else
+               return bformat(_("%1$s[[name]] (%2$s[[email]])"), name(), email());
+}
+
+
 bool Author::valid() const
 {
        //this cannot be equal if the buffer_id was produced by the hash function.
@@ -57,15 +67,16 @@ bool Author::valid() const
 
 bool operator==(Author const & l, Author const & r)
 {
-       return l.name() == r.name() && l.email() == r.email();
+       return l.name() == r.name() && l.email() == r.email() && l.initials() == r.initials();
 }
 
 
 ostream & operator<<(ostream & os, Author const & a)
 {
        // FIXME UNICODE
-       os << a.buffer_id_ << " \"" << to_utf8(a.name_)
-                       << "\" " << to_utf8(a.email_);
+       os << a.buffer_id_ << " \"" << to_utf8(a.name_) << "\"";
+       if (!a.email_.empty())
+               os << " " << to_utf8(a.email_);
 
        return os;
 }
@@ -167,13 +178,9 @@ ostream & operator<<(ostream & os, AuthorList const & a)
        // Copy the authorlist, because we don't want to sort the original
        AuthorList sorted = a;
        sorted.sort();
-
-       AuthorList::Authors::const_iterator a_it = sorted.begin();
-       AuthorList::Authors::const_iterator const a_end = sorted.end();
-
-       for (; a_it != a_end; ++a_it) {
-               if (a_it->used() && a_it->valid())
-                       os << "\\author " << *a_it << "\n";     
+       for (auto const & aut : sorted) {
+               if (aut.used() && aut.valid())
+                       os << "\\author " << aut << "\n";
        }
        return os;
 }