Uploaded image for project: 'Commons Text'
  1. Commons Text
  2. TEXT-19

Add alphabet converter

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.0
    • None

    Description

      (as described in the mailing list)

      This is a utility class I wrote for converting from one alphabet to another - for example, from unicode to latin, without using some of the chars in latin. The usage looks like this:

      Set<Character> originals; // a, b, c, d
      Set<Character> encoding; // 0, 1, d
      Set<Character> doNotEncode; // d
      
      AlphabetConverter ac = AlphabetConverter.createConverter(originals, encoding, doNotEncode);
      
      ac.encode("a"); // 00
      ac.encode("b"); // 01
      ac.encode("c"); // 0d
      ac.encode("d"); // d
      ac.encode("abcd"); // 00010dd
      
      

      Of course, x.equals(ac.decode(ac.encode)) should always be true.

      The implementation provided makes the encodings of fixed length, other than the "do not encode" chars, which remain as they are (length one).

      In addition, in order to make it easier to preserve the encoding scheme, I've added a human-readable toString implementation, and a constructor that can recreate an AlphabetConverter from the encoding map, such that:

      AlphabetConverter ac;
      
      ac.equals(AlphabetConverter.createConverterFromMap(ac.getOriginalToEncoded())); // always should be true
      

      Attachments

        Activity

          People

            kinow Bruno P. Kinoshita
            eyal Eyal Allweil
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: