]> git.lyx.org Git - lyx.git/blob - src/BiblioInfo.cpp
9cb3b4458e5c04bf5878d80cf010028dc92b70b5
[lyx.git] / src / BiblioInfo.cpp
1 /**
2  * \file BiblioInfo.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author Herbert Voß
8  * \author Richard Heck
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "BiblioInfo.h"
16 #include "Buffer.h"
17 #include "BufferParams.h"
18 #include "buffer_funcs.h"
19 #include "Encoding.h"
20 #include "InsetIterator.h"
21 #include "Paragraph.h"
22 #include "TocBackend.h"
23
24 #include "insets/Inset.h"
25 #include "insets/InsetBibitem.h"
26 #include "insets/InsetBibtex.h"
27 #include "insets/InsetInclude.h"
28
29 #include "support/convert.h"
30 #include "support/docstream.h"
31 #include "support/gettext.h"
32 #include "support/lassert.h"
33 #include "support/lstrings.h"
34 #include "support/textutils.h"
35
36 #include "boost/regex.hpp"
37
38 #include <set>
39
40 using namespace std;
41 using namespace lyx::support;
42
43
44 namespace lyx {
45
46 namespace {
47
48 // gets the "family name" from an author-type string
49 docstring familyName(docstring const & name)
50 {
51         if (name.empty())
52                 return docstring();
53
54         // first we look for a comma, and take the last name to be everything
55         // preceding the right-most one, so that we also get the "jr" part.
56         docstring::size_type idx = name.rfind(',');
57         if (idx != docstring::npos)
58                 return ltrim(name.substr(0, idx));
59
60         // OK, so now we want to look for the last name. We're going to
61         // include the "von" part. This isn't perfect.
62         // Split on spaces, to get various tokens.
63         vector<docstring> pieces = getVectorFromString(name, from_ascii(" "));
64         // If we only get two, assume the last one is the last name
65         if (pieces.size() <= 2)
66                 return pieces.back();
67
68         // Now we look for the first token that begins with a lower case letter.
69         vector<docstring>::const_iterator it = pieces.begin();
70         vector<docstring>::const_iterator en = pieces.end();
71         for (; it != en; ++it) {
72                 if ((*it).size() == 0)
73                         continue;
74                 char_type const c = (*it)[0];
75                 if (isLower(c))
76                         break;
77         }
78
79         if (it == en) // we never found a "von"
80                 return pieces.back();
81
82         // reconstruct what we need to return
83         docstring retval;
84         bool first = true;
85         for (; it != en; ++it) {
86                 if (!first)
87                         retval += " ";
88                 else 
89                         first = false;
90                 retval += *it;
91         }
92         return retval;
93 }
94
95 // converts a string containing LaTeX commands into unicode
96 // for display.
97 docstring convertLaTeXCommands(docstring const & str)
98 {
99         docstring val = str;
100         docstring ret;
101
102         bool scanning_cmd = false;
103         bool scanning_math = false;
104         bool escaped = false; // used to catch \$, etc.
105         while (val.size()) {
106                 char_type const ch = val[0];
107
108                 // if we're scanning math, we output everything until we
109                 // find an unescaped $, at which point we break out.
110                 if (scanning_math) {
111                         if (escaped)
112                                 escaped = false;
113                         else if (ch == '\\')
114                                 escaped = true;
115                         else if (ch == '$') 
116                                 scanning_math = false;
117                         ret += ch;
118                         val = val.substr(1);
119                         continue;
120                 }
121
122                 // if we're scanning a command name, then we just
123                 // discard characters until we hit something that
124                 // isn't alpha.
125                 if (scanning_cmd) {
126                         if (isAlphaASCII(ch)) {
127                                 val = val.substr(1);
128                                 escaped = false;
129                                 continue;
130                         }
131                         // so we're done with this command.
132                         // now we fall through and check this character.
133                         scanning_cmd = false;
134                 }
135
136                 // was the last character a \? If so, then this is something like:
137                 // \\ or \$, so we'll just output it. That's probably not always right...
138                 if (escaped) {
139                         // exception: output \, as THIN SPACE
140                         if (ch == ',')
141                                 ret.push_back(0x2009);
142                         else
143                                 ret += ch;
144                         val = val.substr(1);
145                         escaped = false;
146                         continue;
147                 }
148
149                 if (ch == '$') {
150                         ret += ch;
151                         val = val.substr(1);
152                         scanning_math = true;
153                         continue;
154                 }
155
156                 // we just ignore braces
157                 if (ch == '{' || ch == '}') {
158                         val = val.substr(1);
159                         continue;
160                 }
161
162                 // we're going to check things that look like commands, so if
163                 // this doesn't, just output it.
164                 if (ch != '\\') {
165                         ret += ch;
166                         val = val.substr(1);
167                         continue;
168                 }
169
170                 // ok, could be a command of some sort
171                 // let's see if it corresponds to some unicode
172                 // unicodesymbols has things in the form: \"{u},
173                 // whereas we may see things like: \"u. So we'll
174                 // look for that and change it, if necessary.
175                 static boost::regex const reg("^\\\\\\W\\w");
176                 if (boost::regex_search(to_utf8(val), reg)) {
177                         val.insert(3, from_ascii("}"));
178                         val.insert(2, from_ascii("{"));
179                 }
180                 docstring rem;
181                 docstring const cnvtd = Encodings::fromLaTeXCommand(val, rem,
182                                                         Encodings::TEXT_CMD);
183                 if (!cnvtd.empty()) {
184                         // it did, so we'll take that bit and proceed with what's left
185                         ret += cnvtd;
186                         val = rem;
187                         continue;
188                 }
189                 // it's a command of some sort
190                 scanning_cmd = true;
191                 escaped = true;
192                 val = val.substr(1);
193         }
194         return ret;
195 }
196
197 } // anon namespace
198
199
200 //////////////////////////////////////////////////////////////////////
201 //
202 // BibTeXInfo
203 //
204 //////////////////////////////////////////////////////////////////////
205
206 BibTeXInfo::BibTeXInfo(docstring const & key, docstring const & type)
207         : is_bibtex_(true), bib_key_(key), entry_type_(type), info_(),
208           modifier_(0)
209 {}
210
211
212 docstring const BibTeXInfo::getAbbreviatedAuthor() const
213 {
214         if (!is_bibtex_) {
215                 docstring const opt = label();
216                 if (opt.empty())
217                         return docstring();
218
219                 docstring authors;
220                 docstring const remainder = trim(split(opt, authors, '('));
221                 if (remainder.empty())
222                         // in this case, we didn't find a "(", 
223                         // so we don't have author (year)
224                         return docstring();
225                 return authors;
226         }
227
228         docstring author = convertLaTeXCommands(operator[]("author"));
229         if (author.empty()) {
230                 author = convertLaTeXCommands(operator[]("editor"));
231                 if (author.empty())
232                         return bib_key_;
233         }
234
235         // OK, we've got some names. Let's format them.
236         // Try to split the author list on " and "
237         vector<docstring> const authors =
238                 getVectorFromString(author, from_ascii(" and "));
239
240         if (authors.size() == 2)
241                 return bformat(_("%1$s and %2$s"),
242                         familyName(authors[0]), familyName(authors[1]));
243
244         if (authors.size() > 2)
245                 return bformat(_("%1$s et al."), familyName(authors[0]));
246
247         return familyName(authors[0]);
248 }
249
250
251 docstring const BibTeXInfo::getYear() const
252 {
253         if (is_bibtex_) 
254                 return operator[]("year");
255
256         docstring const opt = label();
257         if (opt.empty())
258                 return docstring();
259
260         docstring authors;
261         docstring tmp = split(opt, authors, '(');
262         if (tmp.empty()) 
263                 // we don't have author (year)
264                 return docstring();
265         docstring year;
266         tmp = split(tmp, year, ')');
267         return year;
268 }
269
270
271 docstring const BibTeXInfo::getXRef() const
272 {
273         if (!is_bibtex_)
274                 return docstring();
275         return operator[]("crossref");
276 }
277
278
279 docstring const & BibTeXInfo::getInfo(BibTeXInfo const * const xref) const
280 {
281         if (!info_.empty())
282                 return info_;
283
284         if (!is_bibtex_) {
285                 BibTeXInfo::const_iterator it = find(from_ascii("ref"));
286                 info_ = it->second;
287                 return info_;
288         }
289  
290         // FIXME
291         // This could be made a lot better using the entry_type_
292         // field to customize the output based upon entry type.
293         
294         // Search for all possible "required" fields
295         docstring author = getValueForKey("author", xref);
296         if (author.empty())
297                 author = getValueForKey("editor", xref);
298  
299         docstring year   = getValueForKey("year", xref);
300         docstring title  = getValueForKey("title", xref);
301         docstring docLoc = getValueForKey("pages", xref);
302         if (docLoc.empty()) {
303                 docLoc = getValueForKey("chapter", xref);
304                 if (!docLoc.empty())
305                         docLoc = _("Ch. ") + docLoc;
306         }       else {
307                 docLoc = _("pp. ") + docLoc;
308         }
309
310         docstring media = getValueForKey("journal", xref);
311         if (media.empty()) {
312                 media = getValueForKey("publisher", xref);
313                 if (media.empty()) {
314                         media = getValueForKey("school", xref);
315                         if (media.empty())
316                                 media = getValueForKey("institution");
317                 }
318         }
319         docstring volume = getValueForKey("volume", xref);
320
321         odocstringstream result;
322         if (!author.empty())
323                 result << author << ", ";
324         if (!title.empty())
325                 result << title;
326         if (!media.empty())
327                 result << ", " << media;
328         if (!year.empty())
329                 result << " (" << year << ")";
330         if (!docLoc.empty())
331                 result << ", " << docLoc;
332
333         docstring const result_str = rtrim(result.str());
334         if (!result_str.empty()) {
335                 info_ = convertLaTeXCommands(result_str);
336                 return info_;
337         }
338
339         // This should never happen (or at least be very unusual!)
340         static docstring e = docstring();
341         return e;
342 }
343
344
345 docstring const & BibTeXInfo::operator[](docstring const & field) const
346 {
347         BibTeXInfo::const_iterator it = find(field);
348         if (it != end())
349                 return it->second;
350         static docstring const empty_value = docstring();
351         return empty_value;
352 }
353         
354         
355 docstring const & BibTeXInfo::operator[](string const & field) const
356 {
357         return operator[](from_ascii(field));
358 }
359
360
361 docstring BibTeXInfo::getValueForKey(string const & key, 
362                 BibTeXInfo const * const xref) const
363 {
364         docstring const ret = operator[](key);
365         if (!ret.empty() || !xref)
366                 return ret;
367         return (*xref)[key];
368 }
369
370
371 //////////////////////////////////////////////////////////////////////
372 //
373 // BiblioInfo
374 //
375 //////////////////////////////////////////////////////////////////////
376
377 namespace {
378 // A functor for use with sort, leading to case insensitive sorting
379         class compareNoCase: public binary_function<docstring, docstring, bool>
380         {
381                 public:
382                         bool operator()(docstring const & s1, docstring const & s2) const {
383                                 return compare_no_case(s1, s2) < 0;
384                         }
385         };
386 } // namespace anon
387
388
389 vector<docstring> const BiblioInfo::getKeys() const
390 {
391         vector<docstring> bibkeys;
392         BiblioInfo::const_iterator it  = begin();
393         for (; it != end(); ++it)
394                 bibkeys.push_back(it->first);
395         sort(bibkeys.begin(), bibkeys.end(), compareNoCase());
396         return bibkeys;
397 }
398
399
400 vector<docstring> const BiblioInfo::getFields() const
401 {
402         vector<docstring> bibfields;
403         set<docstring>::const_iterator it = field_names_.begin();
404         set<docstring>::const_iterator end = field_names_.end();
405         for (; it != end; ++it)
406                 bibfields.push_back(*it);
407         sort(bibfields.begin(), bibfields.end());
408         return bibfields;
409 }
410
411
412 vector<docstring> const BiblioInfo::getEntries() const
413 {
414         vector<docstring> bibentries;
415         set<docstring>::const_iterator it = entry_types_.begin();
416         set<docstring>::const_iterator end = entry_types_.end();
417         for (; it != end; ++it)
418                 bibentries.push_back(*it);
419         sort(bibentries.begin(), bibentries.end());
420         return bibentries;
421 }
422
423
424 docstring const BiblioInfo::getAbbreviatedAuthor(docstring const & key) const
425 {
426         BiblioInfo::const_iterator it = find(key);
427         if (it == end())
428                 return docstring();
429         BibTeXInfo const & data = it->second;
430         return data.getAbbreviatedAuthor();
431 }
432
433
434 docstring const BiblioInfo::getCiteNumber(docstring const & key) const
435 {
436         BiblioInfo::const_iterator it = find(key);
437         if (it == end())
438                 return docstring();
439         BibTeXInfo const & data = it->second;
440         return data.citeNumber();
441 }
442
443
444 docstring const BiblioInfo::getYear(docstring const & key, bool use_modifier) const
445 {
446         BiblioInfo::const_iterator it = find(key);
447         if (it == end())
448                 return docstring();
449         BibTeXInfo const & data = it->second;
450         docstring year = data.getYear();
451         if (year.empty()) {
452                 // let's try the crossref
453                 docstring const xref = data.getXRef();
454                 if (xref.empty())
455                         return _("No year"); // no luck
456                 BiblioInfo::const_iterator const xrefit = find(xref);
457                 if (xrefit == end())
458                         return _("No year"); // no luck again
459                 BibTeXInfo const & xref_data = xrefit->second;
460                 year = xref_data.getYear();
461         }
462         if (use_modifier && data.modifier() != 0)
463                 year += data.modifier();
464         return year;
465 }
466
467
468 docstring const BiblioInfo::getInfo(docstring const & key) const
469 {
470         BiblioInfo::const_iterator it = find(key);
471         if (it == end())
472                 return docstring();
473         BibTeXInfo const & data = it->second;
474         BibTeXInfo const * xrefptr = 0;
475         docstring const xref = data.getXRef();
476         if (!xref.empty()) {
477                 BiblioInfo::const_iterator const xrefit = find(xref);
478                 if (xrefit != end())
479                         xrefptr = &(xrefit->second);
480         }
481         return data.getInfo(xrefptr);
482 }
483
484
485 bool BiblioInfo::isBibtex(docstring const & key) const
486 {
487         BiblioInfo::const_iterator it = find(key);
488         if (it == end())
489                 return false;
490         return it->second.isBibTeX();
491 }
492
493
494
495 vector<docstring> const BiblioInfo::getCiteStrings(
496         docstring const & key, Buffer const & buf) const
497 {
498         CiteEngine const engine = buf.params().citeEngine();
499         if (engine == ENGINE_BASIC || engine == ENGINE_NATBIB_NUMERICAL)
500                 return getNumericalStrings(key, buf);
501         else
502                 return getAuthorYearStrings(key, buf);
503 }
504
505
506 vector<docstring> const BiblioInfo::getNumericalStrings(
507         docstring const & key, Buffer const & buf) const
508 {
509         if (empty())
510                 return vector<docstring>();
511
512         docstring const author = getAbbreviatedAuthor(key);
513         docstring const year   = getYear(key);
514         if (author.empty() || year.empty())
515                 return vector<docstring>();
516
517         vector<CiteStyle> const & styles = citeStyles(buf.params().citeEngine());
518         
519         vector<docstring> vec(styles.size());
520         for (size_t i = 0; i != vec.size(); ++i) {
521                 docstring str;
522
523                 switch (styles[i]) {
524                         case CITE:
525                         case CITEP:
526                                 str = from_ascii("[#ID]");
527                                 break;
528
529                         case NOCITE:
530                                 str = _("Add to bibliography only.");
531                                 break;
532
533                         case CITET:
534                                 str = author + " [#ID]";
535                                 break;
536
537                         case CITEALT:
538                                 str = author + " #ID";
539                                 break;
540
541                         case CITEALP:
542                                 str = from_ascii("#ID");
543                                 break;
544
545                         case CITEAUTHOR:
546                                 str = author;
547                                 break;
548
549                         case CITEYEAR:
550                                 str = year;
551                                 break;
552
553                         case CITEYEARPAR:
554                                 str = '(' + year + ')';
555                                 break;
556                 }
557
558                 vec[i] = str;
559         }
560
561         return vec;
562 }
563
564
565 vector<docstring> const BiblioInfo::getAuthorYearStrings(
566         docstring const & key, Buffer const & buf) const
567 {
568         if (empty())
569                 return vector<docstring>();
570
571         docstring const author = getAbbreviatedAuthor(key);
572         docstring const year   = getYear(key);
573         if (author.empty() || year.empty())
574                 return vector<docstring>();
575
576         vector<CiteStyle> const & styles = citeStyles(buf.params().citeEngine());
577         
578         vector<docstring> vec(styles.size());
579         for (size_t i = 0; i != vec.size(); ++i) {
580                 docstring str;
581
582                 switch (styles[i]) {
583                         case CITE:
584                 // jurabib only: Author/Annotator
585                 // (i.e. the "before" field, 2nd opt arg)
586                                 str = author + "/<" + _("before") + '>';
587                                 break;
588
589                         case NOCITE:
590                                 str = _("Add to bibliography only.");
591                                 break;
592
593                         case CITET:
594                                 str = author + " (" + year + ')';
595                                 break;
596
597                         case CITEP:
598                                 str = '(' + author + ", " + year + ')';
599                                 break;
600
601                         case CITEALT:
602                                 str = author + ' ' + year ;
603                                 break;
604
605                         case CITEALP:
606                                 str = author + ", " + year ;
607                                 break;
608
609                         case CITEAUTHOR:
610                                 str = author;
611                                 break;
612
613                         case CITEYEAR:
614                                 str = year;
615                                 break;
616
617                         case CITEYEARPAR:
618                                 str = '(' + year + ')';
619                                 break;
620                 }
621                 vec[i] = str;
622         }
623         return vec;
624 }
625
626
627 void BiblioInfo::mergeBiblioInfo(BiblioInfo const & info)
628 {
629         bimap_.insert(info.begin(), info.end());
630 }
631
632
633 namespace {
634         // used in xhtml to sort a list of BibTeXInfo objects
635         bool lSorter(BibTeXInfo const * lhs, BibTeXInfo const * rhs)
636         {
637                 docstring const lauth = lhs->getAbbreviatedAuthor();
638                 docstring const rauth = rhs->getAbbreviatedAuthor();
639                 docstring const lyear = lhs->getYear();
640                 docstring const ryear = rhs->getYear();
641                 docstring const ltitl = lhs->operator[]("title");
642                 docstring const rtitl = rhs->operator[]("title");
643                 return  (lauth < rauth)
644                                 || (lauth == rauth && lyear < ryear)
645                                 || (lauth == rauth && lyear == ryear && ltitl < rtitl);
646         }
647 }
648
649
650 void BiblioInfo::collectCitedEntries(Buffer const & buf)
651 {
652         cited_entries_.clear();
653         // We are going to collect all the citation keys used in the document,
654         // getting them from the TOC.
655         // FIXME We may want to collect these differently, in the first case,
656         // so that we might have them in order of appearance.
657         set<docstring> citekeys;
658         Toc const & toc = buf.tocBackend().toc("citation");
659         Toc::const_iterator it = toc.begin();
660         Toc::const_iterator const en = toc.end();
661         for (; it != en; ++it) {
662                 if (it->str().empty())
663                         continue;
664                 vector<docstring> const keys = getVectorFromString(it->str());
665                 citekeys.insert(keys.begin(), keys.end());
666         }
667         if (citekeys.empty())
668                 return;
669         
670         // We have a set of the keys used in this document.
671         // We will now convert it to a list of the BibTeXInfo objects used in 
672         // this document...
673         vector<BibTeXInfo const *> bi;
674         set<docstring>::const_iterator cit = citekeys.begin();
675         set<docstring>::const_iterator const cen = citekeys.end();
676         for (; cit != cen; ++cit) {
677                 BiblioInfo::const_iterator const bt = find(*cit);
678                 if (bt == end() || !bt->second.isBibTeX())
679                         continue;
680                 bi.push_back(&(bt->second));
681         }
682         // ...and sort it.
683         sort(bi.begin(), bi.end(), lSorter);
684         
685         // Now we can write the sorted keys
686         vector<BibTeXInfo const *>::const_iterator bit = bi.begin();
687         vector<BibTeXInfo const *>::const_iterator ben = bi.end();
688         for (; bit != ben; ++bit)
689                 cited_entries_.push_back((*bit)->key());
690 }
691
692
693 void BiblioInfo::makeCitationLabels(Buffer const & buf)
694 {
695         collectCitedEntries(buf);
696         CiteEngine const engine = buf.params().citeEngine();
697         bool const numbers = 
698                 (engine == ENGINE_BASIC || engine == ENGINE_NATBIB_NUMERICAL);
699
700         int keynumber = 0;
701         char modifier = 0;
702         // used to remember the last one we saw
703         // we'll be comparing entries to see if we need to add
704         // modifiers, like "1984a"
705         map<docstring, BibTeXInfo>::iterator last;
706
707         vector<docstring>::const_iterator it = cited_entries_.begin();
708         vector<docstring>::const_iterator const en = cited_entries_.end();
709         for (; it != en; ++it) {
710                 map<docstring, BibTeXInfo>::iterator const biit = bimap_.find(*it);
711                 // this shouldn't happen, but...
712                 if (biit == bimap_.end())
713                         // ...fail gracefully, anyway.
714                         continue;
715                 BibTeXInfo & entry = biit->second;
716                 if (numbers) {
717                         docstring const num = convert<docstring>(++keynumber);
718                         entry.setCiteNumber(num);
719                 } else {
720                         if (it != cited_entries_.begin()
721                             && entry.getAbbreviatedAuthor() == last->second.getAbbreviatedAuthor()
722                             // we access the year via getYear() so as to get it from the xref,
723                             // if we need to do so
724                             && getYear(entry.key()) == getYear(last->second.key())) {
725                                 if (modifier == 0) {
726                                         // so the last one should have been 'a'
727                                         last->second.setModifier('a');
728                                         modifier = 'b';
729                                 } else if (modifier == 'z')
730                                         modifier = 'A';
731                                 else
732                                         modifier++;
733                         } else {
734                                 modifier = 0;
735                         }
736                         entry.setModifier(modifier);                            
737                         // remember the last one
738                         last = biit;
739                 }
740         }
741 }
742
743
744 //////////////////////////////////////////////////////////////////////
745 //
746 // CitationStyle
747 //
748 //////////////////////////////////////////////////////////////////////
749
750 namespace {
751
752
753 char const * const citeCommands[] = {
754         "cite", "citet", "citep", "citealt", "citealp",
755         "citeauthor", "citeyear", "citeyearpar", "nocite" };
756
757 unsigned int const nCiteCommands =
758                 sizeof(citeCommands) / sizeof(char *);
759
760 CiteStyle const citeStylesArray[] = {
761         CITE, CITET, CITEP, CITEALT, CITEALP, 
762         CITEAUTHOR, CITEYEAR, CITEYEARPAR, NOCITE };
763
764 unsigned int const nCiteStyles =
765                 sizeof(citeStylesArray) / sizeof(CiteStyle);
766
767 CiteStyle const citeStylesFull[] = {
768         CITET, CITEP, CITEALT, CITEALP, CITEAUTHOR };
769
770 unsigned int const nCiteStylesFull =
771                 sizeof(citeStylesFull) / sizeof(CiteStyle);
772
773 CiteStyle const citeStylesUCase[] = {
774         CITET, CITEP, CITEALT, CITEALP, CITEAUTHOR };
775
776 unsigned int const nCiteStylesUCase =
777         sizeof(citeStylesUCase) / sizeof(CiteStyle);
778
779 } // namespace anon
780
781
782 CitationStyle citationStyleFromString(string const & command)
783 {
784         CitationStyle s;
785         if (command.empty())
786                 return s;
787
788         string cmd = command;
789         if (cmd[0] == 'C') {
790                 s.forceUpperCase = true;
791                 cmd[0] = 'c';
792         }
793
794         size_t const n = cmd.size() - 1;
795         if (cmd != "cite" && cmd[n] == '*') {
796                 s.full = true;
797                 cmd = cmd.substr(0, n);
798         }
799
800         char const * const * const last = citeCommands + nCiteCommands;
801         char const * const * const ptr = find(citeCommands, last, cmd);
802
803         if (ptr != last) {
804                 size_t idx = ptr - citeCommands;
805                 s.style = citeStylesArray[idx];
806         }
807         return s;
808 }
809
810
811 string citationStyleToString(const CitationStyle & s)
812 {
813         string cite = citeCommands[s.style];
814         if (s.full) {
815                 CiteStyle const * last = citeStylesFull + nCiteStylesFull;
816                 if (std::find(citeStylesFull, last, s.style) != last)
817                         cite += '*';
818         }
819
820         if (s.forceUpperCase) {
821                 CiteStyle const * last = citeStylesUCase + nCiteStylesUCase;
822                 if (std::find(citeStylesUCase, last, s.style) != last)
823                         cite[0] = 'C';
824         }
825
826         return cite;
827 }
828
829 vector<CiteStyle> citeStyles(CiteEngine engine)
830 {
831         unsigned int nStyles = 0;
832         unsigned int start = 0;
833
834         switch (engine) {
835                 case ENGINE_BASIC:
836                         nStyles = 2;
837                         start = 0;
838                         break;
839                 case ENGINE_NATBIB_AUTHORYEAR:
840                 case ENGINE_NATBIB_NUMERICAL:
841                         nStyles = nCiteStyles - 1;
842                         start = 1;
843                         break;
844                 case ENGINE_JURABIB:
845                         nStyles = nCiteStyles;
846                         start = 0;
847                         break;
848         }
849
850         vector<CiteStyle> styles(nStyles);
851         size_t i = 0;
852         int j = start;
853         for (; i != styles.size(); ++i, ++j)
854                 styles[i] = citeStylesArray[j];
855
856         return styles;
857 }
858
859 } // namespace lyx
860