Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 356979 - TextUtils.shortenText() throws PatternSyntaxException
Summary: TextUtils.shortenText() throws PatternSyntaxException
Status: RESOLVED FIXED
Alias: None
Product: JSDT
Classification: WebTools
Component: Debug (show other bugs)
Version: 3.4   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.4 M2   Edit
Assignee: Grant Gayed CLA
QA Contact: Michael Rennie CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 357399
  Show dependency tree
 
Reported: 2011-09-07 13:36 EDT by Grant Gayed CLA
Modified: 2011-09-12 12:19 EDT (History)
1 user (show)

See Also:


Attachments
patch (936 bytes, patch)
2011-09-07 13:36 EDT, Grant Gayed CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Grant Gayed CLA 2011-09-07 13:36:23 EDT
Created attachment 202920 [details]
patch

This method is using String.replaceAll() instead of String.replace(), and as a result is failing because replaceAll() expects its argument to be a regex.

Fix is committed to HEAD.  Creating this report as a reminder to make this change in the 3_2_ and 3_3_maintenance streams once the initial backport of crossfire to these streams is done.
Comment 2 Grant Gayed CLA 2011-09-08 10:30:25 EDT
Comment on attachment 202920 [details]
patch

This patch uses String API that's too new.  Here's a better implementation of the method:

	public static String shortenText(String string, int threshold) {
		int length = string.length(); 
		if (length > threshold) {
			int chomp = length - threshold + 3;
			int begin = Math.round(threshold/2)-1;
			StringBuffer buff = new StringBuffer();
			buff.append(string.substring(0, begin)).append("...").append(string.substring(begin+chomp)); //$NON-NLS-1$
			return buff.toString();
		}
		return string;
	}
Comment 3 Grant Gayed CLA 2011-09-08 10:50:45 EDT
Comment 2 implementation is tested and committed to the HEAD and R3_2_maintenance streams > 20110908.  R3_3_maintenance stream is still TODO, once the rest of the Crossfire stuff has arrived there.
Comment 4 Michael Rennie CLA 2011-09-12 12:19:13 EDT
(In reply to comment #3)
> Comment 2 implementation is tested and committed to the HEAD and
> R3_2_maintenance streams > 20110908.  R3_3_maintenance stream is still TODO,
> once the rest of the Crossfire stuff has arrived there.

I am going to mark this as fixed, R3_3_maintenance will just get all of the fixes from HEAD when the back-port is done - so we don't need to keep this bug open for that.

I will clone this bug and target it for 3.3.2+
Comment 5 Michael Rennie CLA 2011-09-12 12:19:26 EDT
fixed.