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