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 Author const & AuthorList::get(int id) const
95 LASSERT(id < (int)authors_.size() , /**/);
100 AuthorList::Authors::const_iterator AuthorList::begin() const
102 return authors_.begin();
106 AuthorList::Authors::const_iterator AuthorList::end() const
108 return authors_.end();
112 void AuthorList::sort() {
113 std::sort(authors_.begin(), authors_.end(), author_smaller);
117 ostream & operator<<(ostream & os, AuthorList const & a) {
118 // Copy the authorlist, because we don't want to sort the original
119 AuthorList sorted = a;
122 AuthorList::Authors::const_iterator a_it = sorted.begin();
123 AuthorList::Authors::const_iterator a_end = sorted.end();
125 // Find the buffer id for the current author (internal id 0),
126 // if he doesn't have a buffer_id yet.
127 if (sorted.get(0).buffer_id() == 0) {
128 unsigned int cur_id = 1;
129 for (; a_it != a_end; ++a_it) {
130 if (a_it->buffer_id() == cur_id)
132 else if (a_it->buffer_id() > cur_id) {
136 // Set the id in both the original authorlist,
138 a.get(0).setBufferId(cur_id);
139 sorted.get(0).setBufferId(cur_id);
143 for (a_it = sorted.begin(); a_it != a_end; ++a_it) {
145 os << "\\author " << *a_it << "\n";