{"action":"created","issue":{"url":"https://api.github.com/repos/google/guava/issues/651","repository_url":"https://api.github.com/repos/google/guava","labels_url":"https://api.github.com/repos/google/guava/issues/651/labels{/name}","comments_url":"https://api.github.com/repos/google/guava/issues/651/comments","events_url":"https://api.github.com/repos/google/guava/issues/651/events","html_url":"https://github.com/google/guava/issues/651","id":47420327,"number":651,"title":"Strings.replaceAll(target, regex, fn(MatchResult, String))","user":{"login":"gissuebot","id":8091570,"avatar_url":"https://avatars.githubusercontent.com/u/8091570?v=3","gravatar_id":"","url":"https://api.github.com/users/gissuebot","html_url":"https://github.com/gissuebot","followers_url":"https://api.github.com/users/gissuebot/followers","following_url":"https://api.github.com/users/gissuebot/following{/other_user}","gists_url":"https://api.github.com/users/gissuebot/gists{/gist_id}","starred_url":"https://api.github.com/users/gissuebot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gissuebot/subscriptions","organizations_url":"https://api.github.com/users/gissuebot/orgs","repos_url":"https://api.github.com/users/gissuebot/repos","events_url":"https://api.github.com/users/gissuebot/events{/privacy}","received_events_url":"https://api.github.com/users/gissuebot/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/google/guava/labels/package:%20base","name":"package: base","color":"207de5"},{"url":"https://api.github.com/repos/google/guava/labels/status:%20research","name":"status: research","color":"bfe5bf"},{"url":"https://api.github.com/repos/google/guava/labels/type:%20addition","name":"type: addition","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2014-10-31T17:19:16Z","updated_at":"2016-07-12T14:13:04Z","closed_at":null,"body":"_[Original issue](https://code.google.com/p/guava-libraries/issues/detail?id=651) created by **pholser** on 2011-07-07 at 01:52 AM_\n\n---\n\nA possible implementation:\n\npublic class Strings {\n&nbsp;&nbsp;&nbsp;&nbsp;private Strings() {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new UnsupportedOperationException();\n&nbsp;&nbsp;&nbsp;&nbsp;}\n\n    public static String replaceAll(String target, String regex, Function<MatchResult, String> operation) {\n        StringBuffer result = new StringBuffer(target.length() * 3 / 2);\n        Pattern pattern = Pattern.compile(regex);\n\n        Matcher matcher = pattern.matcher(target);\n        while (matcher.find()) {\n            MatchResult match = matcher.toMatchResult();\n            String replacement = operation.apply(match);\n            if (!replacement.equals(match.group()))\n                matcher.appendReplacement(result, replacement);\n        }\n        matcher.appendTail(result);\n\n        return result.toString();\n    }\n}\n\nI'm ambivalent about whether to make the type of 'regex' a Pattern or leave it as a String for the method to compile().\n\nMotivation: To allow global replacement of matches with the result of a function of the match result, a la C#'s Regex.Replace(string, MatchEvaluator). PITA to roll the appendReplacement/appendTail bit by hand.\n"},"comment":{"url":"https://api.github.com/repos/google/guava/issues/comments/232059956","html_url":"https://github.com/google/guava/issues/651#issuecomment-232059956","issue_url":"https://api.github.com/repos/google/guava/issues/651","id":232059956,"user":{"login":"ogregoire","id":666970,"avatar_url":"https://avatars.githubusercontent.com/u/666970?v=3","gravatar_id":"","url":"https://api.github.com/users/ogregoire","html_url":"https://github.com/ogregoire","followers_url":"https://api.github.com/users/ogregoire/followers","following_url":"https://api.github.com/users/ogregoire/following{/other_user}","gists_url":"https://api.github.com/users/ogregoire/gists{/gist_id}","starred_url":"https://api.github.com/users/ogregoire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ogregoire/subscriptions","organizations_url":"https://api.github.com/users/ogregoire/orgs","repos_url":"https://api.github.com/users/ogregoire/repos","events_url":"https://api.github.com/users/ogregoire/events{/privacy}","received_events_url":"https://api.github.com/users/ogregoire/received_events","type":"User","site_admin":false},"created_at":"2016-07-12T14:13:04Z","updated_at":"2016-07-12T14:13:04Z","body":"I've started an implementation that matches exactly, not based on regex, but I guess it can easily be improved.\r\n\r\nIt can be seen here: https://gist.github.com/ogregoire/8c95bd3ab7c7e670a5012caad47125e3\r\n\r\nIf I'm not lost in other considerations, I'll try to make this into a guava-like class and create a PR."}}
{"actor":{"display_login":"ogregoire"}}