Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-5417

Add findResult() to String

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Duplicate
    • None
    • None
    • groovy-jdk
    • None

    Description

      Collection implements a method with the following signature:

      public Object findResult(Closure closure)

      It would be nice if a similar method existed for String.

      public Object findResult(Pattern pattern, Closure closure)

      The method find() almost performs the same function except that it converts the result to a string, even if it's null or a Boolean. Alternatively, the existing find() methods could be changed to return Object instead of String. Without this method, the matching string has to be saved into a temporary variable and then processed afterwards.

      Example:
      if (new File("file").text.findResult(~/VAR\s*=\s*(\S+)/)

      { it[1] != "VALUE1" }

      ) {
      // ...
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            balor123 Uri Moszkowicz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: