Commit e7fe72da authored by User expired's avatar User expired
Browse files

Fix quote to bracket replacement in multi line records

parent 07300b5e
Pipeline #40149 failed with stage
in 1 minute and 46 seconds
......@@ -34,6 +34,19 @@ for arg; do
done
# Function to replace double quotes by curly brackets.
function replace_quotes() { # replace_quotes bibfile
sed -i -r '
s/^ ([A-Za-z][A-Za-z_-]*) = "/ \1 = {/ # Replace opening quote by {.
T # End here if there was no replacement.
:a # Label with name a.
s/" *(,?)$/}\1/ # Replace closing quote by }.
t # End here if replacement was successful.
N # Append next line to search closing quote.
ba # Go to label a to repeat search.
' "$1"
}
# Function to merge lines.
function merge_lines() { # merge_lines bibfilename
sed -i ':a # Label with name a.
......@@ -43,7 +56,7 @@ s/{[\n \t]*/{/ # At left curly bracket remove newline and whitespace.
s/[ \t]*\n[ \t]*}/}/ # At right curly bracket remove whitespace and newline.
s/[ \t]*\n[ \t]*/ /g # At other places replace space+newline by single space.
/[^},]$/N # If bib field is still incomplete, append next line.
//ba # Go to label to repeat this for multiple-line fields.
//ba # Go to label a to repeat this for multiple-line fields.
/ *\(},*\)$/s//\1/ # Remove whitespace before trailing curly bracket.
/}$/{N;s/\n *,/,/} # Remove newline between trailing curly bracket and comma.
' "$1"
......@@ -104,10 +117,7 @@ do
sed -i -r 's/^ ([A-Za-z][A-Za-z_-]*) = / \L\u\1 = /' "$tmpfile"
# Use curly brackets {} instead of double quotes "" or no quotes.
# FIXME: Multi line entries with double quotes are not treated correctly.
sed -i -r 's/^ ([A-Za-z][A-Za-z_-]*) = "/ \1 = {/;s/" *,$/},/;T;s/"$/}/' "$tmpfile"
sed -i '$s/"}$/}\n}/' "$tmpfile"
sed -i -r 's/^ ([A-Za-z][A-Za-z_-]*) = ([^{].*[^},])(,*)$/ \1 = {\2}\3/' "$tmpfile"
replace_quotes "$tmpfile"
# Remove preceding and trailing whitespace in field contents.
sed -i 's/ *\(},\?\)$/\1/' "$tmpfile"
......
......@@ -194,9 +194,18 @@ testQuotesToCurlyBrackets() {
echo ' Field = "some text"' > $fileOne
bib-format $fileOne
assertEquals ' Field = {some text}' "$(cat $fileOne)"
echo ' Field = "some "more" text"' > $fileOne
echo ' Field = "some "more" text",' > $fileOne
bib-format $fileOne
assertEquals ' Field = {some "more" text}' "$(cat $fileOne)"
assertEquals ' Field = {some "more" text},' "$(cat $fileOne)"
echo ' Field = "some multi
line text
row 3",' > $fileOne
bib-format $fileOne
assertEquals ' Field = {some multi line text row 3},' "$(cat $fileOne)"
echo ' Field = "Two lines
and no comma",' > $fileOne
bib-format $fileOne
assertEquals ' Field = {Two lines and no comma},' "$(cat $fileOne)"
}
testCurlyBracketsInField() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment