3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
15 #include "support/lstrings.h"
17 #include "support/lassert.h"
23 using namespace lyx::support;
28 bool operator==(Author const & l, Author const & r)
30 return l.name() == r.name() && l.email() == r.email();
34 ostream & operator<<(ostream & os, Author const & a)
37 os << a.buffer_id() << " \"" << to_utf8(a.name())
38 << "\" " << to_utf8(a.email());
43 istream & operator>>(istream & is, Author & a)
49 a.name_ = from_utf8(trim(token(s, '\"', 1)));
50 a.email_ = from_utf8(trim(token(s, '\"', 2)));
55 bool author_smaller(Author const & lhs, Author const & rhs) {
56 return lhs.buffer_id() < rhs.buffer_id();
60 AuthorList::AuthorList()
66 int AuthorList::record(Author const & a)
68 Authors::const_iterator it(authors_.begin());
69 Authors::const_iterator itend(authors_.end());
71 for (int i = 0; it != itend; ++it, ++i) {
73 if (it->buffer_id() == 0)
74 // The current author is internally represented as
75 // author 0, but it appears he has already an id.
76 it->setBufferId(a.buffer_id());
80 authors_.push_back(a);
85 void AuthorList::record(int id, Author const & a)
87 LASSERT(unsigned(id) < authors_.size(), /**/);
93 void AuthorList::recordCurrentAuthor(Author const & a)
95 // current author has id 0
100 Author const & AuthorList::get(int id) const
102 LASSERT(id < (int)authors_.size() , /**/);
107 AuthorList::Authors::const_iterator AuthorList::begin() const
109 return authors_.begin();
113 AuthorList::Authors::const_iterator AuthorList::end() const
115 return authors_.end();
119 void AuthorList::sort() {
120 std::sort(authors_.begin(), authors_.end(), author_smaller);
124 ostream & operator<<(ostream & os, AuthorList const & a) {
125 // Copy the authorlist, because we don't want to sort the original
126 AuthorList sorted = a;
129 AuthorList::Authors::const_iterator a_it = sorted.begin();
130 AuthorList::Authors::const_iterator a_end = sorted.end();
132 // Find the buffer id for the current author (internal id 0),
133 // if he doesn't have a buffer_id yet.
134 if (sorted.get(0).buffer_id() == 0) {
135 unsigned int cur_id = 1;
136 for (; a_it != a_end; ++a_it) {
137 if (a_it->buffer_id() == cur_id)
139 else if (a_it->buffer_id() > cur_id) {
143 // Set the id in both the original authorlist,
145 a.get(0).setBufferId(cur_id);
146 sorted.get(0).setBufferId(cur_id);
150 for (a_it = sorted.begin(); a_it != a_end; ++a_it) {
152 os << "\\author " << *a_it << "\n";