| 13 | 13 | * No conversion is performed. |
| 14 | 14 | */ |
| 15 | CONVERT_REGULAR( "'", "regular" ), |
|
| 15 | CONVERT_REGULAR( "", "regular" ), |
|
| 16 | 16 | /** |
| 17 | 17 | * Apostrophes become MODIFIER LETTER APOSTROPHE ({@code ʼ}). |
| 200 | 200 | */ |
| 201 | 201 | public String toString( final Apostrophe apostrophe ) { |
| 202 | final var glyph = mLexeme.getType().glyph(); |
|
| 203 | 202 | final var tokenType = getType(); |
| 203 | final var glyph = mLexeme.getType().glyph(); |
|
| 204 | final var straight = tokenType.isStraight(); |
|
| 204 | 205 | |
| 205 | 206 | // Retrieves the base glyph, unless curling was requested. When curling |
| 206 | 207 | // apostrophes, this will determine the user-selected type of apostrophe |
| 207 | 208 | // entity to use. |
| 208 | return apostrophe == CONVERT_REGULAR |
|
| 209 | return straight |
|
| 210 | ? CHARS.get( tokenType ) |
|
| 211 | : apostrophe == CONVERT_REGULAR |
|
| 209 | 212 | ? CHARS.getOrDefault( tokenType, glyph.text() ) |
| 210 | 213 | : I18N_ENTITIES.getOrDefault( glyph, convert( tokenType, apostrophe ) ); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | /** |
|
| 36 | * Answers whether the quotation mark must be rendered straight. |
|
| 37 | * |
|
| 38 | * @return {@code true} means the quotation mark was escaped. |
|
| 39 | */ |
|
| 40 | public boolean isStraight() { |
|
| 41 | return this == QUOTE_STRAIGHT_SINGLE || this == QUOTE_STRAIGHT_DOUBLE; |
|
| 42 | } |
|
| 43 | ||
| 35 | 44 | @Override |
| 36 | 45 | public String toString() { |
| 47 | 47 | input, |
| 48 | 48 | CONTRACTIONS, |
| 49 | replace( output, offset, CONVERT_APOS_ENTITY ), |
|
| 49 | replace( output, offset, CONVERT_APOS ), |
|
| 50 | 50 | _ -> false |
| 51 | 51 | ); |
| 34 | 34 | public void test_Parse_UncurledQuotes1_CurlyQuotes() throws IOException { |
| 35 | 35 | testCurler( |
| 36 | createCurler( FILTER_PLAIN, CONVERT_APOS_ENTITY ), |
|
| 36 | createCurler( FILTER_PLAIN, CONVERT_APOS ), |
|
| 37 | 37 | "unambiguous-1-pass.txt" |
| 38 | 38 | ); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | @Test |
| 42 | 42 | public void test_Parse_UncurledQuotes2_CurlyQuotes() throws IOException { |
| 43 | 43 | testCurler( |
| 44 | createCurler( FILTER_PLAIN, CONVERT_APOS_ENTITY ), |
|
| 44 | createCurler( FILTER_PLAIN, CONVERT_APOS ), |
|
| 45 | 45 | "unambiguous-2-pass.txt" |
| 46 | 46 | ); |
| ... | ||
| 58 | 58 | public void test_Parse_UncurledQuotesXml_CurlyQuotes() throws IOException { |
| 59 | 59 | testCurler( |
| 60 | createCurler( FILTER_XML, CONVERT_APOS_ENTITY ), "xml.txt" |
|
| 60 | createCurler( FILTER_XML, CONVERT_APOS ), "xml.txt" |
|
| 61 | 61 | ); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | @Test |
| 65 | 65 | public void test_Parse_UncurledQuotesI11l_CurlyQuotes() throws IOException { |
| 66 | 66 | testCurler( |
| 67 | createCurler( FILTER_PLAIN, CONVERT_APOS_ENTITY ), "i18n.txt" |
|
| 67 | createCurler( FILTER_PLAIN, CONVERT_APOS ), "i18n.txt" |
|
| 68 | 68 | ); |
| 69 | 69 | } |
| ... | ||
| 91 | 91 | } |
| 92 | 92 | |
| 93 | final var curler = createCurler( FILTER_XML, CONVERT_APOS_ENTITY ); |
|
| 93 | final var curler = createCurler( FILTER_XML, CONVERT_APOS ); |
|
| 94 | 94 | System.out.println( curler.apply( sb.toString() ) ); |
| 95 | 95 | } |
| 10 | 10 | import java.util.concurrent.atomic.AtomicInteger; |
| 11 | 11 | |
| 12 | import static com.whitemagicsoftware.keenquotes.parser.Apostrophe.CONVERT_APOS_ENTITY; |
|
| 12 | import static com.whitemagicsoftware.keenquotes.parser.Apostrophe.CONVERT_APOS; |
|
| 13 | 13 | import static com.whitemagicsoftware.keenquotes.parser.Curler.replace; |
| 14 | 14 | import static com.whitemagicsoftware.keenquotes.texts.TestResource.readPairs; |
| ... | ||
| 31 | 31 | input, |
| 32 | 32 | CONTRACTIONS, |
| 33 | replace( output, offset, CONVERT_APOS_ENTITY ), |
|
| 33 | replace( output, offset, CONVERT_APOS ), |
|
| 34 | 34 | _ -> false |
| 35 | 35 | ); |