<commit_before># Copyright (C) 2006, 2007, 2008  <NAME>
#
# This file is part of pybtex.
#
# pybtex is free software; you can redistribute it and/or modify
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# pybtex is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pybtex; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
# USA

"""name formatting styles
"""
from pybtex.richtext import Symbol, Text, nbsp
from pybtex.style.template import join, together, node, _format_list
from pybtex.bibtex.name import tie_or_space

@node
def name_part(children, data, before='', tie=False):
    parts = together [children].format_data(data)
    if not parts:
        return Text()
    if tie:
        return Text(before, parts, tie_or_space(parts, nbsp, ' '))
    else:
        return Text(before, parts)


def plain(person, abbr=False):
    r"""
    >>> from pybtex.core import Person
    >>> name = Person(string=r"<NAME>{\'e}<NAME>")
    >>> print plain(name).format().plaintext()
    de<nbsp>la Vall{\'e}e<nbsp>Poussin, <NAME><nbsp>Joseph
    >>> print plain(name, abbr=True).format().plaintext()
    de<nbsp>la Vall{\'e}e<nbsp>Poussin, C.<nbsp><NAME>.<nbsp>J.
    >>> name = Person(first='First', last='Last', middle='Middle')
    >>> print plain(name).format().plaintext()
    Last, First<nbsp>Middle
    >>> print plain(name, abbr=True).format().plaintext()
    Last, F.<nbsp>M.

    """
    return join [
        name_part(tie=True) [person.prelast()],
        name_part [person.last()],
        name_part(before=', ') [person.lineage()],
        name_part(before=', ') [person.first(abbr) + person.middle(abbr)],
    ]<commit_msg>Rename names.plain to last_first, add a real plain style ({ff~}{vv~}{ll}{, jj}).<commit_after># Copyright (C) 2006, 2007, 2008  <NAME>
#
# This file is part of pybtex.
#
# pybtex is free software; you can redistribute it and/or modify
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# pybtex is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pybtex; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
# USA

"""name formatting styles
"""
from pybtex.richtext import Symbol, Text, nbsp
from pybtex.style.template import join, together, node, _format_list
from pybtex.bibtex.name import tie_or_space

@node
def name_part(children, data, before='', tie=False):
    parts = together [children].format_data(data)
    if not parts:
        return Text()
    if tie:
        return Text(before, parts, tie_or_space(parts, nbsp, ' '))
    else:
        return Text(before, parts)


def plain(person, abbr=False):
    r"""
    {ff~}{vv~}{ll}{, jj}

    >>> from pybtex.core import Person
    >>> name = Person(string=r"<NAME>{\'e}<NAME>")
    >>> print plain(name).format().plaintext()
    <NAME><nbsp>Joseph de<nbsp>la Vall{\'e}e<nbsp>Poussin
    >>> print plain(name, abbr=True).format().plaintext()
    C.<nbsp>L. X.<nbsp>J. de<nbsp>la Vall{\'e}e<nbsp>Poussin

    >>> name = Person(first='First', last='Last', middle='Middle')
    >>> print plain(name).format().plaintext()
    First<nbsp>Middle Last
    >>> print plain(name, abbr=True).format().plaintext()
    F.<nbsp>M. Last
    """
    return join [
        name_part(tie=True) [person.first(abbr) + person.middle(abbr)],
        name_part(tie=True) [person.prelast()],
        name_part [person.last()],
        name_part(before=', ') [person.lineage()]
    ]

def last_first(person, abbr=False):
    r"""
    >>> from pybtex.core import Person
    >>> name = Person(string=r"<NAME>{\'e}<NAME>")
    >>> print last_first(name).format().plaintext()
    de<nbsp>la Vall{\'e}e<nbsp>Poussin, <NAME><nbsp>Joseph
    >>> print last_first(name, abbr=True).format().plaintext()
    de<nbsp>la Vall{\'e}e<nbsp>Poussin, C.<nbsp>L. X.<nbsp>J.

    >>> name = Person(first='First', last='Last', middle='Middle')
    >>> print last_first(name).format().plaintext()
    Last, First<nbsp>Middle
    >>> print last_first(name, abbr=True).format().plaintext()
    Last, F.<nbsp>M.

    """
    return join [
        name_part(tie=True) [person.prelast()],
        name_part [person.last()],
        name_part(before=', ') [person.lineage()],
        name_part(before=', ') [person.first(abbr) + person.middle(abbr)],
    ]
{'fraction_non_alphanumeric': 0.14947742062709524, 'fraction_numerical': 0.00946558864129363, 'mean_word_length': 3.8582375478927204, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6235366', 'n_tokens_mistral': 1687, 'n_tokens_neox': 1617, 'n_words': 483}