commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <j...@apache.org>
Subject [jira] Updated: (LANG-180) [lang] adding a StringUtils.replace method that takes an array or List of replacement strings
Date Fri, 25 Jan 2008 08:46:34 GMT

     [ https://issues.apache.org/jira/browse/LANG-180?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Henri Yandell updated LANG-180:
-------------------------------

    Attachment: LANG-180.patch

I managed to find a bit of time to look at the core of the code and am attaching my modifications.


I've folded the other static methods inside the main functions. On the one hand, that's bad
coding, on the other this is a huge file with many static methods and doing the code inline
when it's not being reused much helps keep things simpler.

Also I've modified the API slightly - passing in a null 'with' is also a no-op. Previously
a null repl but existent 'with' was a no-op, but a null 'with' and existent 'repl' was considered
an exception due to different lengths. Possibly the correct solution is to make both cases
exceptions rather than no-ops.

> [lang] adding a StringUtils.replace method that takes an array or List of replacement
strings
> ---------------------------------------------------------------------------------------------
>
>                 Key: LANG-180
>                 URL: https://issues.apache.org/jira/browse/LANG-180
>             Project: Commons Lang
>          Issue Type: Improvement
>         Environment: Operating System: other
> Platform: Other
>            Reporter: Chris
>            Priority: Minor
>             Fix For: 2.4
>
>         Attachments: LANG-180.patch, LANG-180.patch, StringUtilsAndText.java
>
>
> I have the situation where I have a String template with a dozen replacements 
> I need to make.  When I loop through and use StringUtils.replace each time, it 
> has to make a StringBuffer of the whole template each time.  I think we could 
> make this more efficient if we had a replace() method which took an array of 
> Strings to search for, and an array of Strings to replace with (or we could 
> use a Collection or List or something).  This way we could possibly do the 
> replace in one StringBuffer result.
> One issue is if the replacement text has Strings to be replaced, do we iterate 
> through again until there are no Strings to search for?  Based on your 
> replaceChars(String str, String searchChars, String replaceChars) method, I 
> assume the answer is no, but we could have a boolean flag to have it both ways.
> I can write this for you if you are interested, please let me know.
> Thanks!
> Chris

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message