Skip to content

Commit

Permalink
Merge pull request #42 from vvcarvalho/main
Browse files Browse the repository at this point in the history
span: create 'substreams' from start to end bounds.
  • Loading branch information
Zulu-Inuoe authored Aug 19, 2023
2 parents 4e7de78 + d0d2246 commit 628ac48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,16 @@ This *may* help speed up parsing on highly heterogeneous JSON.

*=> span*

* *in* - a `string`, or `vector (unsigned-byte 8)`
* *in* - a `string`, `stream` ' or `vector (unsigned-byte 8)`
* *start, end* - bounding index designators of sequence. The defaults for *start* and *end* are 0 and nil, respectively.

*span* a span object representing the range.

#### Description

Create a span to be used in [`jzon:parse`](#jzonparse), or [`jzon:make-parser`](#jzonparser) in order to specify a bounded *start* and *end* for a string or vector.
Create a span to be used in [`jzon:parse`](#jzonparse), or [`jzon:make-parser`](#jzonparser) in order to specify a bounded *start* and *end* for a string, stream or vector.

NOTE: For streams, only input streams are allowed.

##### Example

Expand Down
10 changes: 9 additions & 1 deletion src/jzon.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,15 @@ see `close-parser'"
(end (or end (length in))))
(unless (<= 0 start end (length in))
(error "The bounding indices ~A and ~A are bad for a sequence of length ~A." start end (length in)))
(make-instance '%octet-vector-span :vector in :start start :end end)))))
(make-instance '%octet-vector-span :vector in :start start :end end)))
(stream
(let ((start start)
(end (or end (file-length in))))
(unless (<= 0 start end (file-length in))
(error "The bounding indices ~A and ~A are bad for a stream of length ~A." start end (file-length in)))
(unless (input-stream-p in)
(error "The stream ~A is not an input stream." in))
(flexi-streams:make-flexi-stream in :element-type (stream-element-type in) :position start :bound end)))))

(defun parse (in &key
(max-depth 128)
Expand Down

0 comments on commit 628ac48

Please sign in to comment.