SHARE
TWEET

Untitled

a guest Mar 26th, 2020 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.blvckbytes.vocabsucker;
  2.  
  3. import java.util.Arrays;
  4. import java.util.List;
  5.  
  6. public class LetterConverter {
  7.  
  8.   /**
  9.    * Tries to parse a letter from the href attribute out of a
  10.    * use tag representing a letter in the SVG page
  11.    * @param href Href attribute's value of use tag
  12.    */
  13.   public static String tryParse( String href ) {
  14.  
  15.     // Invalid href provided
  16.     if( href == null )
  17.       return "?";
  18.  
  19.     // Resource ranges
  20.     String alphabet = "abcdefghijklmnopqrstuvwxyz";
  21.     String numbers = "0123456789";
  22.     String mutations = "ß??ÄÖÜä??öü";
  23.     String symbols = "(),-./";
  24.     List< String > gluedLetters = Arrays.asList( "fi", "ff", "fl", "ffi" );
  25.  
  26.     try {
  27.  
  28.       // The #T1_1 charset is the only one needed for vocabulary
  29.       if( !href.startsWith( "#T1_1_" ) )
  30.         return "?";
  31.  
  32.       // Cut out the charset index and parse it
  33.       int index = Integer.parseInt( href.substring( 6 ) );
  34.  
  35.       // Numbers
  36.       if( index <= 22 && index >= 13 ) {
  37.         index -= 13;
  38.         return numbers.substring( index, index + 1 );
  39.       }
  40.  
  41.       // Lowercase letters
  42.       if( index <= 82 && index >= 56 ) {
  43.         index -= 56;
  44.         return alphabet.substring( index, index + 1 );
  45.       }
  46.  
  47.       // Uppercase letters
  48.       if( index <= 51 && index >= 27 ) {
  49.         // They just skipped Y in uppercase alphabet...
  50.         alphabet = alphabet.substring( 0, alphabet.length() - 2 ) + "Z";
  51.  
  52.         index -= 27;
  53.         return alphabet.substring( index, index + 1 ).toUpperCase();
  54.       }
  55.  
  56.       // Mutations
  57.       if( index >= 88 && index <= 88 + mutations.length() ) {
  58.         index -= 88;
  59.         return mutations.substring( index, index + 1 );
  60.       }
  61.  
  62.       // Symbols
  63.       if( index >= 7 && index <= 7 + symbols.length() ) {
  64.         index -= 7;
  65.         return symbols.substring( index, index + 1 );
  66.       }
  67.  
  68.       // Glued letters
  69.       if( index >= 100 && index <= 100 + gluedLetters.size() ) {
  70.         index -= 100;
  71.         return gluedLetters.get( index );
  72.       }
  73.  
  74.       // Opening square bracket
  75.       if( index == 52 )
  76.         return "[";
  77.  
  78.       // Closing square bracket
  79.       if( index == 53 )
  80.         return "]";
  81.  
  82.       // Single quote
  83.       if( index == 6 )
  84.         return "'";
  85.  
  86.       // Nothing matched
  87.       return "?";
  88.  
  89.     } catch ( Exception e ) {
  90.       // Error occoured while parsing
  91.       return "?";
  92.     }
  93.  
  94.   }
  95.  
  96. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top