All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.undercouch.citeproc.helper.FrenchPunctuationSpacing Maven / Gradle / Ivy

package de.undercouch.citeproc.helper;

import java.util.regex.Pattern;

/**
 * 

Applies rules of French punctuation spacing.

*

See the following links for reference:

* *

Note: We are following the rules described in the second link above. * The sources collected are more convincing than the implementation in * citeproc-js.

* @author Michel Kraemer */ public class FrenchPunctuationSpacing { // narrow non-breaking spaces before and after guillemets private static final Pattern SPACE_AFTER_LEFT_GUILLEMET = Pattern.compile("([«|‹])\\h*(?=\\H)"); private static final Pattern SPACE_BEFORE_RIGHT_GUILLEMET = Pattern.compile("(?<=\\H)\\h*([»|›])"); // equal-width spaces around colon private static final Pattern SPACES_AROUND_COLON = Pattern.compile("(?<=\\H)\\h*(:[\\s\u00a0])(?=\\H)"); // narrow non-breaking space before ';', '?', and '!' private static final Pattern SPACE_BEFORE_PUNCTUATION = Pattern.compile("(?<=[^\\h;?!])\\h*([;?!])"); /** * Apply rules of French punctuation spacing * @param str the input string * @return the processed string */ public static String apply(String str) { str = SPACE_AFTER_LEFT_GUILLEMET.matcher(str).replaceAll("$1\u202F"); str = SPACE_BEFORE_RIGHT_GUILLEMET.matcher(str).replaceAll("\u202F$1"); str = SPACES_AROUND_COLON.matcher(str).replaceAll("\u00a0$1"); str = SPACE_BEFORE_PUNCTUATION.matcher(str).replaceAll("\u202F$1"); return str; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy