Compounds | |
| struct | biblio::CitationStyle |
| Type returned by getCitationStyle, below. More... | |
| struct | biblio::compareNoCase |
| struct | biblio::RegexMatch |
Typedefs | |
| typedef std::map< string, string > | InfoMap |
| First entry is the bibliography key, second the data. More... | |
Enumerations | |
| enum | CiteStyle { CITE, CITET, CITEP, CITEALT, CITEALP, CITEAUTHOR, CITEYEAR, CITEYEARPAR } |
| enum | Search { SIMPLE, REGEX } |
| enum | Direction { FORWARD, BACKWARD } |
Functions | |
| string const | familyName (string const &name) |
| string const | getAbbreviatedAuthor (InfoMap const &map, string const &key) |
| return the short form of an authorlist. More... | |
| string const | getYear (InfoMap const &map, string const &key) |
| vector< string > const | getKeys (InfoMap const &map) |
| Returns a vector of bibliography keys. More... | |
| string const | getInfo (InfoMap const &map, string const &key) |
| Returns the BibTeX data associated with a given key. More... | |
| string const | escape_special_chars (string const &expr) |
| vector< string >::const_iterator | searchKeys (InfoMap const &theMap, vector< string > const &keys, string const &search_expr, vector< string >::const_iterator start, Search type, Direction dir, bool caseSensitive) |
| Returns an iterator to the first key that meets the search criterion, or end() if unsuccessful. More... | |
| string const | parseBibTeX (string data, string const &findkey) |
| Search a BibTeX info field for the given key and return the associated field. More... | |
| CitationStyle const | getCitationStyle (string const &command) |
| Given the LaTeX command, return the appropriate CitationStyle. More... | |
| string const | getCiteCommand (CiteStyle command, bool full, bool forceUCase) |
| Returns the LaTeX citation command. More... | |
| vector< CiteStyle > const | getCiteStyles (bool usingNatbib) |
| Returns a vector of available Citation styles. More... | |
| vector< string > const | getNumericalStrings (string const &key, InfoMap const &map, vector< CiteStyle > const &styles) |
| "Translates" the available Citation Styles into strings for this key. More... | |
| vector< string > const | getAuthorYearStrings (string const &key, InfoMap const &map, vector< CiteStyle > const &styles) |
| "Translates" the available Citation Styles into strings for this key. More... | |
Variables | |
| char const *const | citeCommands [] |
| unsigned int const | nCiteCommands |
| CiteStyle const | citeStyles [] |
| unsigned int const | nCiteStyles |
| CiteStyle const | citeStylesFull [] |
| unsigned int const | nCiteStylesFull |
| CiteStyle const | citeStylesUCase [] |
| unsigned int const | nCiteStylesUCase |
|
|
First entry is the bibliography key, second the data.
Definition at line 52 of file biblio.h. Referenced by biblio::RegexMatch::RegexMatch. |
|
|
Definition at line 24 of file biblio.h.
00024 {
00025 CITE,
00026 CITET,
00027 CITEP,
00028 CITEALT,
00029 CITEALP,
00030 CITEAUTHOR,
00031 CITEYEAR,
00032 CITEYEARPAR
00033 };
|
|
|
Definition at line 44 of file biblio.h.
|
|
|
Definition at line 36 of file biblio.h.
|
|
|
Definition at line 249 of file biblio.C.
00250 {
00251 // Search for all chars '.|*?+(){}[^$]\'
00252 // Note that '[' and '\' must be escaped.
00253 // This is a limitation of boost::regex, but all other chars in BREs
00254 // are assumed literal.
00255 boost::RegEx reg("[].|*?+(){}^$\\[\\\\]");
00256
00257 // $& is a perl-like expression that expands to all of the current match
00258 // The '$' must be prefixed with the escape character '\' for
00259 // boost to treat it as a literal.
00260 // Thus, to prefix a matched expression with '\', we use:
00261 return STRCONV(reg.Merge(STRCONV(expr), "\\\\$&"));
00262 }
|
|
|
Definition at line 36 of file biblio.C.
00037 {
00038 // Very simple parser
00039 string fname = name;
00040
00041 // possible authorname combinations are:
00042 // "Surname, FirstName"
00043 // "Surname, F."
00044 // "FirstName Surname"
00045 // "F. Surname"
00046 string::size_type idx = fname.find(',');
00047 if (idx != string::npos)
00048 return ltrim(fname.substr(0, idx));
00049 idx = fname.rfind('.');
00050 if (idx != string::npos)
00051 fname = ltrim(fname.substr(idx + 1));
00052 // test if we have a LaTeX Space in front
00053 if (fname[0] == '\\')
00054 return fname.substr(2);
00055
00056 return rtrim(fname);
00057 }
|
|
||||||||||||
|
return the short form of an authorlist.
Definition at line 60 of file biblio.C.
00061 {
00062 Assert(!map.empty());
00063
00064 InfoMap::const_iterator it = map.find(key);
00065 if (it == map.end())
00066 return string();
00067 string const & data = it->second;
00068
00069 // Is the entry a BibTeX one or one from lyx-layout "bibliography"?
00070 string::size_type const pos = data.find("TheBibliographyRef");
00071 if (pos != string::npos) {
00072 if (pos <= 2) {
00073 return string();
00074 }
00075
00076 string const opt = trim(data.substr(0, pos - 1));
00077 if (opt.empty())
00078 return string();
00079
00080 string authors;
00081 split(opt, authors, '(');
00082 return authors;
00083 }
00084
00085 string author = parseBibTeX(data, "author");
00086
00087 if (author.empty())
00088 author = parseBibTeX(data, "editor");
00089
00090 if (author.empty()) {
00091 author = parseBibTeX(data, "key");
00092 if (author.empty())
00093 author = key;
00094 return author;
00095 }
00096
00097 vector<string> const authors = getVectorFromString(author, " and ");
00098 if (authors.empty())
00099 return author;
00100
00101 if (authors.size() == 2)
00102 return bformat(_("%1$s and %2$s"),
00103 familyName(authors[0]), familyName(authors[1]));
00104
00105 if (authors.size() > 2)
00106 return bformat(_("%1$s et al."), familyName(authors[0]));
00107
00108 return familyName(authors[0]);
00109 }
|
|
||||||||||||||||
|
"Translates" the available Citation Styles into strings for this key. The returned string is displayed by the GUI. Eg, the vector will contain: Jones et al. (1990), (Jones et al. 1990), Jones et al. 1990, ... User supplies : the key, the InfoMap of bibkeys info, the available citation styles Definition at line 633 of file biblio.C. Referenced by ControlCitation::getCiteStrings.
00635 {
00636 if (map.empty()) {
00637 return vector<string>();
00638 }
00639
00640 string const author = getAbbreviatedAuthor(map, key);
00641 string const year = getYear(map, key);
00642 if (author.empty() || year.empty())
00643 return vector<string>();
00644
00645 vector<string> vec(styles.size());
00646 for (vector<string>::size_type i = 0; i != vec.size(); ++i) {
00647 string str;
00648
00649 switch (styles[i]) {
00650 case CITE:
00651 case CITET:
00652 str = author + " (" + year + ')';
00653 break;
00654
00655 case CITEP:
00656 str = '(' + author + ", " + year + ')';
00657 break;
00658
00659 case CITEALT:
00660 str = author + ' ' + year ;
00661 break;
00662
00663 case CITEALP:
00664 str = author + ", " + year ;
00665 break;
00666
00667 case CITEAUTHOR:
00668 str = author;
00669 break;
00670
00671 case CITEYEAR:
00672 str = year;
00673 break;
00674
00675 case CITEYEARPAR:
00676 str = '(' + year + ')';
00677 break;
00678 }
00679
00680 vec[i] = str;
00681 }
00682
00683 return vec;
00684 }
|
|
|
Given the LaTeX command, return the appropriate CitationStyle.
Definition at line 507 of file biblio.C. Referenced by QCitation::updateStyle, and updateStyle.
00508 {
00509 if (command.empty()) return CitationStyle();
00510
00511 CitationStyle cs;
00512 string cmd = command;
00513
00514 if (cmd[0] == 'C') {
00515 cs.forceUCase = true;
00516 cmd[0] = 'c';
00517 }
00518
00519 size_t n = cmd.size() - 1;
00520 if (cmd[n] == '*') {
00521 cs.full = true;
00522 cmd = cmd.substr(0,n);
00523 }
00524
00525 char const * const * const last = citeCommands + nCiteCommands;
00526 char const * const * const ptr = std::find(citeCommands, last, cmd);
00527
00528 if (ptr != last) {
00529 size_t idx = ptr - citeCommands;
00530 cs.style = citeStyles[idx];
00531 }
00532
00533 return cs;
00534 }
|
|
||||||||||||||||
|
Returns the LaTeX citation command. User supplies : The CiteStyle enum, a flag forcing the full author list, a flag forcing upper case, e.g. "della Casa" becomes "Della Case" Definition at line 537 of file biblio.C. Referenced by QCitation::apply, and FormCitation::apply.
00538 {
00539 string cite = citeCommands[command];
00540 if (full) {
00541 CiteStyle const * last = citeStylesFull + nCiteStylesFull;
00542 if (std::find(citeStylesFull, last, command) != last)
00543 cite += '*';
00544 }
00545
00546 if (forceUCase) {
00547 CiteStyle const * last = citeStylesUCase + nCiteStylesUCase;
00548 if (std::find(citeStylesUCase, last, command) != last)
00549 cite[0] = 'C';
00550 }
00551
00552 return cite;
00553 }
|
|
|
Returns a vector of available Citation styles.
Definition at line 556 of file biblio.C. Referenced by ControlCitation::getCiteStrings, and ControlCitation::initialiseParams.
00557 {
00558 unsigned int nStyles = 1;
00559 unsigned int start = 0;
00560 if (usingNatbib) {
00561 nStyles = nCiteStyles - 1;
00562 start = 1;
00563 }
00564
00565 vector<CiteStyle> styles(nStyles);
00566
00567 vector<CiteStyle>::size_type i = 0;
00568 int j = start;
00569 for (; i != styles.size(); ++i, ++j) {
00570 styles[i] = citeStyles[j];
00571 }
00572
00573 return styles;
00574 }
|
|
||||||||||||
|
Returns the BibTeX data associated with a given key. Empty if no info exists. Definition at line 176 of file biblio.C.
00177 {
00178 Assert(!map.empty());
00179
00180 InfoMap::const_iterator it = map.find(key);
00181 if (it == map.end())
00182 return string();
00183 string const & data = it->second;
00184
00185 // is the entry a BibTeX one or one from lyx-layout "bibliography"?
00186 string const separator("TheBibliographyRef");
00187 string::size_type const pos = data.find(separator);
00188 if (pos != string::npos) {
00189 string::size_type const pos2 = pos + separator.size();
00190 string const info = trim(data.substr(pos2));
00191 return info;
00192 }
00193
00194 // Search for all possible "required" keys
00195 string author = parseBibTeX(data, "author");
00196 if (author.empty())
00197 author = parseBibTeX(data, "editor");
00198
00199 string year = parseBibTeX(data, "year");
00200 string title = parseBibTeX(data, "title");
00201 string booktitle = parseBibTeX(data, "booktitle");
00202 string chapter = parseBibTeX(data, "chapter");
00203 string number = parseBibTeX(data, "number");
00204 string volume = parseBibTeX(data, "volume");
00205 string pages = parseBibTeX(data, "pages");
00206
00207 string media = parseBibTeX(data, "journal");
00208 if (media.empty())
00209 media = parseBibTeX(data, "publisher");
00210 if (media.empty())
00211 media = parseBibTeX(data, "school");
00212 if (media.empty())
00213 media = parseBibTeX(data, "institution");
00214
00215 ostringstream result;
00216 if (!author.empty())
00217 result << author << ", ";
00218 if (!title.empty())
00219 result << title;
00220 if (!booktitle.empty())
00221 result << ", in " << booktitle;
00222 if (!chapter.empty())
00223 result << ", Ch. " << chapter;
00224 if (!media.empty())
00225 result << ", " << media;
00226 if (!volume.empty())
00227 result << ", vol. " << volume;
00228 if (!number.empty())
00229 result << ", no. " << number;
00230 if (!pages.empty())
00231 result << ", pp. " << pages;
00232 if (!year.empty())
00233 result << ", " << year;
00234
00235 string const result_str = rtrim(STRCONV(result.str()));
00236 if (!result_str.empty())
00237 return result_str;
00238
00239 // This should never happen (or at least be very unusual!)
00240 return data;
00241 }
|
|
|
Returns a vector of bibliography keys.
Definition at line 162 of file biblio.C. Referenced by FormCitation::update, and QCitation::update_contents.
00163 {
00164 vector<string> bibkeys;
00165 InfoMap::const_iterator it = map.begin();
00166 InfoMap::const_iterator end = map.end();
00167 for (; it != end; ++it) {
00168 bibkeys.push_back(it->first);
00169 }
00170
00171 std::sort(bibkeys.begin(), bibkeys.end(), compareNoCase());
00172 return bibkeys;
00173 }
|
|
||||||||||||||||
|
"Translates" the available Citation Styles into strings for this key. The returned string is displayed by the GUI. [XX] is used in place of the actual reference Eg, the vector will contain: [XX], Jones et al. [XX], ... User supplies : the key, the InfoMap of bibkeys info, the available citation styles Definition at line 578 of file biblio.C. Referenced by ControlCitation::getCiteStrings.
00580 {
00581 if (map.empty()) {
00582 return vector<string>();
00583 }
00584
00585 string const author = getAbbreviatedAuthor(map, key);
00586 string const year = getYear(map, key);
00587 if (author.empty() || year.empty())
00588 return vector<string>();
00589
00590 vector<string> vec(styles.size());
00591 for (vector<string>::size_type i = 0; i != vec.size(); ++i) {
00592 string str;
00593
00594 switch (styles[i]) {
00595 case CITE:
00596 case CITEP:
00597 str = "[#ID]";
00598 break;
00599
00600 case CITET:
00601 str = author + " [#ID]";
00602 break;
00603
00604 case CITEALT:
00605 str = author + " #ID";
00606 break;
00607
00608 case CITEALP:
00609 str = "#ID";
00610 break;
00611
00612 case CITEAUTHOR:
00613 str = author;
00614 break;
00615
00616 case CITEYEAR:
00617 str = year;
00618 break;
00619
00620 case CITEYEARPAR:
00621 str = '(' + year + ')';
00622 break;
00623 }
00624
00625 vec[i] = str;
00626 }
00627
00628 return vec;
00629 }
|
|
||||||||||||
|
Definition at line 112 of file biblio.C.
00113 {
00114 Assert(!map.empty());
00115
00116 InfoMap::const_iterator it = map.find(key);
00117 if (it == map.end())
00118 return string();
00119 string const & data = it->second;
00120
00121 // Is the entry a BibTeX one or one from lyx-layout "bibliography"?
00122 string::size_type const pos = data.find("TheBibliographyRef");
00123 if (pos != string::npos) {
00124 if (pos <= 2) {
00125 return string();
00126 }
00127
00128 string const opt =
00129 trim(data.substr(0, pos - 1));
00130 if (opt.empty())
00131 return string();
00132
00133 string authors;
00134 string const tmp = split(opt, authors, '(');
00135 string year;
00136 split(tmp, year, ')');
00137 return year;
00138
00139 }
00140
00141 string year = parseBibTeX(data, "year");
00142 if (year.empty())
00143 year = _("No year");
00144
00145 return year;
00146 }
|
|
||||||||||||
|
Search a BibTeX info field for the given key and return the associated field.
Definition at line 344 of file biblio.C.
00345 {
00346 string keyvalue;
00347 // at first we delete all characters right of '%' and
00348 // replace tabs through a space and remove leading spaces
00349 // we read the data line by line so that the \n are
00350 // ignored, too.
00351 string data_;
00352 int Entries = 0;
00353 string dummy = token(data,'\n', Entries);
00354 while (!dummy.empty()) {
00355 dummy = subst(dummy, '\t', ' '); // no tabs
00356 dummy = ltrim(dummy); // no leading spaces
00357 // ignore lines with a beginning '%' or ignore all right of %
00358 string::size_type const idx =
00359 dummy.empty() ? string::npos : dummy.find('%');
00360 if (idx != string::npos)
00361 dummy.erase(idx, string::npos);
00362 // do we have a new token or a new line of
00363 // the same one? In the first case we ignore
00364 // the \n and in the second we replace it
00365 // with a space
00366 if (!dummy.empty()) {
00367 if (!contains(dummy, "="))
00368 data_ += ' ' + dummy;
00369 else
00370 data_ += dummy;
00371 }
00372 dummy = token(data, '\n', ++Entries);
00373 }
00374
00375 // replace double commas with "" for easy scanning
00376 data = subst(data_, ",,", "\"\"");
00377
00378 // unlikely!
00379 if (data.empty())
00380 return string();
00381
00382 // now get only the important line of the bibtex entry.
00383 // all entries are devided by ',' except the last one.
00384 data += ','; // now we have same behaviour for all entries
00385 // because the last one is "blah ... }"
00386 Entries = 0;
00387 bool found = false;
00388 // parsing of title and booktitle is different from the
00389 // others, because booktitle contains title
00390 do {
00391 dummy = token(data, ',', Entries++);
00392 if (!dummy.empty()) {
00393 found = contains(ascii_lowercase(dummy), findkey);
00394 if (findkey == "title" &&
00395 contains(ascii_lowercase(dummy), "booktitle"))
00396 found = false;
00397 }
00398 } while (!found && !dummy.empty());
00399 if (dummy.empty())
00400 // no such keyword
00401 return string();
00402
00403 // we are not sure, if we get all, because "key= "blah, blah" is
00404 // allowed.
00405 // Therefore we read all until the next "=" character, which follows a
00406 // new keyword
00407 keyvalue = dummy;
00408 dummy = token(data, ',', Entries++);
00409 while (!contains(dummy, '=') && !dummy.empty()) {
00410 keyvalue += ',' + dummy;
00411 dummy = token(data, ',', Entries++);
00412 }
00413
00414 // replace double "" with originals ,, (two commas)
00415 // leaving us with the all-important line
00416 data = subst(keyvalue, "\"\"", ",,");
00417
00418 // Clean-up.
00419 // 1. Spaces
00420 data = rtrim(data);
00421 // 2. if there is no opening '{' then a closing '{' is probably cruft.
00422 if (!contains(data, '{'))
00423 data = rtrim(data, "}");
00424 // happens, when last keyword
00425 string::size_type const idx =
00426 !data.empty() ? data.find('=') : string::npos;
00427
00428 if (idx == string::npos)
00429 return string();
00430
00431 data = trim(data.substr(idx));
00432
00433 if (data.length() < 2 || data[0] != '=') { // a valid entry?
00434 return string();
00435 } else {
00436 // delete '=' and the following spaces
00437 data = ltrim(data, " =");
00438 if (data.length() < 2) {
00439 return data; // not long enough to find delimiters
00440 } else {
00441 string::size_type keypos = 1;
00442 char enclosing;
00443 if (data[0] == '{') {
00444 enclosing = '}';
00445 } else if (data[0] == '"') {
00446 enclosing = '"';
00447 } else {
00448 // no {} and no "", pure data but with a
00449 // possible ',' at the end
00450 return rtrim(data, ",");
00451 }
00452 string tmp = data.substr(keypos);
00453 while (tmp.find('{') != string::npos &&
00454 tmp.find('}') != string::npos &&
00455 tmp.find('{') < tmp.find('}') &&
00456 tmp.find('{') < tmp.find(enclosing)) {
00457
00458 keypos += tmp.find('{') + 1;
00459 tmp = data.substr(keypos);
00460 keypos += tmp.find('}') + 1;
00461 tmp = data.substr(keypos);
00462 }
00463 if (tmp.find(enclosing) == string::npos)
00464 return data;
00465 else {
00466 keypos += tmp.find(enclosing);
00467 return data.substr(1, keypos - 1);
00468 }
00469 }
00470 }
00471 }
|
|
||||||||||||||||||||||||||||||||
|
Returns an iterator to the first key that meets the search criterion, or end() if unsuccessful. User supplies : the InfoMap of bibkeys info, the vector of keys to be searched, the search criterion, an iterator defining the starting point of the search, an enum defining a Simple or Regex search, an enum defining the search direction. Definition at line 301 of file biblio.C. Referenced by QCitationDialog::find, and FormCitation::findBiblio.
00308 {
00309 // Preliminary checks
00310 if (start < keys.begin() || start >= keys.end())
00311 return keys.end();
00312
00313 string expr = trim(search_expr);
00314 if (expr.empty())
00315 return keys.end();
00316
00317 if (type == SIMPLE)
00318 // We must escape special chars in the search_expr so that
00319 // it is treated as a simple string by boost::regex.
00320 expr = escape_special_chars(expr);
00321
00322 // Build the functor that will be passed to find_if.
00323 RegexMatch const match(theMap, expr, !caseSensitive);
00324 if (!match.validRE())
00325 return keys.end();
00326
00327 // Search the vector of 'keys' from 'start' for one that matches the
00328 // predicate 'match'. Searching can be forward or backward from start.
00329 if (dir == FORWARD)
00330 return std::find_if(start, keys.end(), match);
00331
00332 vector<string>::const_reverse_iterator rit(start);
00333 vector<string>::const_reverse_iterator rend = keys.rend();
00334 rit = std::find_if(rit, rend, match);
00335
00336 if (rit == rend)
00337 return keys.end();
00338 // This is correct and always safe.
00339 // (See Meyer's Effective STL, Item 28.)
00340 return (++rit).base();
00341 }
|
|
|
Initial value: {
"cite", "citet", "citep", "citealt", "citealp", "citeauthor",
"citeyear", "citeyearpar" } |
|
|
Initial value: {
CITE, CITET, CITEP, CITEALT, CITEALP,
CITEAUTHOR, CITEYEAR, CITEYEARPAR } |
|
|
Initial value: {
CITET, CITEP, CITEALT, CITEALP, CITEAUTHOR } |
|
|
Initial value: {
CITET, CITEP, CITEALT, CITEALP, CITEAUTHOR } |
|
|
Initial value:
sizeof(citeCommands) / sizeof(char *) |
|
|
Initial value:
sizeof(citeStyles) / sizeof(CiteStyle) |
|
|
Initial value:
sizeof(citeStylesFull) / sizeof(CiteStyle) |
|
|
Initial value:
sizeof(citeStylesUCase) / sizeof(CiteStyle) |
1.2.14 written by Dimitri van Heesch,
© 1997-2002