On 22:20 Wed 26 Jan     , Pekka Enberg wrote:
> From 674bac6bc573322c0003f7947ff9446efbc1d349 Mon Sep 17 00:00:00 2001
> From: Ivan Maidanski <iv...@mail.ru>
> Date: Sat, 22 Jan 2011 21:36:13 +0200
> Subject: [PATCH] Implement Pattern.quote() API method
> 
> 2010-07-02  Ivan Maidanski  <iv...@mail.ru>
> 
>       * java/util/regex/Pattern.java:
>       (quote): Implement new 1.5 Java API method.
> ---
>  ChangeLog                    |    5 +++++
>  java/util/regex/Pattern.java |   39 ++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 43 insertions(+), 1 deletions(-)
> 
> diff --git a/ChangeLog b/ChangeLog
> index 4d0bf6d..52b4760 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,8 @@
> +2010-07-02  Ivan Maidanski  <iv...@mail.ru>
> +
> +     * java/util/regex/Pattern.java:
> +     (quote): Implement new 1.5 Java API method.
> +
>  2011-01-21  Pekka Enberg <penb...@kernel.org>
>  
>       * java/lang/Class.java:
> diff --git a/java/util/regex/Pattern.java b/java/util/regex/Pattern.java
> index 7d1fc84..4b306a0 100644
> --- a/java/util/regex/Pattern.java
> +++ b/java/util/regex/Pattern.java
> @@ -1,5 +1,6 @@
>  /* Pattern.java -- Compiled regular expression ready to be applied.
> -   Copyright (C) 2002, 2004, 2005, 2007 Free Software Foundation, Inc.
> +   Copyright (C) 2002, 2004, 2005, 2007, 2010
> +   Free Software Foundation, Inc.
>  
>  This file is part of GNU Classpath.
>  
> @@ -37,6 +38,8 @@ exception statement from your version. */
>  
>  package java.util.regex;
>  
> +import gnu.java.lang.CPStringBuilder;
> +
>  import gnu.java.util.regex.RE;
>  import gnu.java.util.regex.REException;
>  import gnu.java.util.regex.RESyntax;
> @@ -260,6 +263,40 @@ public final class Pattern implements Serializable
>    }
>  
>    /**
> +   * Returns a literal pattern for the specified String.
> +   * @param String to return a literal pattern for.
> +   * @exception NullPointerException if str is null.
> +   * @returns a literal pattern for the specified String.
> +   * @since 1.5
> +   */
> +  public static String quote(String str)
> +  {
> +    int eInd = str.indexOf("\\E");
> +    if (eInd < 0)
> +      {
> +        // No need to handle backslashes.
> +        return "\\Q" + str + "\\E";
> +      }
> +
> +    CPStringBuilder sb = new CPStringBuilder(str.length() + 16);
> +    sb.append("\\Q"); // start quote
> +
> +    int pos = 0;
> +    do
> +      {
> +        // A backslash is quoted by another backslash;
> +        // 'E' is not needed to be quoted.
> +        sb.append(str.substring(pos, eInd))
> +          .append("\\E" + "\\\\" + "E" + "\\Q");
> +        pos = eInd + 2;
> +      } while ((eInd = str.indexOf("\\E", pos)) >= 0);
> +
> +    sb.append(str.substring(pos, str.length()))
> +      .append("\\E"); // end quote
> +    return sb.toString();
> +  }
> +
> +  /**
>     * Return the regular expression used to construct this object.
>     * @specnote Prior to JDK 1.5 this method had a different behavior
>     * @since 1.5
> -- 
> 1.7.1
> 
> 
> 

A blank line between the description and the @param would look better i.e.:

> +   * Returns a literal pattern for the specified String.
> +   *
> +   * @param String to return a literal pattern for.
> +   * @exception NullPointerException if str is null.
> +   * @returns a literal pattern for the specified String.
> +   * @since 1.5

Good to commit with that change.
-- 
Andrew :)

Free Java Software Engineer
Red Hat, Inc. (http://www.redhat.com)

Support Free Java!
Contribute to GNU Classpath and IcedTea
http://www.gnu.org/software/classpath
http://icedtea.classpath.org
PGP Key: 94EFD9D8 (http://subkeys.pgp.net)
Fingerprint = F8EF F1EA 401E 2E60 15FA  7927 142C 2591 94EF D9D8

Reply via email to