public static ELText parse()

in impl/src/main/java/org/apache/myfaces/view/facelets/el/ELText.java [538:642]


    public static ELText parse(ExpressionFactory fact, ELContext ctx, String in, Location location) throws ELException
    {
        char[] ca = in.toCharArray();
        int i = 0;
        char c = 0;
        int len = ca.length;
        int end = len - 1;
        boolean esc = false;
        int vlen = 0;

        StringBuilder buff = null;
        List<ELText> text = null;
        ELText t = null;
        ValueExpression ve = null;

        while (i < len)
        {
            c = ca[i];
            if ('\\' == c)
            {
                esc = !esc;
                if (esc && i < end && (ca[i + 1] == '$' || ca[i + 1] == '#'))
                {
                    i++;
                    continue;
                }
            }
            else if (!esc && ('$' == c || '#' == c))
            {
                if (i < end)
                {
                    if ('{' == ca[i + 1])
                    {
                        if (buff != null && buff.length() > 0)
                        {
                            if (text == null)
                            {
                                text = new ArrayList<>();
                            }
                            text.add(new ELText(buff.toString()));
                            buff.setLength(0);
                        }
                        vlen = findVarLength(ca, i);
                        if (ctx != null && fact != null)
                        {
                            ve = fact.createValueExpression(ctx, new String(ca, i, vlen), String.class);
                            if (location != null)
                            {
                                ve = new ContextAwareTagValueExpression(location, "expression", ve);
                            }
                            t = new ELCacheableTextVariable(ve);
                        }
                        else
                        {
                            ve = new LiteralValueExpression(new String(ca, i, vlen));
                            if (location != null)
                            {
                                ve = new ContextAwareTagValueExpression(location, "expression", ve);
                            }
                            t = new ELCacheableTextVariable(ve);
                        }
                        if (text == null)
                        {
                            text = new ArrayList<>();
                        }
                        text.add(t);
                        i += vlen;
                        continue;
                    }
                }
            }

            esc = false;
            if (buff == null)
            {
                buff = new StringBuilder(128);
            }
            buff.append(c);
            i++;
        }

        if (buff != null && buff.length() > 0)
        {
            if (text == null)
            {
                text = new ArrayList<>();
            }
            text.add(new ELText(buff.toString()));
            buff.setLength(0);
        }

        if (text == null || text.isEmpty())
        {
            return null;
        }
        else if (text.size() == 1)
        {
            return text.get(0);
        }
        else
        {
            ELText[] ta = text.toArray(new ELText[text.size()]);
            return new ELTextComposite(ta);
        }
    }