Example #1
0
        protected object GetTokenAsSinglyQuotedString(int startIndex, Encoding /*!*/ encoding, bool forceBinaryString)
        {
            PhpStringBuilder result = new PhpStringBuilder(encoding, forceBinaryString, TokenLength);

            int buffer_pos = token_start + startIndex + 1;

            // the following loops expect the token ending by '
            Debug.Assert(buffer[buffer_pos - 1] == '\'' && buffer[token_end - 1] == '\'');

            //StringBuilder result = new StringBuilder(TokenLength);
            char c;

            while ((c = buffer[buffer_pos++]) != '\'')
            {
                if (c == '\\')
                {
                    switch (c = buffer[buffer_pos++])
                    {
                    case '\\':
                    case '\'':
                        result.Append(c);
                        break;

                    // ??? will cause many problems ... but PHP allows this
                    //case 'C':
                    //  if (!inUnicodeString) goto default;
                    //  result.Append(ParseCodePointName(ref buffer_pos));
                    //  break;

                    //case 'u':
                    //case 'U':
                    //  if (!inUnicodeString) goto default;
                    //  result.Append(ParseCodePoint( c == 'u' ? 4 : 6, ref buffer_pos));
                    //  break;

                    default:
                        result.Append('\\');
                        result.Append(c);
                        break;
                    }
                }
                else
                {
                    result.Append(c);
                }
            }

            return(result.Result);
        }
Example #2
0
        //protected void GetTokenAsQualifiedName(int startIndex, List<string>/*!*/ result)
        //{
        //    Debug.Assert(result != null);

        //    int current_name = token_start + startIndex;
        //    int next_separator = token_start + startIndex;

        //    for (; ; )
        //    {
        //        while (next_separator < token_end && buffer[next_separator] != '\\')
        //            next_separator++;

        //        if (next_separator == token_end) break;

        //        result.Add(new String(buffer, current_name, next_separator - current_name));
        //        next_separator += QualifiedName.Separator.ToString().Length;
        //        current_name = next_separator;
        //    }

        //    // last item:
        //    result.Add(new String(buffer, current_name, token_end - current_name));
        //}

        #region GetTokenAs*QuotedString

        protected object GetTokenAsDoublyQuotedString(int startIndex, Encoding /*!*/ encoding, bool forceBinaryString)
        {
            PhpStringBuilder result = new PhpStringBuilder(encoding, forceBinaryString, TokenLength);

            int buffer_pos = token_start + startIndex + 1;

            // the following loops expect the token ending by "
            Debug.Assert(buffer[buffer_pos - 1] == '"' && buffer[token_end - 1] == '"');

            //StringBuilder result = new StringBuilder(TokenLength);

            char c;

            while ((c = buffer[buffer_pos++]) != '"')
            {
                if (c == '\\')
                {
                    switch (c = buffer[buffer_pos++])
                    {
                    case 'n':
                        result.Append('\n');
                        break;

                    case 'r':
                        result.Append('\r');
                        break;

                    case 't':
                        result.Append('\t');
                        break;

                    case '\\':
                    case '$':
                    case '"':
                        result.Append(c);
                        break;

                    case 'C':
                        if (!inUnicodeString)
                        {
                            goto default;
                        }
                        result.Append(ParseCodePointName(ref buffer_pos));
                        break;

                    case 'u':
                    case 'U':
                        if (!inUnicodeString)
                        {
                            goto default;
                        }
                        result.Append(ParseCodePoint(c == 'u' ? 4 : 6, ref buffer_pos));
                        break;

                    case 'x':
                    {
                        int digit;
                        if ((digit = Convert.AlphaNumericToDigit(buffer[buffer_pos])) < 16)
                        {
                            int hex_code = digit;
                            buffer_pos++;
                            if ((digit = Convert.AlphaNumericToDigit(buffer[buffer_pos])) < 16)
                            {
                                buffer_pos++;
                                hex_code = (hex_code << 4) + digit;
                            }

                            //encodeBytes[0] = (byte)hex_code;
                            //result.Append(encodeChars, 0, encoding.GetChars(encodeBytes, 0, 1, encodeChars, 0));
                            result.Append((byte)hex_code);
                        }
                        else
                        {
                            result.Append('\\');
                            result.Append('x');
                        }
                        break;
                    }

                    default:
                    {
                        int digit;
                        if ((digit = Convert.NumericToDigit(c)) < 8)
                        {
                            int octal_code = digit;

                            if ((digit = Convert.NumericToDigit(buffer[buffer_pos])) < 8)
                            {
                                octal_code = (octal_code << 3) + digit;
                                buffer_pos++;

                                if ((digit = Convert.NumericToDigit(buffer[buffer_pos])) < 8)
                                {
                                    buffer_pos++;
                                    octal_code = (octal_code << 3) + digit;
                                }
                            }
                            //encodeBytes[0] = (byte)octal_code;
                            //result.Append(encodeChars, 0, encoding.GetChars(encodeBytes, 0, 1, encodeChars, 0));
                            result.Append((byte)octal_code);
                        }
                        else
                        {
                            result.Append('\\');
                            result.Append(c);
                        }
                        break;
                    }
                    }
                }
                else
                {
                    result.Append(c);
                }
            }

            return(result.Result);
        }