Browse Source

Pre-treatment for escaped space in author names

pull/166/head
Oliverpool 9 years ago
parent
commit
a8ef3d96ac
  1. 8
      patacrep/authors.py
  2. 2
      test/test_authors.py

8
patacrep/authors.py

@ -39,14 +39,15 @@ def compile_authwords(authwords):
def split_author_names(string):
r"""Split author between first and last name.
The last space separates first and last name. LaTeX commands are ignored.
The last space separates first and last name.
LaTeX commands are ignored, escaped spaces are converted to ~.
>>> split_author_names("Edgar Allan Poe")
('Poe', 'Edgar Allan')
>>> split_author_names("Edgar Allan \emph {Poe}")
('{Poe}', 'Edgar Allan \\emph')
>>> split_author_names(r"The Rolling\ Stones")
('Stones', 'The Rolling\\')
('Rolling~Stones', 'The')
>>> split_author_names("The {Rolling Stones}")
('Stones}', 'The {Rolling')
>>> split_author_names("The Rolling Stones")
@ -54,7 +55,8 @@ def split_author_names(string):
>>> split_author_names(" John Doe ")
('Doe', 'John')
"""
chunks = string.strip().split(" ")
chunks = string.strip().replace("\\ ", "~")
chunks = chunks.split(" ")
return (chunks[-1].strip(), " ".join(chunks[:-1]).strip())

2
test/test_authors.py

@ -17,7 +17,7 @@ SPLIT_AUTHORS_DATA = [
("The mamas and the papas", ("mamas and the papas", "The")), # Unbreakable spaces
(r"\LaTeX command", ("command", r"\LaTeX")), # LaTeX commands are ignored
(r"\emph{Some braces}", ("braces}", r"\emph{Some")), # LaTeX commands are ignored
(r"The Rolling\ Stones", ("Stones", 'The Rolling\\')), # LaTeX commands are ignored
(r"The Rolling\ Stones", ("Rolling~Stones", 'The')), # LaTeX commands are ignored
]
PROCESS_AUTHORS_DATA = [

Loading…
Cancel
Save