From 66ef9d45417ab4d8c4e0ecbf519e2c751362f85d Mon Sep 17 00:00:00 2001 From: Igor Date: Sat, 13 Nov 2010 18:31:58 +0300 Subject: Format author --- bibtex.php | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/bibtex.php b/bibtex.php index 88904d4..a66b0c6 100644 --- a/bibtex.php +++ b/bibtex.php @@ -161,6 +161,7 @@ class BibtexParser { $text = preg_replace('/([^\\\\])~/u', '\\1 ', $text); $text = preg_replace('/<<(.*?)>>/u', '«\1»', $text); + $text = preg_replace('/``(.*?)\'\'/u', '“\1”', $text); $text = preg_replace('/(\d+)\s*-{1,3}\s*(\d+)/u', '\1–\2', $text); $text = preg_replace('/---/u', '—', $text); $text = preg_replace('/--/u', '–', $text); @@ -348,7 +349,8 @@ class BibtexParserTeam extends BibtexParser protected function format_editor() { $this->format_field_default('editor'); - $this->entry['editor'] = $this->_('Ed. by') . ' ' . $this->entry['editor']; + $this->entry['editor'] = $this->_('Ed. by') + . ' ' . $this->format_author1($this->entry['editor']); } protected function format_volume() @@ -370,10 +372,37 @@ class BibtexParserTeam extends BibtexParser $this->entry['number'] = $this->_('no.') . ' ' . $this->entry['number']; } + + + /* + * И.Н. Пашев => Пашев И. Н. + * Игорь Пашев => Пашев И. + * Иг. Пашев => Пашев Иг. + * Пашев, Игорь Николаевич => Пашев И. Н. + * Пашев, И. Н. => Пашев И. Н. + */ protected function format_author1($author) { - $res = ''; - $res = $this->latex2html($author); + $res = ''; $aa = array(); + $author = preg_replace('/\s*\.\s*/', '. ', $this->latex2html($author)); + + if ($i = mb_strpos($author, ',')) + { + $main = mb_substr($author, 0, $i); + $aa = preg_split('/\s+/u', trim(mb_substr($author, $i+1))); + } + else + { + $aa = preg_split('/\s+/u', $author); + $main = array_pop($aa); + } + + foreach ($aa as &$i) + $i = preg_replace('/^(.)[^.]*$/u', '$1.', $i); + + array_unshift ($aa, $main); + $res = implode(' ', $aa); + return $res; } @@ -448,7 +477,7 @@ class BibtexParserTeam extends BibtexParser protected function format_book() { - $parts = array(); // All parts are connected with '. — ' + $parts = array(); // All parts are joined with '. — ' $part = ''; // FIXME : If $this->entry['count_authors'] > 3, place them after title? @@ -507,7 +536,7 @@ class BibtexParserTeam extends BibtexParser protected function format_article() { - $parts = array(); // All parts are connected with '. — ' + $parts = array(); // All parts are joined with '. — ' $part = ''; // FIXME : If $this->entry['count_authors'] > 3, place them after title? @@ -556,7 +585,7 @@ class BibtexParserTeam extends BibtexParser protected function format_grant() { - $parts = array(); // All parts are connected with '. — ' + $parts = array(); // All parts are joined with '. — ' if (!empty($this->entry['organization'])) @@ -595,7 +624,7 @@ class BibtexParserTeam extends BibtexParser protected function format_inproceedings() { - $parts = array(); // All parts are connected with '. — ' + $parts = array(); // All parts are joined with '. — ' $part = ''; if (!empty($this->entry['author'])) -- cgit v1.2.3