Class SmartQuotes


  • public class SmartQuotes
    extends java.lang.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 Summary

      Constructors 
      Constructor Description
      SmartQuotes()
      Creates the smart-quotes parser
      SmartQuotes​(java.lang.String leftSingleQuote, java.lang.String rightSingleQuote, java.lang.String leftDoubleQuote, java.lang.String rightDoubleQuote, java.lang.String apostrophe, java.lang.String prime, java.lang.String doublePrime, java.lang.String triplePrime, java.util.Locale locale)
      Creates the smart-quotes parser with custom symbols
      SmartQuotes​(java.lang.String leftSingleQuote, java.lang.String rightSingleQuote, java.lang.String leftDoubleQuote, java.lang.String rightDoubleQuote, java.util.Locale locale)
      Creates the smart-quotes parser with custom symbols
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String apply​(java.lang.String str)
      Replace straight quotation marks and apostrophes in the given string by their typographically correct counterparts.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SmartQuotes

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

        public SmartQuotes​(java.lang.String leftSingleQuote,
                           java.lang.String rightSingleQuote,
                           java.lang.String leftDoubleQuote,
                           java.lang.String rightDoubleQuote,
                           java.util.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​(java.lang.String leftSingleQuote,
                           java.lang.String rightSingleQuote,
                           java.lang.String leftDoubleQuote,
                           java.lang.String rightDoubleQuote,
                           java.lang.String apostrophe,
                           java.lang.String prime,
                           java.lang.String doublePrime,
                           java.lang.String triplePrime,
                           java.util.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 java.lang.String apply​(java.lang.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