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

Provide access to expanded replacement string

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • None
    • core-libs
    • None

      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.

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

              Created:
              Updated: