private void ReadProperties(PsdReader reader, int level, Properties props)
 {
     reader.Skip('\t', level);
     char c = reader.ReadChar();
     if (c == ']')
     {
         return;
     }
     else if (c == '<')
     {
         reader.Skip('<');
     }
     reader.Skip('\n');
     //Properties props = new Properties();
     while (true)
     {
         reader.Skip('\t', level);
         c = reader.ReadChar();
         if (c == '>')
         {
             reader.Skip('>');
             return;
         }
         else
         {
             //assert c == 9;
             c = reader.ReadChar();
             //assert c == '/' : "unknown char: " + c + " on level: " + level;
             string name = string.Empty;
             while (true)
             {
                 c = reader.ReadChar();
                 if (c == ' ' || c == 10)
                 {
                     break;
                 }
                 name += c;
             }
             if (c == 10)
             {
                 Properties p = new Properties();
                 this.ReadProperties(reader, level + 1, p);
                 if (p.Count > 0)
                     props.Add(name, p);
                 reader.Skip('\n');
             }
             else if (c == ' ')
             {
                 object value = this.ReadValue(reader, level + 1);
                 props.Add(name, value);
             }
             else
             {
                 //assert false;
             }
         }
     }
 }
Exemple #2
0
        private object ReadValue(PsdReader reader, int level)
        {
            char c = reader.ReadChar();

            if (c == ']')
            {
                return(null);
            }
            else if (c == '(')
            {
                // unicode string
                string text            = string.Empty;
                int    stringSignature = reader.ReadInt16() & 0xFFFF;
                //assert stringSignature == 0xFEFF;
                while (true)
                {
                    char b1 = reader.ReadChar();
                    if (b1 == ')')
                    {
                        reader.Skip('\n');
                        return(text);
                    }
                    char b2 = reader.ReadChar();
                    if (b2 == '\\')
                    {
                        b2 = reader.ReadChar();
                    }
                    if (b2 == 13)
                    {
                        text += '\n';
                    }
                    else
                    {
                        text += (char)((b1 << 8) | b2);
                    }
                }
            }
            else if (c == '[')
            {
                ArrayList list = new ArrayList();
                // array
                c = reader.ReadChar();
                while (true)
                {
                    if (c == ' ')
                    {
                        object val = this.ReadValue(reader, level);
                        if (val == null)
                        {
                            reader.Skip('\n');
                            return(list);
                        }
                        else
                        {
                            list.Add(val);
                        }
                    }
                    else if (c == 10)
                    {
                        Properties p = new Properties();
                        this.ReadProperties(reader, level, p);
                        reader.Skip('\n');
                        if (p.Count == 0)
                        {
                            return(list);
                        }
                        else
                        {
                            list.Add(p);
                        }
                    }
                    else
                    {
                        //assert false;
                    }
                }
            }
            else
            {
                string value = string.Empty;
                do
                {
                    value += c;
                    c      = reader.ReadChar();
                }while (c != 10 && c != ' ');

                {
                    int f;
                    if (int.TryParse(value, out f) == true)
                    {
                        return(f);
                    }
                }
                {
                    float f;
                    if (float.TryParse(value, out f) == true)
                    {
                        return(f);
                    }
                }
                {
                    bool f;
                    if (bool.TryParse(value, out f) == true)
                    {
                        return(f);
                    }
                }

                return(value);
            }
        }
Exemple #3
0
        private void ReadProperties(PsdReader reader, int level, Properties props)
        {
            reader.Skip('\t', level);
            char c = reader.ReadChar();

            if (c == ']')
            {
                return;
            }
            else if (c == '<')
            {
                reader.Skip('<');
            }
            reader.Skip('\n');
            //Properties props = new Properties();
            while (true)
            {
                reader.Skip('\t', level);
                c = reader.ReadChar();
                if (c == '>')
                {
                    reader.Skip('>');
                    return;
                }
                else
                {
                    //assert c == 9;
                    c = reader.ReadChar();
                    //assert c == '/' : "unknown char: " + c + " on level: " + level;
                    string name = string.Empty;
                    while (true)
                    {
                        c = reader.ReadChar();
                        if (c == ' ' || c == 10)
                        {
                            break;
                        }
                        name += c;
                    }
                    if (c == 10)
                    {
                        Properties p = new Properties();
                        this.ReadProperties(reader, level + 1, p);
                        if (p.Count > 0)
                        {
                            props.Add(name, p);
                        }
                        reader.Skip('\n');
                    }
                    else if (c == ' ')
                    {
                        object value = this.ReadValue(reader, level + 1);
                        props.Add(name, value);
                    }
                    else
                    {
                        //assert false;
                    }
                }
            }
        }
        private object ReadValue(PsdReader reader, int level)
        {
            char c = reader.ReadChar();
            if (c == ']')
            {
                return null;
            }
            else if (c == '(')
            {
                // unicode string
                string text = string.Empty;
                int stringSignature = reader.ReadInt16() & 0xFFFF;
                //assert stringSignature == 0xFEFF;
                while (true)
                {
                    char b1 = reader.ReadChar();
                    if (b1 == ')')
                    {
                        reader.Skip('\n');
                        return text;
                    }
                    char b2 = reader.ReadChar();
                    if (b2 == '\\')
                    {
                        b2 = reader.ReadChar();
                    }
                    if (b2 == 13)
                    {
                        text += '\n';
                    }
                    else
                    {
                        text += (char)((b1 << 8) | b2);
                    }
                }
            }
            else if (c == '[')
            {
                ArrayList list = new ArrayList();
                // array
                c = reader.ReadChar();
                while (true)
                {
                    if (c == ' ')
                    {
                        object val = this.ReadValue(reader, level);
                        if (val == null)
                        {
                            reader.Skip('\n');
                            return list;
                        }
                        else
                        {
                            list.Add(val);
                        }
                    }
                    else if (c == 10)
                    {
                        Properties p = new Properties();
                        this.ReadProperties(reader, level, p);
                        reader.Skip('\n');
                        if (p.Count == 0)
                        {
                            return list;
                        }
                        else
                        {
                            list.Add(p);
                        }
                    }
                    else
                    {
                        //assert false;
                    }
                }
            }
            else
            {
                string value = string.Empty;
                do
                {
                    value += c;
                    c = reader.ReadChar();
                }
                while (c != 10 && c != ' ');

                {
                    int f;
                    if (int.TryParse(value, out f) == true)
                        return f;
                }
                {
                    float f;
                    if (float.TryParse(value, out f) == true)
                        return f;
                }
                {
                    bool f;
                    if (bool.TryParse(value, out f) == true)
                        return f;
                }

                return value;
            }
        }
Exemple #5
0
        private Object ReadValue(PsdReader reader, Int32 level)
        {
            Char c = reader.ReadChar();

            if (c == ']')
            {
                return(null);
            }
            else if (c == '(')
            {
                // unicode string
                String text            = String.Empty;
                Int32  stringSignature = reader.ReadInt16() & 0xFFFF;
                //assert stringSignature == 0xFEFF;
                while (true)
                {
                    Char b1 = reader.ReadChar();
                    if (b1 == ')')
                    {
                        reader.Skip('\n');
                        return(text);
                    }
                    Char b2 = reader.ReadChar();
                    if (b2 == '\\')
                    {
                        b2 = reader.ReadChar();
                    }
                    if (b2 == 13)
                    {
                        text += '\n';
                    }
                    else
                    {
                        text += (Char)((b1 << 8) | b2);
                    }
                }
            }
            else if (c == '[')
            {
                ArrayList list = new ArrayList();
                // array
                c = reader.ReadChar();
                while (true)
                {
                    if (c == ' ')
                    {
                        Object val = this.ReadValue(reader, level);
                        if (val == null)
                        {
                            reader.Skip('\n');
                            return(list);
                        }
                        else
                        {
                            list.Add(val);
                        }
                    }
                    else if (c == 10)
                    {
                        Properties p = new Properties();
                        this.ReadProperties(reader, level, p);
                        reader.Skip('\n');
                        if (p.Count == 0)
                        {
                            return(list);
                        }
                        else
                        {
                            list.Add(p);
                        }
                    }
                    else
                    {
                        //assert false;
                    }
                }
            }
            else
            {
                String value = String.Empty;
                do
                {
                    value += c;
                    c      = reader.ReadChar();
                }while (c != 10 && c != ' ');

                {
                    Int32 f;
                    if (Int32.TryParse(value, out f) == true)
                    {
                        return(f);
                    }
                }
                {
                    Single f;
                    if (Single.TryParse(value, out f) == true)
                    {
                        return(f);
                    }
                }
                {
                    Boolean f;
                    if (Boolean.TryParse(value, out f) == true)
                    {
                        return(f);
                    }
                }

                return(value);
            }
        }