class DefaultFieldParser implements FieldParser {

    @Override
    public FieldMap parse( String fields )
    {
        List<String> prefixList = Lists.newArrayList();
        FieldMap fieldMap = new FieldMap();

        StringBuilder builder = new StringBuilder();

        String[] fieldSplit = fields.split( "" );

        for ( int i = 0; i < fieldSplit.length; i++ )
        {
            String c = fieldSplit[i];

            // if we reach a field transformer, parse it out here (necessary to allow for () to be used to handle transformer parameters)
            if ( (c.equals( ":" ) && fieldSplit[i + 1].equals( ":" )) || c.equals( "~" ) || c.equals( "|" ) )
            {
                boolean insideParameters = false;

                for ( ; i < fieldSplit.length; i++ )
                {
                    c = fieldSplit[i];

                    if ( StringUtils.isAlphanumeric( c ) || c.equals( ":" ) || c.equals( "~" ) || c.equals( "|" ) )
                    {
                        builder.append( c );
                    }
                    else if ( c.equals( "(" ) ) // start parameter
                    {
                        insideParameters = true;
                        builder.append( c );
                    }
                    else if ( insideParameters && c.equals( ";" ) ) // allow parameter separator
                    {
                        builder.append( c );
                    }
                    else if ( (insideParameters && c.equals( ")" )) ) // end
                    {
                        builder.append( c );
                        break;
                    }
                    else if ( c.equals( "," ) || ( c.equals( "[" ) && !insideParameters ) ) // rewind and break
                    {
                        i--;
                        break;
                    }
                }
            }
            else if ( c.equals( "," ) )
            {
                putInMap( fieldMap, joinedWithPrefix( builder, prefixList ) );
                builder = new StringBuilder();
            }
            else if ( c.equals( "[" ) || c.equals( "(" ) )
            {
                prefixList.add( builder.toString() );
                builder = new StringBuilder();
            }
            else if ( c.equals( "]" ) || c.equals( ")" ) )
            {
                if ( !builder.toString().isEmpty() )
                {
                    putInMap( fieldMap, joinedWithPrefix( builder, prefixList ) );
                }

                prefixList.remove( prefixList.size() - 1 );
                builder = new StringBuilder();
            }
            else if ( StringUtils.isAlphanumeric( c ) || c.equals( "*" ) || c.equals( ":" ) || c.equals( ";" ) || c.equals( "~" ) || c.equals( "!" )
                || c.equals( "|" ) || c.equals( "{" ) || c.equals( "}" ) )
            {
                builder.append( c );
            }
        }

        if ( !builder.toString().isEmpty() )
        {
            putInMap( fieldMap, joinedWithPrefix( builder, prefixList ) );
        }

        return fieldMap;
    }

}