Tcl Library Source Code

Check-in [1c1271bd98]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fixed buglets which slipped through in previous commit.
Timelines: family | ancestors | descendants | both | ak-bug-6efa4f571af052-jsonc
Files: files | file ages | folders
SHA1: 1c1271bd984b760256c1309a904eb40f4f43e167
User & Date: andreask 2013-12-11 22:25:32
Context
2013-12-11
22:26
Small test simplification check-in: 942a650535 user: andreask tags: ak-bug-6efa4f571af052-jsonc
22:25
Fixed buglets which slipped through in previous commit. check-in: 1c1271bd98 user: andreask tags: ak-bug-6efa4f571af052-jsonc
21:07
Moved the larger test cases and data into separate files, less quoting that way. Added test case for the escape-able characters. Added test cases for invalid json. Shifted the json generating procedures to the common file, making them shared between Tcl and C implementations. Added a benchmark suite, using the test cases in the files as input. check-in: af6919a548 user: andreask tags: ak-bug-6efa4f571af052-jsonc
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to modules/json/json_tcl.tcl.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#   $Id: json.tcl,v 1.7 2011/11/10 21:05:58 andreas_kupries Exp $
#

if {![package vsatisfies [package provide Tcl] 8.5]} {
    package require dict
}

namespace eval json {
    # Regular expression for tokenizing a JSON text (cf. http://json.org/)

    # tokens consisting of a single character
    variable singleCharTokens { "{" "}" ":" "\\[" "\\]" "," }
    variable singleCharTokenRE "\[[join $singleCharTokens {}]\]"

    # quoted string tokens






|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#   $Id: json.tcl,v 1.7 2011/11/10 21:05:58 andreas_kupries Exp $
#

if {![package vsatisfies [package provide Tcl] 8.5]} {
    package require dict
}

namespace eval ::json {
    # Regular expression for tokenizing a JSON text (cf. http://json.org/)

    # tokens consisting of a single character
    variable singleCharTokens { "{" "}" ":" "\\[" "\\]" "," }
    variable singleCharTokenRE "\[[join $singleCharTokens {}]\]"

    # quoted string tokens

Changes to modules/json/jsonc.tcl.

348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
...
363
364
365
366
367
368
369
370
371
372
373
	while (1) {
	    parsed = json_tokener_parse_ex(tok, text, len);

	    /* parse error, abort, not valid */
	    if (parsed == NULL) {
		json_tokener_free(tok);
		Tcl_SetObjResult(I, Tcl_NewBooleanObj (0));
		return TCL_ERROR;
	    }
	    json_object_put(parsed);

	    /* Abort if we have consumed all input */
	    if (tok->char_offset >= len) break;

	    /* Skip over consumed text for next parse */
................................................................................
	    text += tok->char_offset;
	    len  -= tok->char_offset;
	}

	json_tokener_free(tok);

	/* We are good and done */
	Tcl_SetObjResult(I, Tcl_NewBooleanObj (0));
	return TCL_OK;
    }
}






|







 







|



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
...
363
364
365
366
367
368
369
370
371
372
373
	while (1) {
	    parsed = json_tokener_parse_ex(tok, text, len);

	    /* parse error, abort, not valid */
	    if (parsed == NULL) {
		json_tokener_free(tok);
		Tcl_SetObjResult(I, Tcl_NewBooleanObj (0));
		return TCL_OK;
	    }
	    json_object_put(parsed);

	    /* Abort if we have consumed all input */
	    if (tok->char_offset >= len) break;

	    /* Skip over consumed text for next parse */
................................................................................
	    text += tok->char_offset;
	    len  -= tok->char_offset;
	}

	json_tokener_free(tok);

	/* We are good and done */
	Tcl_SetObjResult(I, Tcl_NewBooleanObj (1));
	return TCL_OK;
    }
}