Class SmartQuotes


  • public class SmartQuotes
    extends Object

    Replaces straight quotation marks and apostrophes by their typographically correct counterparts.

    The code is based on smartquotes.js (https://smartquotes.js.org/) written by Kelly Martin released under the MIT license. It has been translated to Java and extended to support multiple languages.

    Author:
    Michel Kraemer
    • Constructor Detail

      • SmartQuotes

        public SmartQuotes()
        Creates the smart-quotes parser
      • SmartQuotes

        public SmartQuotes​(String leftSingleQuote,
                           String rightSingleQuote,
                           String leftDoubleQuote,
                           String rightDoubleQuote,
                           Locale locale)
        Creates the smart-quotes parser with custom symbols
        Parameters:
        leftSingleQuote - custom left single quotation mark
        rightSingleQuote - custom right singe quotation mark
        leftDoubleQuote - custom left double quotation mark
        rightDoubleQuote - custom right double quotation mark
        locale - a locale object used to apply special rules and corner cases
      • SmartQuotes

        public SmartQuotes​(String leftSingleQuote,
                           String rightSingleQuote,
                           String leftDoubleQuote,
                           String rightDoubleQuote,
                           String apostrophe,
                           String prime,
                           String doublePrime,
                           String triplePrime,
                           Locale locale)
        Creates the smart-quotes parser with custom symbols
        Parameters:
        leftSingleQuote - custom left single quotation mark
        rightSingleQuote - custom right singe quotation mark
        leftDoubleQuote - custom left double quotation mark
        rightDoubleQuote - custom right double quotation mark
        apostrophe - custom apostrophe
        prime - custom prime
        doublePrime - custom double prime
        triplePrime - custom triple prime
        locale - a locale object used to apply special rules and corner cases
    • Method Detail

      • apply

        public String apply​(String str)
        Replace straight quotation marks and apostrophes in the given string by their typographically correct counterparts.
        Parameters:
        str - the input string
        Returns:
        the processed string