You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gregor B. Rosenauer (JIRA)" <ji...@apache.org> on 2008/02/01 17:05:08 UTC
[jira] Created: (LANG-405) StringUtils.truncate() to cut out middle
part of a String
StringUtils.truncate() to cut out middle part of a String
---------------------------------------------------------
Key: LANG-405
URL: https://issues.apache.org/jira/browse/LANG-405
Project: Commons Lang
Issue Type: New Feature
Affects Versions: 2.2
Reporter: Gregor B. Rosenauer
Priority: Minor
It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
BeOS had a function like this, but it's poorly documented, missing examples:
http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
e.g.:
A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
becomes:
A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (LANG-405) StringUtils.truncate() to cut out middle
part of a String
Posted by "Srihari Reddy (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Srihari Reddy updated LANG-405:
-------------------------------
Comment: was deleted
(was: Thanks Henri. i added the new test case to the junit test case assertEquals("ab.ef", StringUtils.truncateMiddle("abcdef", ".", 5));
The result of StringUtils.truncateMiddle("abcdef", ".", 5) is ab.ef.
i am attaching the updated patch.)
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Components: lang.*
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 3.0
>
> Attachments: LANG-405.diff, LANG-405.diff, LANG-405.diff
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Issue Comment Edited: (LANG-405) StringUtils.truncate() to
cut out middle part of a String
Posted by "Gregor B. Rosenauer (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12565218#action_12565218 ]
grexe edited comment on LANG-405 at 2/3/08 1:00 PM:
------------------------------------------------------------------
Henry, I understood your original comment and you are right that the documentation does not explicitly mention this. However I remember this String function was indeed supported, and in any way the reference was only ment to illustrate the feature I am suggesting here...,-)
FWIW, here is a screenshot to an example (it seems to just cut out the part exceeding the total length from the middle), 3rd screenshot that shows the mail messages:
[http://www.beatjapan.org/mirror/www.be.com/documentation/user_docs/04_internet_use.html#Using Internet Mail Services]
(Aah, BeOS is still good for some inspiration:)
was (Author: grexe):
Henry, I understood your original comment and you are right that the documentation does not explicitly mention this. However I remember this String function was indeed supported, and in any way the reference was only ment to illustrate the feature I am suggesting here...,-)
FWIW, here is a screenshot to an example (it seems to just cut out the part exceeding the total length from the middle), 3rd screenshot that shows the mail messages:
http://www.beatjapan.org/mirror/www.be.com/documentation/user_docs/04_internet_use.html#Using Internet Mail Services
(Aah, BeOS is still good for some inspiration:)
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-405) StringUtils.truncate() to cut out
middle part of a String
Posted by "Sebb (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12564819#action_12564819 ]
Sebb commented on LANG-405:
---------------------------
What rules should be used to decide where to put the ellipsis?
Should it try to leave:
Equal numbers of characters each side?
Equal numbers of words each side?
or
A sentence that still makes some sense? ;-)
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-405) StringUtils.truncate() to cut out
middle part of a String
Posted by "Srihari Reddy (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12802832#action_12802832 ]
Srihari Reddy commented on LANG-405:
------------------------------------
Modified Henri's patch.changed the way the result sting is computed and built. also added the test cases for it.
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Components: lang.*
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 3.0
>
> Attachments: LANG-405.diff, LANG-405.diff, LANG-405.diff
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-405) StringUtils.truncate() to cut out
middle part of a String
Posted by "Paul Benedict (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12803285#action_12803285 ]
Paul Benedict commented on LANG-405:
------------------------------------
This method does not fit the definition of truncate (http://www.google.com/search?q=define%3Atruncate); truncation always deal with the trunks/edges/ends.
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Components: lang.*
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 3.0
>
> Attachments: LANG-405.diff, LANG-405.diff, LANG-405.diff
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (LANG-405) Cut out middle part of a String
Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Niall Pemberton updated LANG-405:
---------------------------------
Fix Version/s: (was: 3.0)
2.5
> Cut out middle part of a String
> -------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Components: lang.*
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 2.5
>
> Attachments: LANG-405.diff, LANG-405.diff, LANG-405.diff
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-405) StringUtils.truncate() to cut out
middle part of a String
Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12803229#action_12803229 ]
Henri Yandell commented on LANG-405:
------------------------------------
Thanks Srihari. Patch tried but your new failing test of "ab.ef" fails.
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Components: lang.*
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 3.0
>
> Attachments: LANG-405.diff, LANG-405.diff, LANG-405.diff
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (LANG-405) StringUtils.truncate() to cut out middle
part of a String
Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Henri Yandell updated LANG-405:
-------------------------------
Attachment: LANG-405.diff
Updating patch with unit tests and minor tweaks (documentation) to Dave's patch.
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 3.0
>
> Attachments: LANG-405.diff, LANG-405.diff
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-405) StringUtils.truncate() to cut out
middle part of a String
Posted by "Sebb (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12803305#action_12803305 ]
Sebb commented on LANG-405:
---------------------------
Agreed, that's better.
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Components: lang.*
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 3.0
>
> Attachments: LANG-405.diff, LANG-405.diff, LANG-405.diff
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (LANG-405) StringUtils.truncate() to cut out middle
part of a String
Posted by "Srihari Reddy (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Srihari Reddy updated LANG-405:
-------------------------------
Attachment: LANG-405.diff
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Components: lang.*
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 3.0
>
> Attachments: LANG-405.diff, LANG-405.diff, LANG-405.diff
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-405) StringUtils.truncate() to cut out
middle part of a String
Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12803301#action_12803301 ]
Niall Pemberton commented on LANG-405:
--------------------------------------
We already have an abbreviate() method that does a similar thing and I agree with Paul - truncate could be misleading. So how about abbreviateMiddle() ?
http://commons.apache.org/lang/api-release/org/apache/commons/lang/StringUtils.html#abbreviate%28java.lang.String,%20int%29
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Components: lang.*
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 3.0
>
> Attachments: LANG-405.diff, LANG-405.diff, LANG-405.diff
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (LANG-405) Cut out middle part of a String
Posted by "Paul Benedict (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul Benedict updated LANG-405:
-------------------------------
Summary: Cut out middle part of a String (was: StringUtils.truncate() to cut out middle part of a String)
To remove any confusion when reading site reports, removing "truncate" from this ticket summary.
> Cut out middle part of a String
> -------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Components: lang.*
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 3.0
>
> Attachments: LANG-405.diff, LANG-405.diff, LANG-405.diff
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (LANG-405) StringUtils.truncate() to cut out middle
part of a String
Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Henri Yandell updated LANG-405:
-------------------------------
Fix Version/s: 3.0
So....
public String truncateMiddle(String str, String middle, int length);
I think it would be worth looking at further - so patches welcome :) Putting in 3.0 until someone codes something.
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 3.0
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-405) StringUtils.truncate() to cut out
middle part of a String
Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12565032#action_12565032 ]
Henri Yandell commented on LANG-405:
------------------------------------
Are you sure that's what the BeOS function did? Reading the docs, Truncate(n) looks like java.lang.String.substring(0,n).
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-405) StringUtils.truncate() to cut out
middle part of a String
Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12789710#action_12789710 ]
Henri Yandell commented on LANG-405:
------------------------------------
Started writing tests. The following fails:
assertEquals("a.d", StringUtils.truncateMiddle("abcd", ".", 3));
It gets a result of "ab."
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 3.0
>
> Attachments: LANG-405.diff
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-405) StringUtils.truncate() to cut out
middle part of a String
Posted by "Srihari Reddy (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12802790#action_12802790 ]
Srihari Reddy commented on LANG-405:
------------------------------------
started to write more tests. the following test too fails
assertEquals("ab.ef", StringUtils.truncateMiddle("abcdef", ".", 5));
shouldn't the result be ab.ef but the result is abc.f
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Components: lang.*
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 3.0
>
> Attachments: LANG-405.diff, LANG-405.diff
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Closed: (LANG-405) StringUtils.truncate() to cut out middle
part of a String
Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Henri Yandell closed LANG-405.
------------------------------
Resolution: Fixed
Scratch that - I'd incorrectly copied it and had "..". Patch looks good:
svn ci -m "Applying Srihari Reddy's patch from LANG-405, based on Dave Meikle's original patch. This adds a truncateMiddle method to StringUtils. "
Sending src/main/java/org/apache/commons/lang3/StringUtils.java
Sending src/test/java/org/apache/commons/lang3/StringUtilsTest.java
Transmitting file data ..
Committed revision 901595.
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Components: lang.*
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 3.0
>
> Attachments: LANG-405.diff, LANG-405.diff, LANG-405.diff
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-405) StringUtils.truncate() to cut out
middle part of a String
Posted by "Gregor B. Rosenauer (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12568703#action_12568703 ]
Gregor B. Rosenauer commented on LANG-405:
------------------------------------------
actually
public String truncateMiddle(String str, int length);
would suffice since the middle part is shortened to an ellipsis "...", or was the "String middle" ment as a placeholder?
Anyway, 'nough talking, I see your hint clearly:) Hope to have some time by the end of the week to look into this.
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 3.0
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-405) StringUtils.truncate() to cut out
middle part of a String
Posted by "Gregor B. Rosenauer (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12565113#action_12565113 ]
Gregor B. Rosenauer commented on LANG-405:
------------------------------------------
Thanks for looking into this little feature request:)
@Henri: Yes, in BeOS this function was used to shorten filenames for display in the desktop filemanager, Tracker, and was available in the standard API. It was a cool feature, like most other aspects of the BeOS, way ahead of its time,-)
@Sebb: good question, I think it would be way too much effort to put in word or even sentence recognition (which words or sentences make sense in which language etc.). I would be happy enough to have an equal number of characters at each side. This would be enough for the main use cases I encountered so far:
1. there are multiple Strings and cutting off the beginning/end of a String is not enough to differentiate them, like in user interfaces (tables etc.).
2. you need an excerpt of a String that is too big as a whole, e.g. logging an XML-document where the beginning/end is both interesting but the middle part is big and not needed as a whole
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-405) StringUtils.truncate() to cut out
middle part of a String
Posted by "Gregor B. Rosenauer (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12565218#action_12565218 ]
Gregor B. Rosenauer commented on LANG-405:
------------------------------------------
Henry, I understood your original comment and you are right that the documentation does not explicitly mention this. However I remember this String function was indeed supported, and in any way the reference was only ment to illustrate the feature I am suggesting here...,-)
FWIW, here is a screenshot to an example (it seems to just cut out the part exceeding the total length from the middle), 3rd screenshot that shows the mail messages:
http://www.beatjapan.org/mirror/www.be.com/documentation/user_docs/04_internet_use.html#Using Internet Mail Services
(Aah, BeOS is still good for some inspiration:)
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Issue Comment Edited: (LANG-405) StringUtils.truncate() to
cut out middle part of a String
Posted by "Dave Meikle (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12569731#action_12569731 ]
davemeikle edited comment on LANG-405 at 5/19/08 3:52 AM:
-----------------------------------------------------------
Initial implementation that I believe does what was discussed, although this will need to be checked.
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 3.0
>
> Attachments: LANG-405.diff
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-405) StringUtils.truncate() to cut out
middle part of a String
Posted by "Srihari Reddy (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12803234#action_12803234 ]
Srihari Reddy commented on LANG-405:
------------------------------------
Thanks Henri. i added the new test case to the junit test case assertEquals("ab.ef", StringUtils.truncateMiddle("abcdef", ".", 5));
The result of StringUtils.truncateMiddle("abcdef", ".", 5) is ab.ef.
i am attaching the updated patch.
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Components: lang.*
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 3.0
>
> Attachments: LANG-405.diff, LANG-405.diff, LANG-405.diff
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-405) StringUtils.truncate() to cut out
middle part of a String
Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12565147#action_12565147 ]
Henri Yandell commented on LANG-405:
------------------------------------
I didn't explain myself well - the documentation you point to for Truncate does not suggest it does what you're saying. It seems to just be a substring( 0, n ) function, which Java comfortably supports.
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-405) StringUtils.truncate() to cut out
middle part of a String
Posted by "Sebb (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12803294#action_12803294 ]
Sebb commented on LANG-405:
---------------------------
Indeed, but it is not called truncate(), it is called truncateMiddle().
Perhaps the JIRA issue title needs to be changed?
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Components: lang.*
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 3.0
>
> Attachments: LANG-405.diff, LANG-405.diff, LANG-405.diff
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (LANG-405) Cut out middle part of a String
Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12803402#action_12803402 ]
Niall Pemberton commented on LANG-405:
--------------------------------------
OK I've renamed the method to abbreviateMiddle()
http://svn.apache.org/viewvc?view=revision&revision=901815
> Cut out middle part of a String
> -------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Components: lang.*
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
> Fix For: 3.0
>
> Attachments: LANG-405.diff, LANG-405.diff, LANG-405.diff
>
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Issue Comment Edited: (LANG-405) StringUtils.truncate() to
cut out middle part of a String
Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/LANG-405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12565032#action_12565032 ]
bayard edited comment on LANG-405 at 2/1/08 9:41 PM:
------------------------------------------------------------
Are you sure that's what the BeOS function did? Reading the docs, Truncate( n ) looks like java.lang.String.substring( 0,n ).
was (Author: bayard):
Are you sure that's what the BeOS function did? Reading the docs, Truncate(n) looks like java.lang.String.substring(0,n).
> StringUtils.truncate() to cut out middle part of a String
> ---------------------------------------------------------
>
> Key: LANG-405
> URL: https://issues.apache.org/jira/browse/LANG-405
> Project: Commons Lang
> Issue Type: New Feature
> Affects Versions: 2.2
> Reporter: Gregor B. Rosenauer
> Priority: Minor
>
> It would be handy to have a String method that cuts out the middle part of a String such that as much as possible is kept from the start and end of the String, but the middle part is replaced by an ellipsis "..."
> BeOS had a function like this, but it's poorly documented, missing examples:
> http://www.beunited.org/bebook/The%20Support%20Kit/String.html#Truncate()
> e.g.:
> A very long text with unimportant stuff in the middle but interesting start and end to see if the text is complete.
> becomes:
> A very long text...to see if the text is complete.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.