Ejemplo n.º 1
0
        private string s_stringEscaped(string str, PrivateWexprValueStringProperties props)
        {
            var buf = "";

            if (!props.isBarewordSafe)
            {
                buf += '\"';
            }

            for (int i = 0; i < str.Length; ++i)
            {
                char c = str[i];

                if (s_requiresEscape(c))
                {
                    // write it out as an escape
                    buf += '\\';
                    buf += s_escapeForValue(c);
                }
                else
                {
                    buf += c;
                }
            }

            if (!props.isBarewordSafe)
            {
                // add quotes
                buf += '\"';
            }

            return(buf);
        }
Ejemplo n.º 2
0
        private PrivateWexprValueStringProperties s_wexprValueStringProperties(string str)
        {
            var props = new PrivateWexprValueStringProperties();

            props.isBarewordSafe = true;             // default to being safe
            props.needsEscaping  = false;            // but we dont need escaping
            props.writeByteSize  = 0;

            var len = str.Length;

            for (var i = 0; i < len; ++i)
            {
                // For now we cant escape so that stays false.
                // bareword safe we'll just check for a few symbols
                char c = str[i];

                // see any symbols that makes it not bareword safe?
                if (s_isNotBarewordSafe(c))
                {
                    props.isBarewordSafe = false;
                }

                // we at least write the character
                props.writeByteSize += 1;

                // does it need to be escaped?
                if (c == '"')
                {
                    props.writeByteSize += 1;                     // needs the escape
                }
            }

            if (len == 0)
            {
                props.isBarewordSafe = false;                 // empty string is not safe, since that will be nothing
            }
            return(props);
        }