~ubuntu-branches/debian/sid/f-spot/sid

« back to all changes in this revision

Viewing changes to lib/Hyena/src/Hyena/Hyena.Json/Deserializer.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2010-05-24 10:35:57 UTC
  • mfrom: (2.4.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20100524103557-1j0i8f66caybci2n
* New upstream release 0.7.0
 + First release of the unstable 0.7 development series. Massive changes.
 + Reparenting and detaching support (Anton Keks) (Closes: #559745)
 + A new Mallard-based documentation (Harold Schreckengost)
 + No longer embeds flickrnet, uses distribution copy (Iain Lane)
 + Adoption of a large amount of Hyena functionality (Paul Lange, Peter
   Goetz)
 + No longer embeds gnome-keyring-sharp
 + Completely rewritten import, much faster and less memory hungry (Ruben
   Vermeersch) (Closes: #559080, #492658, #341790, #357811, #426017) (LP:
   #412091)
 + No longer use gphoto2-sharp, now uses gvfs which is less crash-pron
   (Ruben Vermeersch)
 + Fix Facebook support (Ruben Vermeersch)
 + Modernized unit tests
 + Revamped build (Mike Gemünde)
 + Much improved duplicate detection (much faster too) (Ruben Vermeersch)
 + Mouse selection in Iconview (Vincent Pomey)
 + Image panning support using middle mouse button (Wojciech Dzierżanowski)
 + Timeline slider now restricted to the size of the window (Iain Churcher)
 + Over 100 bugs closed (http://bit.ly/cyVjnD)
   - No more warnings about schema defaults (Closes: #584215) (LP: #586132)
* debian/control: Clean up build deps to match configure checks
* debian/rules: Don't run dh_makeshilbs as we don't ship any shared
  libraries. There are some private ones though, which get picked up and
  result in a useless postinst/postrm call to ldconfig. Thanks, lintian.
* debian/patches/debian_fix-distclean.patch,
  debian/patches/debian_fix_f-spot.exe.config.patch,
  debian/patches/debian_link-system-flickrnet.patch,
  debian/patches/debian_link-system-gnome-keyring.patch,
  debian/patches/debian_disable-unit-tests,
  debian/patches/git_transition_duration.patch,
  debian/patches/ubuntu_fix_folder_export_hang.patch:
  Clean up obsolete patches which are no longer necessary 
* debian/patches/*: Temporarily disable patches which originated from Ubuntu
  and no longer apply cleanly. We will get these back in a future upstream
  development release.
* debian/patches/*: Refresh to apply cleanly 
* debian/rules: Add new include dir to autoreconf call to pick up f-spot
  macros 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Deserializer.cs
 
3
//
 
4
// Author:
 
5
//   Aaron Bockover <abockover@novell.com>
 
6
//
 
7
// Copyright (C) 2008 Novell, Inc.
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining
 
10
// a copy of this software and associated documentation files (the
 
11
// "Software"), to deal in the Software without restriction, including
 
12
// without limitation the rights to use, copy, modify, merge, publish,
 
13
// distribute, sublicense, and/or sell copies of the Software, and to
 
14
// permit persons to whom the Software is furnished to do so, subject to
 
15
// the following conditions:
 
16
//
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
//
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
//
 
28
 
 
29
using System;
 
30
using System.IO;
 
31
 
 
32
namespace Hyena.Json
 
33
{
 
34
    public class Deserializer
 
35
    {
 
36
        private Tokenizer tokenizer = new Tokenizer ();
 
37
 
 
38
        public Deserializer () { }
 
39
        public Deserializer (string input) { SetInput (input); }
 
40
        public Deserializer (Stream stream) { SetInput (stream); }
 
41
        public Deserializer (StreamReader reader) { SetInput (reader); }
 
42
 
 
43
        public Deserializer SetInput (StreamReader reader)
 
44
        {
 
45
            tokenizer.SetInput (reader);
 
46
            return this;
 
47
        }
 
48
 
 
49
        public Deserializer SetInput (Stream stream)
 
50
        {
 
51
            tokenizer.SetInput (stream);
 
52
            return this;
 
53
        }
 
54
 
 
55
        public Deserializer SetInput (string input)
 
56
        {
 
57
            tokenizer.SetInput (input);
 
58
            return this;
 
59
        }
 
60
 
 
61
        public object Deserialize ()
 
62
        {
 
63
            Token token = CheckScan (TokenType.Value, true);
 
64
            if (token == null) {
 
65
                return null;
 
66
            }
 
67
 
 
68
            return Parse (token);
 
69
        }
 
70
 
 
71
        private object Parse (Token token)
 
72
        {
 
73
            if (token.Type == TokenType.ObjectStart) {
 
74
                return ParseObject ();
 
75
            } else if (token.Type == TokenType.ArrayStart) {
 
76
                return ParseArray ();
 
77
            }
 
78
 
 
79
            return token.Value;
 
80
        }
 
81
 
 
82
        private JsonObject ParseObject ()
 
83
        {
 
84
            JsonObject obj = new JsonObject ();
 
85
 
 
86
            while (true) {
 
87
                Token key = CheckScan (TokenType.String | TokenType.ObjectFinish);
 
88
                if (key.Type == TokenType.ObjectFinish) {
 
89
                    break;
 
90
                }
 
91
 
 
92
                CheckScan (TokenType.Colon);
 
93
                Token value = CheckScan (TokenType.Value);
 
94
 
 
95
                object value_val = value.Value;
 
96
                if (value.Type == TokenType.ArrayStart) {
 
97
                    value_val = ParseArray ();
 
98
                } else if (value.Type == TokenType.ObjectStart) {
 
99
                    value_val = ParseObject ();
 
100
                }
 
101
 
 
102
                obj.Add ((string)key.Value, value_val);
 
103
 
 
104
                Token token = CheckScan (TokenType.Comma | TokenType.ObjectFinish);
 
105
                if (token.Type == TokenType.ObjectFinish) {
 
106
                     break;
 
107
                }
 
108
            }
 
109
 
 
110
            return obj;
 
111
        }
 
112
 
 
113
        private JsonArray ParseArray ()
 
114
        {
 
115
            JsonArray array = new JsonArray ();
 
116
 
 
117
            while (true) {
 
118
                Token value = CheckScan (TokenType.Value | TokenType.ArrayFinish);
 
119
                if (value.Type == TokenType.ArrayFinish) {
 
120
                    break;
 
121
                }
 
122
 
 
123
                array.Add (Parse (value));
 
124
 
 
125
                Token token = CheckScan (TokenType.Comma | TokenType.ArrayFinish);
 
126
                if (token.Type == TokenType.ArrayFinish) {
 
127
                     break;
 
128
                }
 
129
            }
 
130
 
 
131
            return array;
 
132
        }
 
133
 
 
134
        private Token CheckScan (TokenType expected)
 
135
        {
 
136
            return CheckScan (expected, false);
 
137
        }
 
138
 
 
139
        private Token CheckScan (TokenType expected, bool eofok)
 
140
        {
 
141
            Token token = tokenizer.Scan ();
 
142
            if (token == null && eofok) {
 
143
                return null;
 
144
            } else if (token == null) {
 
145
                UnexpectedEof (expected);
 
146
            } else if ((expected & token.Type) == 0) {
 
147
                UnexpectedToken (expected, token);
 
148
            }
 
149
            return token;
 
150
        }
 
151
 
 
152
        private void UnexpectedToken (TokenType expected, Token got)
 
153
        {
 
154
            throw new ApplicationException (String.Format ("Unexpected token {0} at [{1}:{2}]; expected {3}",
 
155
                got.Type, got.SourceLine, got.SourceColumn, expected));
 
156
        }
 
157
 
 
158
        private void UnexpectedEof (TokenType expected)
 
159
        {
 
160
            throw new ApplicationException (String.Format ("Unexpected End of File; expected {0}", expected));
 
161
        }
 
162
    }
 
163
}