yusuke/twitter4j — pull request #57 by sigpwned (2012-07-11 05:36:00+00:00)
Title: Patch for bug TFJ-671

This is intended to be a patch for Jira issue TFJ-671.

Essentially, the patch defines a new class HTMLEntityString which handles HTML entity un/escaping and knows not only about the eventual un/escaped string, but also about the individual entities that were escaped and where they occurred in the original input. (This code is based heavily off of the original HTMLEntity class.) Using the HTMLEntityString object, the various Twitter Entity classes can then rewrite their start/end indexes to be accurate against their corresponding newly-unescaped tweet text. HTMLEntityString is careful to approach the problem such that minimum extra memory and time is used in performing the un/escaping while still retaining enough state to allow these index rewrites to happen in a clear, easy-to-use fashion.

The original HTMLEntity class is left in place with no changes to its call-level interface, but is now implemented in terms of HTMLEntityString.

The patch also includes a couple of tests (that the code passes!) in StatusMethodsTest to demonstrate that it works, and testing that lives on.

Also -- I want to mention how much I appreciate Twitter4j! It's a pleasure to code with, and it makes life *so* much simpler. Thanks for putting it together! I'd be thrilled to contribute back in any way that I can, however small. If you don't like this patch -- if you think it's overkill, or it's unclear, whatever -- let me know, and I'd be happy to take another whack at it. I think it's important to get this bug fixed -- I'm currently hitting it on a project! -- but I certainly don't want to make more work for you and the Twitter4j team, and I'm happy to help however I can.