1
0
mirror of https://github.com/lise-henry/crowbook synced 2024-09-28 02:59:45 +02:00

Fix french cleaner bug when string ends with nb space

This commit is contained in:
Elisabeth Henry 2016-05-07 14:10:15 +02:00
parent 4eb80359e9
commit 2b37374a8f
2 changed files with 15 additions and 6 deletions

View File

@ -8,7 +8,9 @@ unreleased
typography reasons it's better to use different non breaking
spaces according to context, this option was not really useful
anymore.
* Rendering:
* Bugfixes:
* Fixed a bug in `French` cleaner when a string to clean ended by a
non-breaking space (space was doubled with a breaking one).
* LaTeX/PDF:
* "Autocleaning" is now also activated (for french at least) for
LaTeX rendering, since it doesn't correctly insert non-breaking

View File

@ -79,7 +79,7 @@ impl Cleaner for French {
let nb_char_narrow = if latex {
'~'
} else {
'\u{2009}' // narrow non breaking space
'\u{202F}' // narrow non breaking space
};
let nb_char_em = if latex {
'~'
@ -96,7 +96,7 @@ impl Cleaner for French {
{
let mut chars = s.chars();
if let Some(mut current) = chars.next() {
while let Some(next) = chars.next() {
while let Some(next) = chars.next() {
if is_whitespace(current) {
match next {
// handle narrow nb space before char
@ -110,19 +110,26 @@ impl Cleaner for French {
// handle nb space after char
'—' => {
if is_whitespace(next) {
new_s.push(nb_char_em);
if let Some(next) = chars.next() {
new_s.push(nb_char_em);
current = next;
continue;
} else {
current = nb_char_em;
break;
}
}
},
'«' => {
if is_whitespace(next) {
new_s.push(' ');
if let Some(next) = chars.next() {
new_s.push(nb_char);
current = next;
continue;
} else {
current = nb_char;
break;
}
}
@ -135,7 +142,7 @@ impl Cleaner for French {
new_s.push(current);
}
}
*s = new_s
}
}