Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8261619

provide access to expanded replacement string

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: tbd
    • Component/s: core-libs
    • Labels:
      None

      Description

      In Matcher, there are a couple of models for how to do find/replace sequences, but neither expose the ability to directly access the expanded replacement string, as evaluated internally by `Matcher.appendExpandedReplacement`.

      Providing direct access to the expanded replacement would allow a user to support additional find/replace models, especially when matching against a CharSequence derived from an alternate representation for the string being matched.

      The new method could be as simple as:

      public String getExpandedReplacement(String replacement) {
          return appendExpandedReplacement(replacement, new StringBuilder()).toString();
      }
         
      In other words, it can be a simple wrapper around existing functionality.

      Currently, the only way to indirectly access the value is to use `Matcher.appendReplacement` and discard the first part of the value added in to the `StringBuilder`, which is pretty ugly.

        Attachments

          Activity

            People

            Assignee:
            smarks Stuart Marks
            Reporter:
            jjg Jonathan Gibbons
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: