Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 706F8200B94 for ; Sun, 2 Oct 2016 09:29:27 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 64CD6160AD8; Sun, 2 Oct 2016 07:29:27 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A29B8160AC7 for ; Sun, 2 Oct 2016 09:29:26 +0200 (CEST) Received: (qmail 21690 invoked by uid 500); 2 Oct 2016 07:29:21 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 21679 invoked by uid 99); 2 Oct 2016 07:29:20 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 02 Oct 2016 07:29:20 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id A7FF02C2A5F for ; Sun, 2 Oct 2016 07:29:20 +0000 (UTC) Date: Sun, 2 Oct 2016 07:29:20 +0000 (UTC) From: "Bruno P. Kinoshita (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Resolved] (TEXT-19) Add alphabet converter MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Sun, 02 Oct 2016 07:29:27 -0000 [ https://issues.apache.org/jira/browse/TEXT-19?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Bruno P. Kinoshita resolved TEXT-19. ------------------------------------ Resolution: Fixed Pull request #5 to apache/commons-text merged after discussion/review. Thanks to Eyal Allweil. > Add alphabet converter > ---------------------- > > Key: TEXT-19 > URL: https://issues.apache.org/jira/browse/TEXT-19 > Project: Commons Text > Issue Type: New Feature > Reporter: Eyal Allweil > Assignee: Bruno P. Kinoshita > Fix For: 1.0 > > > (as described in [the mailing list|http://mail-archives.apache.org/mod_mbox/commons-dev/201609.mbox/%3c289983494.3057706.1472720010277@mail.yahoo.com%3e]) > 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: > {code} > Set originals; // a, b, c, d > Set encoding; // 0, 1, d > Set 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 > {code} > Of course, x.equals(ac.decode(ac.encode(x))) 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: > {code} > AlphabetConverter ac; > ac.equals(AlphabetConverter.createConverterFromMap(ac.getOriginalToEncoded())); // always should be true > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)