]> git.lyx.org Git - lyx.git/blob - src/Author.cpp
Kill LFUN_PARAGRAPH_SPACING in favour of LFUN_PARAGRAPH_PARAMS.
[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 "support/lassert.h"
18
19 #include <istream>
20
21 using namespace std;
22 using namespace lyx::support;
23
24 namespace lyx {
25
26
27 bool operator==(Author const & l, Author const & r)
28 {
29         return l.name() == r.name() && l.email() == r.email();
30 }
31
32
33 ostream & operator<<(ostream & os, Author const & a)
34 {
35         // FIXME UNICODE
36         os << "\"" << to_utf8(a.name()) << "\" " << to_utf8(a.email());
37         return os;
38 }
39
40 istream & operator>>(istream & is, Author & a)
41 {
42         string s;
43         getline(is, s);
44         // FIXME UNICODE
45         a.name_ = from_utf8(trim(token(s, '\"', 1)));
46         a.email_ = from_utf8(trim(token(s, '\"', 2)));
47         return is;
48 }
49
50
51 AuthorList::AuthorList()
52         : last_id_(0)
53 {
54 }
55
56
57 int AuthorList::record(Author const & a)
58 {
59         Authors::const_iterator it(authors_.begin());
60         Authors::const_iterator itend(authors_.end());
61
62         for (;  it != itend; ++it) {
63                 if (it->second == a)
64                         return it->first;
65         }
66
67         authors_[last_id_++] = a;
68         return last_id_ - 1;
69 }
70
71
72 void AuthorList::record(int id, Author const & a)
73 {
74         LASSERT(unsigned(id) < authors_.size(), /**/);
75
76         authors_[id] = a;
77 }
78
79
80 Author const & AuthorList::get(int id) const
81 {
82         Authors::const_iterator it(authors_.find(id));
83         LASSERT(it != authors_.end(), /**/);
84         return it->second;
85 }
86
87
88 AuthorList::Authors::const_iterator AuthorList::begin() const
89 {
90         return authors_.begin();
91 }
92
93
94 AuthorList::Authors::const_iterator AuthorList::end() const
95 {
96         return authors_.end();
97 }
98
99
100 } // namespace lyx