aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-06-06 22:38:42 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-06-06 22:38:42 +0000
commitb60d64b001c8819e6626b00efbeae96560368a08 (patch)
tree5f4596a1a68c41d917a4aacb43b9804c2121158b /lib
parent6d2dee14f3d5d4224effd0ec2d8fbc07dc54cbac (diff)
downloadruby-b60d64b001c8819e6626b00efbeae96560368a08.tar.gz
* lib/json/common.rb: Ponder offering parse\! method.
* lib/json/editor.rb: be a bit more robust while loading data. * ext/json/ext/{generator,parser}/extconf.rb: add a have_header directive for st.h * test/json: fix some tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12456 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/json/common.rb18
-rw-r--r--lib/json/editor.rb26
2 files changed, 29 insertions, 15 deletions
diff --git a/lib/json/common.rb b/lib/json/common.rb
index c820cfbcce..0967aed8c2 100644
--- a/lib/json/common.rb
+++ b/lib/json/common.rb
@@ -101,11 +101,27 @@ module JSON
# _opts_ can have the following
# keys:
# * *max_nesting*: The maximum depth of nesting allowed in the parsed data
- # structures. Disable depth checking with :max_nesting => false.
+ # structures. Disable depth checking with :max_nesting => false. This value
+ # defaults to 19.
def parse(source, opts = {})
JSON.parser.new(source, opts).parse
end
+ # Parse the JSON string _source_ into a Ruby data structure and return it.
+ #
+ # _opts_ can have the following
+ # keys:
+ # * *max_nesting*: The maximum depth of nesting allowed in the parsed data
+ # structures. Enable depth checking with :max_nesting => anInteger. The parse!
+ # methods defaults to not doing max depth checking: This can be dangerous,
+ # if someone wants to fill up your stack.
+ def parse!(source, opts = {})
+ opts = {
+ :max_nesting => false
+ }.update(opts)
+ JSON.parser.new(source, opts).parse
+ end
+
# Unparse the Ruby data structure _obj_ into a single line JSON string and
# return it. _state_ is a JSON::State object, that can be used to configure
# the output further.
diff --git a/lib/json/editor.rb b/lib/json/editor.rb
index 063df69533..3dbcce5536 100644
--- a/lib/json/editor.rb
+++ b/lib/json/editor.rb
@@ -52,14 +52,12 @@ module JSON
MessageDialog::ERROR,
MessageDialog::BUTTONS_CLOSE, text)
dialog.show_all
- window.focus = dialog
dialog.run
rescue TypeError
dialog = MessageDialog.new(Editor.window, Dialog::MODAL,
MessageDialog::ERROR,
MessageDialog::BUTTONS_CLOSE, text)
dialog.show_all
- window.focus = dialog
dialog.run
ensure
dialog.destroy if dialog
@@ -73,7 +71,6 @@ module JSON
MessageDialog::QUESTION,
MessageDialog::BUTTONS_YES_NO, text)
dialog.show_all
- window.focus = dialog
dialog.run do |response|
return Gtk::Dialog::RESPONSE_YES === response
end
@@ -1102,9 +1099,11 @@ module JSON
# Quit this editor, that is, leave this editor's main loop.
def quit
ask_save if @changed
- destroy
- Gtk.main_quit
- true
+ if Gtk.main_level > 0
+ destroy
+ Gtk.main_quit
+ end
+ nil
end
# Display the new title according to the editor's current state.
@@ -1185,20 +1184,21 @@ module JSON
if filename
if File.directory?(filename)
Editor.error_dialog(self, "Try to select a JSON file!")
- return
+ nil
else
- data = read_data(filename)
@filename = filename
- toplevel.display_status("Loaded data from '#@filename'.")
+ if data = read_data(filename)
+ toplevel.display_status("Loaded data from '#@filename'.")
+ end
display_title
- return data
+ data
end
end
end
# Load the data at location _uri_ into the editor as a JSON document.
def load_location(uri)
- data = read_data(uri)
+ data = read_data(uri) or return
@filename = nil
toplevel.display_status("Loaded data from '#{uri}'.")
display_title
@@ -1217,11 +1217,9 @@ module JSON
end
return JSON::parse(json, :max_nesting => false)
end
- rescue JSON::JSONError => e
+ rescue => e
Editor.error_dialog(self, "Failed to parse JSON file: #{e}!")
return
- rescue SystemCallError => e
- quit
end
# Open a file selecton dialog, displaying _message_, and return the