Better trimming of 'short' inline story content.

This commit is contained in:
dosiecki 2014-03-24 02:52:53 -07:00
parent 89a53e4c1d
commit 719d237070

View file

@ -23,9 +23,8 @@ public class StoryTypeAdapter implements JsonDeserializer<Story> {
private Gson gson; private Gson gson;
// the HTML parser puts placeholders for images and other content when parsing to text, but we // any characters we don't want in the short description, such as newlines or placeholders
// want to remove them. private final static Pattern ShortContentExcludes = Pattern.compile("[\\uFFFC\\u000A\\u000B\\u000C\\u000D]");
private final static Pattern HtmlPlaceholders = Pattern.compile("\\uFFFC");
public StoryTypeAdapter() { public StoryTypeAdapter() {
this.gson = new GsonBuilder() this.gson = new GsonBuilder()
@ -48,8 +47,8 @@ public class StoryTypeAdapter implements JsonDeserializer<Story> {
int length = 200; int length = 200;
if (parsed.length() < 200) { length = parsed.length(); } if (parsed.length() < 200) { length = parsed.length(); }
story.shortContent = parsed.subSequence(0, length).toString(); story.shortContent = parsed.subSequence(0, length).toString();
Matcher m = HtmlPlaceholders.matcher(story.shortContent); Matcher m = ShortContentExcludes .matcher(story.shortContent);
story.shortContent = m.replaceAll(""); story.shortContent = m.replaceAll(" ").trim();
} }
return story; return story;