]> git.lyx.org Git - lyx.git/blob - src/Author.cpp
Fixed some lines that were too long. It compiled afterwards.
[lyx.git] / src / Author.cpp
1 /**
2  * \file Author.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "Author.h"
14
15 #include "support/lstrings.h"
16
17 #include <boost/assert.hpp>
18
19 #include "support/std_istream.h"
20
21 using std::string;
22
23 namespace lyx {
24
25 using support::token;
26 using support::trim;
27
28
29 bool operator==(Author const & l, Author const & r)
30 {
31         return l.name() == r.name() && l.email() == r.email();
32 }
33
34
35 std::ostream & operator<<(std::ostream & os, Author const & a)
36 {
37         // FIXME UNICODE
38         os << "\"" << to_utf8(a.name()) << "\" " << to_utf8(a.email());
39         return os;
40 }
41
42 std::istream & operator>>(std::istream & is, Author & a)
43 {
44         string s;
45         getline(is, s);
46         // FIXME UNICODE
47         a.name_ = from_utf8(trim(token(s, '\"', 1)));
48         a.email_ = from_utf8(trim(token(s, '\"', 2)));
49         return is;
50 }
51
52
53 AuthorList::AuthorList()
54         : last_id_(0)
55 {
56 }
57
58
59 int AuthorList::record(Author const & a)
60 {
61         Authors::const_iterator it(authors_.begin());
62         Authors::const_iterator itend(authors_.end());
63
64         for (;  it != itend; ++it) {
65                 if (it->second == a)
66                         return it->first;
67         }
68
69         authors_[last_id_++] = a;
70         return last_id_ - 1;
71 }
72
73
74 void AuthorList::record(int id, Author const & a)
75 {
76         BOOST_ASSERT(unsigned(id) < authors_.size());
77
78         authors_[id] = a;
79 }
80
81
82 Author const & AuthorList::get(int id) const
83 {
84         Authors::const_iterator it(authors_.find(id));
85         BOOST_ASSERT(it != authors_.end());
86         return it->second;
87 }
88
89
90 AuthorList::Authors::const_iterator AuthorList::begin() const
91 {
92         return authors_.begin();
93 }
94
95
96 AuthorList::Authors::const_iterator AuthorList::end() const
97 {
98         return authors_.end();
99 }
100
101
102 } // namespace lyx