/*
 *
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You 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.apache.flex.compiler.internal.css;

import org.antlr.runtime.TokenStream;
import org.antlr.runtime.tree.CommonTree;

/**
 * Implementation for CSS string property values. For example:<br>
 * <code>{ fontFamily: "Sans Serif"; }</code>
 */
public class CSSStringPropertyValue extends CSSPropertyValue
{

    protected CSSStringPropertyValue(final String stringWithQuotes,
                                     final CommonTree tree,
                                     final TokenStream tokenStream)
    {
        super(tree, tokenStream, CSSModelTreeType.PROPERTY_VALUE);
        assert isQuoted(stringWithQuotes) : "Don't strip quotes in parser: [" + stringWithQuotes + "]";
        this.value = stripQuotes(stringWithQuotes);
    }

    private final String value;

    /**
     * @return The string value without the quotes.
     */
    public String getValue()
    {
        return value;
    }

    @Override
    public String toString()
    {
        return String.format("\"%s\"", value);
    }

    /**
     * Check if the string is quoted with single quotes or double quotes.
     * 
     * @param testString string to test
     * @return True if the string is quoted.
     */
    public static boolean isQuoted(final String testString)
    {
        return (testString.startsWith("\"") && testString.endsWith("\"")) ||
               (testString.startsWith("'") && testString.endsWith("'"));
    }

    /**
     * Strip one pair of quotes around the string.
     * 
     * @param value string to strip
     * @return Stripped string.
     */
    public static String stripQuotes(final String value)
    {
        return value.substring(1, value.length() - 1);
    }
}

@@ -1522,16 +1522,31 @@
 value = 
+convertEscapes(
 stripQuo
@@ -1566,16 +1566,17 @@
 hQuotes)
+)
 ;%0A    %7D%0A
@@ -2448,32 +2448,32 @@
 ng value)%0A    %7B%0A
-
         return v
@@ -2517,10 +2517,1145 @@
 ;%0A    %7D%0A
+    %0A    private static String convertEscapes(String value)%0A    %7B%0A        int idx = 0;%0A        int c = value.indexOf('%5C%5C');%0A        while (c != -1)%0A        %7B%0A            char cnext = value.charAt(c + 1);%0A            if (cnext != '%5C%5C' && cnext != 'n' && cnext != 't' && cnext != 'r')%0A            %7B%0A                int n = value.length() - (c + 1);%0A                if (n %3E 6)%0A                    n = 6;%0A                StringBuilder sub = new StringBuilder();%0A                int i = 0;%0A                for (; i %3C n; i++)%0A                %7B%0A                    char cc = value.charAt(c + i + 1);%0A                    if (cc != ' ')%0A                        sub.append(cc);%0A                    else%0A                        break;%0A                %7D%0A                int ccode = Integer.parseInt(sub.toString(), 16);%0A                sub = new StringBuilder();%0A                sub.append(Character.toChars(ccode));%0A                value = value.substring(0, c) + sub.toString() + value.substring(c + i + 1);%0A            %7D%0A            else%0A                idx += 2;%0A            c = value.indexOf('%5C%5C', idx);%0A        %7D%0A        return value;%0A    %7D%0A
 %7D%0A

handle escapes