Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.blvckbytes.vocabsucker;
- import java.util.Arrays;
- import java.util.List;
- public class LetterConverter {
- /**
- * Tries to parse a letter from the href attribute out of a
- * use tag representing a letter in the SVG page
- * @param href Href attribute's value of use tag
- */
- public static String tryParse( String href ) {
- // Invalid href provided
- if( href == null )
- return "?";
- // Resource ranges
- String alphabet = "abcdefghijklmnopqrstuvwxyz";
- String numbers = "0123456789";
- String mutations = "ß??ÄÖÜä??öü";
- String symbols = "(),-./";
- List< String > gluedLetters = Arrays.asList( "fi", "ff", "fl", "ffi" );
- try {
- // The #T1_1 charset is the only one needed for vocabulary
- if( !href.startsWith( "#T1_1_" ) )
- return "?";
- // Cut out the charset index and parse it
- int index = Integer.parseInt( href.substring( 6 ) );
- // Numbers
- if( index <= 22 && index >= 13 ) {
- index -= 13;
- return numbers.substring( index, index + 1 );
- }
- // Lowercase letters
- if( index <= 82 && index >= 56 ) {
- index -= 56;
- return alphabet.substring( index, index + 1 );
- }
- // Uppercase letters
- if( index <= 51 && index >= 27 ) {
- // They just skipped Y in uppercase alphabet...
- alphabet = alphabet.substring( 0, alphabet.length() - 2 ) + "Z";
- index -= 27;
- return alphabet.substring( index, index + 1 ).toUpperCase();
- }
- // Mutations
- if( index >= 88 && index <= 88 + mutations.length() ) {
- index -= 88;
- return mutations.substring( index, index + 1 );
- }
- // Symbols
- if( index >= 7 && index <= 7 + symbols.length() ) {
- index -= 7;
- return symbols.substring( index, index + 1 );
- }
- // Glued letters
- if( index >= 100 && index <= 100 + gluedLetters.size() ) {
- index -= 100;
- return gluedLetters.get( index );
- }
- // Opening square bracket
- if( index == 52 )
- return "[";
- // Closing square bracket
- if( index == 53 )
- return "]";
- // Single quote
- if( index == 6 )
- return "'";
- // Nothing matched
- return "?";
- } catch ( Exception e ) {
- // Error occoured while parsing
- return "?";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement