Exemple #1
0
        public static dynamic GetValue(this JyndData data, JyndItem item)
        {
            switch (data.Source[item.Data])
            {
            case '"':
                return(data.GetText(item));

            case '{':
                return(data.GetObject(item));

            case '[':
                return(data.GetArray(item));

            case 'n':
                return(data.GetNull(item));

            case 't':
                return(data.GetTrue(item));

            case 'f':
                return(data.GetFalse(item));

            default:
                return(data.GetNumber(item));
            }
        }
Exemple #2
0
 public void AddItem(short indexInstance, ushort data, short dataLength, short dataInstance)
 {
     items[count++] = new JyndItem
     {
         IndexInstance = indexInstance,
         Data          = data,
         DataLength    = dataLength,
         DataInstance  = dataInstance
     };
 }
Exemple #3
0
        public void AddIndexed(ushort index, byte indexLength, short indexInstance, ushort data, short dataLength, short dataInstance)
        {
            ushort hash = ToHash(source, index, indexLength);

            hashes[hash]   = (short)count;
            items[count++] = new JyndItem
            {
                Hash          = hash,
                Index         = index,
                IndexLength   = indexLength,
                IndexInstance = indexInstance,
                Data          = data,
                DataLength    = dataLength,
                DataInstance  = dataInstance
            };
        }
Exemple #4
0
        public static unsafe dynamic GetBigIntegerOrNull(this JyndData data, JyndItem item)
        {
            if (data.Source[item.Data] == 'n')
            {
                return(data.GetNull(item));

                fixed(char *ptr = data.Source)
                {
                    char *str    = ptr + item.Data;
                    int   length = item.DataLength;
                    bool  signed = *str == '-';

                    if (signed)
                    {
                        length--;
                        str++;
                    }

                    return(GetNumberAsBigInteger(str, item, signed, length));
                }
        }
Exemple #5
0
 public static bool IsObject(this JyndData data, JyndItem item)
 {
     return(data.Source[item.Data] == '{');
 }
Exemple #6
0
 private static dynamic GetNumber(this JyndData data, JyndItem item)
 {
     if (item.DataLength > 0)
         return(GetNumberAsIntegralType(data, item)); }
Exemple #7
0
 private static JyndArray GetArray(this JyndData data, JyndItem item)
 {
     return(new JyndArray(data, item.DataInstance));
 }
Exemple #8
0
 private static JyndObject GetObject(this JyndData data, JyndItem item)
 {
     return(new JyndObject(data, item.DataInstance));
 }
Exemple #9
0
 private static bool GetFalse(this JyndData data, JyndItem item)
 {
     return(false);
 }
Exemple #10
0
 private static bool GetTrue(this JyndData data, JyndItem item)
 {
     return(true);
 }
Exemple #11
0
 private static object GetNull(this JyndData data, JyndItem item)
 {
     return(null);
 }
Exemple #12
0
 public static bool IsArray(this JyndData data, JyndItem item)
 {
     return(data.Source[item.Data] == '[');
 }
Exemple #13
0
        private static string GetText(this JyndData data, JyndItem item)
        {
            if (item.DataLength > 0)
            {
                return(data.Source.Substring(item.Data + 1, item.DataLength - 2));
            }

            StringBuilder builder = new StringBuilder();
            int           end     = item.Data - item.DataLength - 1;
            int           start   = item.Data + 1;

            for (int i = start; i < end; i++)
            {
                if (data.Source[i] == '\\')
                {
                    builder.Append(data.Source, start, i - start);
                    i++;

                    switch (data.Source[i])
                    {
                    case 'u':

                        int number = 0;
                        i++;

                        for (int k = i; k < i + 4; k++)
                        {
                            if (data.Source[k] <= '9')
                            {
                                number = number * 16 + data.Source[k] - '0';
                            }
                            else if (data.Source[k] <= 'f')
                            {
                                number = number * 16 + data.Source[k] - 'a' + 10;
                            }
                            else
                            {
                                number = number * 16 + data.Source[k] - 'A' + 10;
                            }
                        }

                        builder.Append((char)number);
                        i += 3;
                        break;

                    case '"':
                        builder.Append('"');
                        break;

                    case '\\':
                        builder.Append('\\');
                        break;

                    case '/':
                        builder.Append('/');
                        break;

                    case 'b':
                        builder.Append('\b');
                        break;

                    case 'f':
                        builder.Append('\f');
                        break;

                    case 'n':
                        builder.Append('\n');
                        break;

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

                    case 't':
                        builder.Append('\t');
                        break;
                    }

                    start = i + 1;
                }
            }

            if (start != item.Data + 1)
            {
                builder.Append(data.Source, start, end - start);
            }

            return(builder.ToString());
        }