]> git.lyx.org Git - lyx.git/blob - src/BiblioInfo.cpp
bc30499b35191ac1ea11503abeb1847ecdcebfac
[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 vector<docstring> const BiblioInfo::getCiteStrings(
486         docstring const & key, Buffer const & buf) const
487 {
488         CiteEngine const engine = buf.params().citeEngine();
489         if (engine == ENGINE_BASIC || engine == ENGINE_NATBIB_NUMERICAL)
490                 return getNumericalStrings(key, buf);
491         else
492                 return getAuthorYearStrings(key, buf);
493 }
494
495
496 vector<docstring> const BiblioInfo::getNumericalStrings(
497         docstring const & key, Buffer const & buf) const
498 {
499         if (empty())
500                 return vector<docstring>();
501
502         docstring const author = getAbbreviatedAuthor(key);
503         docstring const year   = getYear(key);
504         if (author.empty() || year.empty())
505                 return vector<docstring>();
506
507         vector<CiteStyle> const & styles = citeStyles(buf.params().citeEngine());
508         
509         vector<docstring> vec(styles.size());
510         for (size_t i = 0; i != vec.size(); ++i) {
511                 docstring str;
512
513                 switch (styles[i]) {
514                         case CITE:
515                         case CITEP:
516                                 str = from_ascii("[#ID]");
517                                 break;
518
519                         case NOCITE:
520                                 str = _("Add to bibliography only.");
521                                 break;
522
523                         case CITET:
524                                 str = author + " [#ID]";
525                                 break;
526
527                         case CITEALT:
528                                 str = author + " #ID";
529                                 break;
530
531                         case CITEALP:
532                                 str = from_ascii("#ID");
533                                 break;
534
535                         case CITEAUTHOR:
536                                 str = author;
537                                 break;
538
539                         case CITEYEAR:
540                                 str = year;
541                                 break;
542
543                         case CITEYEARPAR:
544                                 str = '(' + year + ')';
545                                 break;
546                 }
547
548                 vec[i] = str;
549         }
550
551         return vec;
552 }
553
554
555 vector<docstring> const BiblioInfo::getAuthorYearStrings(
556         docstring const & key, Buffer const & buf) const
557 {
558         if (empty())
559                 return vector<docstring>();
560
561         docstring const author = getAbbreviatedAuthor(key);
562         docstring const year   = getYear(key);
563         if (author.empty() || year.empty())
564                 return vector<docstring>();
565
566         vector<CiteStyle> const & styles = citeStyles(buf.params().citeEngine());
567         
568         vector<docstring> vec(styles.size());
569         for (size_t i = 0; i != vec.size(); ++i) {
570                 docstring str;
571
572                 switch (styles[i]) {
573                         case CITE:
574                 // jurabib only: Author/Annotator
575                 // (i.e. the "before" field, 2nd opt arg)
576                                 str = author + "/<" + _("before") + '>';
577                                 break;
578
579                         case NOCITE:
580                                 str = _("Add to bibliography only.");
581                                 break;
582
583                         case CITET:
584                                 str = author + " (" + year + ')';
585                                 break;
586
587                         case CITEP:
588                                 str = '(' + author + ", " + year + ')';
589                                 break;
590
591                         case CITEALT:
592                                 str = author + ' ' + year ;
593                                 break;
594
595                         case CITEALP:
596                                 str = author + ", " + year ;
597                                 break;
598
599                         case CITEAUTHOR:
600                                 str = author;
601                                 break;
602
603                         case CITEYEAR:
604                                 str = year;
605                                 break;
606
607                         case CITEYEARPAR:
608                                 str = '(' + year + ')';
609                                 break;
610                 }
611                 vec[i] = str;
612         }
613         return vec;
614 }
615
616
617 void BiblioInfo::mergeBiblioInfo(BiblioInfo const & info)
618 {
619         bimap_.insert(info.begin(), info.end());
620 }
621
622
623 namespace {
624         // used in xhtml to sort a list of BibTeXInfo objects
625         bool lSorter(BibTeXInfo const * lhs, BibTeXInfo const * rhs)
626         {
627                 docstring const lauth = lhs->getAbbreviatedAuthor();
628                 docstring const rauth = rhs->getAbbreviatedAuthor();
629                 docstring const lyear = lhs->getYear();
630                 docstring const ryear = rhs->getYear();
631                 docstring const ltitl = lhs->operator[]("title");
632                 docstring const rtitl = rhs->operator[]("title");
633                 return  (lauth < rauth)
634                                 || (lauth == rauth && lyear < ryear)
635                                 || (lauth == rauth && lyear == ryear && ltitl < rtitl);
636         }
637 }
638
639
640 void BiblioInfo::collectCitedEntries(Buffer const & buf)
641 {
642         cited_entries_.clear();
643         // We are going to collect all the citation keys used in the document,
644         // getting them from the TOC.
645         // FIXME We may want to collect these differently, in the first case,
646         // so that we might have them in order of appearance.
647         set<docstring> citekeys;
648         Toc const & toc = buf.tocBackend().toc("citation");
649         Toc::const_iterator it = toc.begin();
650         Toc::const_iterator const en = toc.end();
651         for (; it != en; ++it) {
652                 if (it->str().empty())
653                         continue;
654                 vector<docstring> const keys = getVectorFromString(it->str());
655                 citekeys.insert(keys.begin(), keys.end());
656         }
657         if (citekeys.empty())
658                 return;
659         
660         // We have a set of the keys used in this document.
661         // We will now convert it to a list of the BibTeXInfo objects used in 
662         // this document...
663         vector<BibTeXInfo const *> bi;
664         set<docstring>::const_iterator cit = citekeys.begin();
665         set<docstring>::const_iterator const cen = citekeys.end();
666         for (; cit != cen; ++cit) {
667                 BiblioInfo::const_iterator const bt = find(*cit);
668                 if (bt == end() || !bt->second.isBibTeX())
669                         continue;
670                 bi.push_back(&(bt->second));
671         }
672         // ...and sort it.
673         sort(bi.begin(), bi.end(), lSorter);
674         
675         // Now we can write the sorted keys
676         vector<BibTeXInfo const *>::const_iterator bit = bi.begin();
677         vector<BibTeXInfo const *>::const_iterator ben = bi.end();
678         for (; bit != ben; ++bit)
679                 cited_entries_.push_back((*bit)->key());
680 }
681
682
683 void BiblioInfo::makeCitationLabels(Buffer const & buf)
684 {
685         collectCitedEntries(buf);
686         CiteEngine const engine = buf.params().citeEngine();
687         bool const numbers = 
688                 (engine == ENGINE_BASIC || engine == ENGINE_NATBIB_NUMERICAL);
689
690         int keynumber = 0;
691         char modifier = 0;
692         // used to remember the last one we saw
693         // we'll be comparing entries to see if we need to add
694         // modifiers, like "1984a"
695         map<docstring, BibTeXInfo>::iterator last;
696
697         vector<docstring>::const_iterator it = cited_entries_.begin();
698         vector<docstring>::const_iterator const en = cited_entries_.end();
699         for (; it != en; ++it) {
700                 map<docstring, BibTeXInfo>::iterator const biit = bimap_.find(*it);
701                 // this shouldn't happen, but...
702                 if (biit == bimap_.end())
703                         // ...fail gracefully, anyway.
704                         continue;
705                 BibTeXInfo & entry = biit->second;
706                 if (numbers) {
707                         docstring const num = convert<docstring>(++keynumber);
708                         entry.setCiteNumber(num);
709                 } else {
710                         if (it != cited_entries_.begin()
711                             && entry.getAbbreviatedAuthor() == last->second.getAbbreviatedAuthor()
712                             // we access the year via getYear() so as to get it from the xref,
713                             // if we need to do so
714                             && getYear(entry.key()) == getYear(last->second.key())) {
715                                 if (modifier == 0) {
716                                         // so the last one should have been 'a'
717                                         last->second.setModifier('a');
718                                         modifier = 'b';
719                                 } else if (modifier == 'z')
720                                         modifier = 'A';
721                                 else
722                                         modifier++;
723                         } else {
724                                 modifier = 0;
725                         }
726                         entry.setModifier(modifier);                            
727                         // remember the last one
728                         last = biit;
729                 }
730         }
731 }
732
733
734 //////////////////////////////////////////////////////////////////////
735 //
736 // CitationStyle
737 //
738 //////////////////////////////////////////////////////////////////////
739
740 namespace {
741
742
743 char const * const citeCommands[] = {
744         "cite", "citet", "citep", "citealt", "citealp",
745         "citeauthor", "citeyear", "citeyearpar", "nocite" };
746
747 unsigned int const nCiteCommands =
748                 sizeof(citeCommands) / sizeof(char *);
749
750 CiteStyle const citeStylesArray[] = {
751         CITE, CITET, CITEP, CITEALT, CITEALP, 
752         CITEAUTHOR, CITEYEAR, CITEYEARPAR, NOCITE };
753
754 unsigned int const nCiteStyles =
755                 sizeof(citeStylesArray) / sizeof(CiteStyle);
756
757 CiteStyle const citeStylesFull[] = {
758         CITET, CITEP, CITEALT, CITEALP, CITEAUTHOR };
759
760 unsigned int const nCiteStylesFull =
761                 sizeof(citeStylesFull) / sizeof(CiteStyle);
762
763 CiteStyle const citeStylesUCase[] = {
764         CITET, CITEP, CITEALT, CITEALP, CITEAUTHOR };
765
766 unsigned int const nCiteStylesUCase =
767         sizeof(citeStylesUCase) / sizeof(CiteStyle);
768
769 } // namespace anon
770
771
772 CitationStyle citationStyleFromString(string const & command)
773 {
774         CitationStyle s;
775         if (command.empty())
776                 return s;
777
778         string cmd = command;
779         if (cmd[0] == 'C') {
780                 s.forceUpperCase = true;
781                 cmd[0] = 'c';
782         }
783
784         size_t const n = cmd.size() - 1;
785         if (cmd != "cite" && cmd[n] == '*') {
786                 s.full = true;
787                 cmd = cmd.substr(0, n);
788         }
789
790         char const * const * const last = citeCommands + nCiteCommands;
791         char const * const * const ptr = find(citeCommands, last, cmd);
792
793         if (ptr != last) {
794                 size_t idx = ptr - citeCommands;
795                 s.style = citeStylesArray[idx];
796         }
797         return s;
798 }
799
800
801 string citationStyleToString(const CitationStyle & s)
802 {
803         string cite = citeCommands[s.style];
804         if (s.full) {
805                 CiteStyle const * last = citeStylesFull + nCiteStylesFull;
806                 if (std::find(citeStylesFull, last, s.style) != last)
807                         cite += '*';
808         }
809
810         if (s.forceUpperCase) {
811                 CiteStyle const * last = citeStylesUCase + nCiteStylesUCase;
812                 if (std::find(citeStylesUCase, last, s.style) != last)
813                         cite[0] = 'C';
814         }
815
816         return cite;
817 }
818
819 vector<CiteStyle> citeStyles(CiteEngine engine)
820 {
821         unsigned int nStyles = 0;
822         unsigned int start = 0;
823
824         switch (engine) {
825                 case ENGINE_BASIC:
826                         nStyles = 2;
827                         start = 0;
828                         break;
829                 case ENGINE_NATBIB_AUTHORYEAR:
830                 case ENGINE_NATBIB_NUMERICAL:
831                         nStyles = nCiteStyles - 1;
832                         start = 1;
833                         break;
834                 case ENGINE_JURABIB:
835                         nStyles = nCiteStyles;
836                         start = 0;
837                         break;
838         }
839
840         vector<CiteStyle> styles(nStyles);
841         size_t i = 0;
842         int j = start;
843         for (; i != styles.size(); ++i, ++j)
844                 styles[i] = citeStylesArray[j];
845
846         return styles;
847 }
848
849 } // namespace lyx
850