/*-
 * Copyright (c) 2012 Red Hat, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.fedoraproject.maven.utils;

import java.util.regex.Pattern;

public class GlobUtils
{
    private static final String specialChars = "(){}.,?*+|<=>!";

    private static String glob2re( String glob )
    {
        StringBuilder re = new StringBuilder();
        boolean escape = false;
        int level = 0;

        re.append( '^' );

        for ( char ch : glob.toCharArray() )
        {
            if ( escape )
            {
                if ( specialChars.indexOf( ch ) >= 0 )
                    re.append( '\\' );
                re.append( ch );
                escape = false;
            }
            else if ( ch == '\\' )
            {
                escape = true;
            }
            else if ( ch == '{' )
            {
                level++;
                re.append( '(' );
            }
            else if ( ch == '}' && level > 0 )
            {
                re.append( ')' );
                level--;
            }
            else if ( ch == ',' && level > 0 )
            {
                re.append( '|' );
            }
            else if ( ch == '?' )
            {
                re.append( '.' );
            }
            else if ( ch == '*' )
            {
                re.append( '.' );
                re.append( '*' );
            }
            else
            {
                if ( specialChars.indexOf( ch ) >= 0 )
                    re.append( '\\' );
                re.append( ch );
            }
        }

        if ( escape )
            throw new Error( "Excape sequence ends prematurely" );
        if ( level != 0 )
            throw new Error( "Alternative not closed" );

        re.append( '$' );
        return re.toString();
    }

    public static Pattern glob2pattern( String glob )
    {
        if ( glob == null )
            return null;
        return Pattern.compile( glob2re( glob ) );
    }
}

@@ -672,110 +672,565 @@
 n;%0A%0A
-public class GlobUtils%0A%7B%0A    private static final String specialChars = %22()%7B%7D.,?*+%7C%3C=%3E!%22;%0A%0A    private
+/**%0A * Utility routines for converting glob paterns to regulat expressions.%0A * %0A * @author Mikolaj Izdebski%0A */%0Apublic class GlobUtils%0A%7B%0A    /**%0A     * Character with special meaning in regular expression namespace. These characters should be escaped when%0A     * converting glob expression to regular expression.%0A     */%0A    private static final String specialChars = %22()%7B%7D.,?*+%7C%3C=%3E!%22;%0A%0A    /**%0A     * Convert wildcard pattern to regular expression.%0A     * %0A     * @param glob wildcard pattern to convery%0A     * @return regular expression%0A     */%0A    public
  sta
@@ -2767,24 +2767,215 @@
 g();%0A    %7D%0A%0A
+    /**%0A     * Create %3Ccode%3EPattern%3C/code%3E from wildcard patter.%0A     * %0A     * @param glob wildcard pattern to convery%0A     * @return pattern corresponding to given wildcard pattern%0A     */%0A
     public s

Document GlobUtils