]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/biblio.h
a new biblio::asValidLatexString helper function.
[lyx.git] / src / frontends / controllers / biblio.h
1 // -*- C++ -*-
2 /**
3  * \file biblio.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef BIBLIOHELPERS_H
13 #define BIBLIOHELPERS_H
14
15 #include <map>
16 #include <string>
17 #include <vector>
18
19 class Buffer;
20
21 /** Functions of use to citation and bibtex GUI controllers and views */
22 namespace biblio {
23
24 class CiteEngine_enum;
25
26 CiteEngine_enum getEngine(Buffer const &);
27
28
29 enum CiteStyle {
30         CITE,
31         CITET,
32         CITEP,
33         CITEALT,
34         CITEALP,
35         CITEAUTHOR,
36         CITEYEAR,
37         CITEYEARPAR
38 };
39
40
41 enum Search {
42         SIMPLE,
43         REGEX
44 };
45
46
47 enum Direction {
48         FORWARD,
49         BACKWARD
50 };
51
52
53 /** Each citation engine recognizes only a subset of all possible
54  *  citation commands. Given a latex command \c input, this function
55  *  returns an appropriate command, valid for \c engine.
56  */
57 std::string const asValidLatexCommand(std::string const & input,
58                                       CiteEngine_enum const & engine);
59
60 /// First entry is the bibliography key, second the data
61 typedef std::map<std::string, std::string> InfoMap;
62
63 /// Returns a vector of bibliography keys
64 std::vector<std::string> const getKeys(InfoMap const &);
65
66 /** Returns the BibTeX data associated with a given key.
67     Empty if no info exists. */
68 std::string const getInfo(InfoMap const &, std::string const &);
69
70 // rturn the year from the bibtex data record
71 std::string const getYear(InfoMap const & map, std::string const & key);
72
73 /// return the short form of an authorlist
74 std::string const getAbbreviatedAuthor(InfoMap const & map, std::string const & key);
75
76 // return only the family name
77 std::string const familyName(std::string const & name);
78
79 /** Search a BibTeX info field for the given key and return the
80     associated field. */
81 std::string const parseBibTeX(std::string data, std::string const & findkey);
82
83 /** Returns an iterator to the first key that meets the search
84     criterion, or end() if unsuccessful.
85
86     User supplies :
87     the InfoMap of bibkeys info,
88     the vector of keys to be searched,
89     the search criterion,
90     an iterator defining the starting point of the search,
91     an enum defining a Simple or Regex search,
92     an enum defining the search direction.
93 */
94
95 std::vector<std::string>::const_iterator
96 searchKeys(InfoMap const & map,
97            std::vector<std::string> const & keys_to_search,
98            std::string const & search_expression,
99            std::vector<std::string>::const_iterator start,
100            Search,
101            Direction,
102            bool caseSensitive=false);
103
104
105 struct CitationStyle {
106         ///
107         CitationStyle(CiteStyle s = CITE, bool f = false, bool force = false)
108                 : style(s), full(f), forceUCase(force) {}
109         /// \param latex_str a LaTeX command, "cite", "Citep*", etc
110         CitationStyle(std::string const & latex_str);
111         ///
112         std::string const asLatexStr() const;
113         ///
114         CiteStyle style;
115         ///
116         bool full;
117         ///
118         bool forceUCase;
119 };
120
121
122 /// Returns a vector of available Citation styles.
123 std::vector<CiteStyle> const getCiteStyles(CiteEngine_enum const &);
124
125 /**
126    "Translates" the available Citation Styles into strings for this key.
127    The returned string is displayed by the GUI.
128
129
130    [XX] is used in place of the actual reference
131    Eg, the vector will contain: [XX], Jones et al. [XX], ...
132
133    User supplies :
134    the key,
135    the InfoMap of bibkeys info,
136    the available citation styles
137 */
138 std::vector<std::string> const
139 getNumericalStrings(std::string const & key,
140                     InfoMap const & map,
141                     std::vector<CiteStyle> const & styles);
142
143 /**
144    "Translates" the available Citation Styles into strings for this key.
145    The returned string is displayed by the GUI.
146
147    Eg, the vector will contain:
148    Jones et al. (1990), (Jones et al. 1990), Jones et al. 1990, ...
149
150    User supplies :
151    the key,
152    the InfoMap of bibkeys info,
153    the available citation styles
154 */
155 std::vector<std::string> const
156 getAuthorYearStrings(std::string const & key,
157                      InfoMap const & map,
158                      std::vector<CiteStyle> const & styles);
159 } // namespace biblio
160
161 #endif // BIBLIOHELPERS_H