Exemplo n.º 1
0
        public void set_jsfile_single_value(char[] value, char[][] key, int key_size, ref JsonData jsonData)
        {
            jsmntok_t[] token      = jsonData.tokens;
            char[]      content    = jsonData.content;
            int         token_size = jsonData.token_size;

            range_t range = this.getAllRange(token);
            range_t temp_range = new range_t();
            int     i = 0, i2 = 0, i_value = 0;
            int     shift     = 0;
            int     data_flag = 0;


            for (i = 0; i < key_size; i++)
            {
                temp_range.start = range.start;
                temp_range.end   = range.end;
                char[] noUse = null;
                this.searchJsonDataInRange(key[i], temp_range, jsonData, ref noUse, ref range);
            }
            string str = new string(key[i - 1]);

            if (str == "Data" && value[0] == '{')
            {
                data_flag = 1;
            }
            char[] temp_content = new char[JsFileParser.MAXPACKETSIZE];
            i       = 0;
            i2      = 0;
            i_value = 0;
            while (true)
            {
                if (i < range.start || i >= range.end)
                {
                    temp_content[i2] = content[i];
                    if (content[i] == '\0')
                    {
                        break;
                    }
                    i++;
                    i2++;
                }
                else
                {
                    if (value[i_value] == '\0')
                    {
                        i = range.end;
                    }
                    else
                    {
                        /*
                         * if (data_flag == 1 && (i_value == 0 || value[i_value - 1] == '\n'))
                         * {
                         *  if (i_value == 0)
                         *  {
                         *      temp_content[i2] = '\n';
                         *      i2++;
                         *  }
                         *  temp_content[i2] = '\t';
                         *  temp_content[i2 + 1] = '\t';
                         *  i2 += 2;
                         * }
                         */
                        temp_content[i2] = value[i_value];
                        i2++;
                        i_value++;
                    }
                }
            }
            shift = i2 - token[0].end;
            i     = 0;
            Coder.arr_puts(temp_content, content, ref i);
            content[i] = '\0';
            for (i = 0; i < token_size; i++)
            {
                if (token[i].start > range.start)
                {
                    token[i].start += shift;
                }
                if (token[i].end >= range.start)
                {
                    token[i].end += shift;
                }
            }
            //content_size = token[0].end;
            jsonData.content_size = token[0].end;

            return;
        }
Exemplo n.º 2
0
        public int build_packet(char[] input, token_info info, char[] packet, int tab_num)
        {
            if (info_i == info.num)
            {
                return(packet_i);
            }
            int packet_size = 0;
            int i;
            int son;

            if (tab_num != 0)
            {
                Coder.arr_putc('\n', packet, ref packet_i);
            }
            for (i = 0; i < tab_num; i++)
            {
                Coder.arr_putc('\t', packet, ref packet_i);
            }
            if (info.name_lens[info_i] != 0)
            {
                Coder.arr_putc('"', packet, ref packet_i);
                Coder.arr_puts(info.names[info_i], packet, ref packet_i);
                Coder.arr_putc('"', packet, ref packet_i);
            }
            switch (info.types[info_i])
            {
            case jsmntype_t.JSMN_OBJECT:
                son = info.sons[info_i];
                Coder.arr_putc('{', packet, ref packet_i);
                for (i = 0; i < son; i++)
                {
                    info_i++;
                    build_packet(input, info, packet, tab_num + 1);
                    if (i != son - 1)
                    {
                        Coder.arr_putc(',', packet, ref packet_i);
                    }
                }
                Coder.arr_putc('\n', packet, ref packet_i);
                for (i = 0; i < tab_num; i++)
                {
                    Coder.arr_putc('\t', packet, ref packet_i);
                }
                Coder.arr_putc('}', packet, ref packet_i);

                if (tab_num == 0)
                {
                    packet_size   = this.packet_i;
                    this.packet_i = 0;
                    this.info_i   = 0;
                    this.in_i     = 0;
                }

                break;

            case jsmntype_t.JSMN_ARRAY:
                son = info.sons[info_i];
                Coder.arr_putc('[', packet, ref packet_i);
                for (i = 0; i < son; i++)
                {
                    info_i++;
                    build_packet(input, info, packet, tab_num + 1);
                    if (i != son - 1)
                    {
                        Coder.arr_putc(',', packet, ref packet_i);
                    }
                }
                Coder.arr_putc('\n', packet, ref packet_i);
                for (i = 0; i < tab_num; i++)
                {
                    Coder.arr_putc('\t', packet, ref packet_i);
                }
                Coder.arr_putc(']', packet, ref packet_i);
                break;

            default:
                if (info.sons[info_i] == 1)
                {
                    Coder.arr_putc(':', packet, ref packet_i);
                    if (info.types[info_i + 1] == jsmntype_t.JSMN_OBJECT || info.types[info_i + 1] == jsmntype_t.JSMN_ARRAY)
                    {
                        info_i++;
                        build_packet(input, info, packet, tab_num);
                    }
                    else
                    {
                        Coder.in_arr_puts(input, ref in_i, packet, ref packet_i);
                        info_i++;
                    }
                }
                break;
            }
            return(packet_size);
        }
Exemplo n.º 3
0
        private void build_decoded(char[] input, ref int data_in_i, token_info info, ref JsonData jsonData, int tab_num)
        {
            //static int decoded_i = 0, info_i = 0, in_i = 0;

            //char[] decoded, ref int decoded_len

            char[] decoded = jsonData.content;

            int i;
            int son;

            if (info_i == info.num)
            {
                return;
            }

            if (tab_num != 0)
            {
                Coder.arr_putc('\n', decoded, ref decoded_i);
            }

            for (i = 0; i < tab_num; i++)
            {
                Coder.arr_putc('\t', decoded, ref decoded_i);
            }

            if (info.name_lens[info_i] != 0)
            {
                Coder.arr_putc('"', decoded, ref decoded_i);
                Coder.arr_puts(info.names[info_i], decoded, ref decoded_i);
                Coder.arr_putc('"', decoded, ref decoded_i);
            }

            switch (info.types[info_i])
            {
            case jsmntype_t.JSMN_OBJECT:
                son = info.sons[info_i];
                Coder.arr_putc('{', decoded, ref decoded_i);
                for (i = 0; i < son; i++)
                {
                    info_i++;
                    this.build_decoded(input, ref data_in_i, info, ref jsonData, tab_num + 1);
                    if (i != son - 1)
                    {
                        Coder.arr_putc(',', decoded, ref decoded_i);
                    }
                }
                Coder.arr_putc('\n', decoded, ref decoded_i);
                for (i = 0; i < tab_num; i++)
                {
                    Coder.arr_putc('\t', decoded, ref decoded_i);
                }
                Coder.arr_putc('}', decoded, ref decoded_i);
                if (tab_num == 0)
                {
                    jsonData.content_size = decoded_i;
                    data_in_i             = in_i;
                    decoded_i             = 0;
                    info_i = 0;
                    in_i   = 0;
                }
                break;

            case jsmntype_t.JSMN_ARRAY:
                son = info.sons[info_i];
                Coder.arr_putc('[', decoded, ref decoded_i);
                for (i = 0; i < son; i++)
                {
                    info_i++;
                    build_decoded(input, ref data_in_i, info, ref jsonData, tab_num + 1);
                    if (i != son - 1)
                    {
                        Coder.arr_putc(',', decoded, ref decoded_i);
                    }
                }
                Coder.arr_putc('\n', decoded, ref decoded_i);
                for (i = 0; i < tab_num; i++)
                {
                    Coder.arr_putc('\t', decoded, ref decoded_i);
                }
                Coder.arr_putc(']', decoded, ref decoded_i);
                break;

            default:
                if (info.sons[info_i] == 1)
                {
                    Coder.arr_putc(':', decoded, ref decoded_i);
                    if (info.types[info_i + 1] == jsmntype_t.JSMN_OBJECT || info.types[info_i + 1] == jsmntype_t.JSMN_ARRAY)
                    {
                        info_i++;
                        build_decoded(input, ref data_in_i, info, ref jsonData, tab_num);
                    }
                    else
                    {
                        if (jsFileParser.strcmp(info.names[info_i], "Data\0".ToCharArray()) == 0)
                        {
                            Coder.arr_putc('0', decoded, ref decoded_i);
                        }
                        else
                        {
                            in_arr_puts(input, ref in_i, decoded, ref decoded_i);
                        }
                        info_i++;
                    }
                }
                break;
            }
            return;
        }