Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
alexandria
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Knut Olav Bøhmer
alexandria
Commits
06a3725d
Commit
06a3725d
authored
Oct 27, 2016
by
Jan Moringen
Committed by
Attila Lendvai
Oct 27, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix STARTS-WITH-SUBSEQ for non-array sequences
parent
926a0666
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
19 deletions
+46
-19
sequences.lisp
sequences.lisp
+31
-19
tests.lisp
tests.lisp
+15
-0
No files found.
sequences.lisp
View file @
06a3725d
...
@@ -300,28 +300,40 @@ sequence, is an empty sequence, or if OBJECT cannot be stored in SEQUENCE."
...
@@ -300,28 +300,40 @@ sequence, is an empty sequence, or if OBJECT cannot be stored in SEQUENCE."
"Test whether the first elements of SEQUENCE are the same (as per TEST) as the elements of PREFIX.
"Test whether the first elements of SEQUENCE are the same (as per TEST) as the elements of PREFIX.
If RETURN-SUFFIX is T the function returns, as a second value, a
If RETURN-SUFFIX is T the function returns, as a second value, a
displaced array pointing to the sequence after PREFIX."
sub-sequence or
displaced array pointing to the sequence after PREFIX."
(
declare
(
dynamic-extent
args
))
(
declare
(
dynamic-extent
args
))
(
let
((
sequence-length
(
length
sequence
))
(
let
((
sequence-length
(
length
sequence
))
(
prefix-length
(
length
prefix
)))
(
prefix-length
(
length
prefix
)))
(
if
(
<=
prefix-length
sequence-length
)
(
when
(
<
sequence-length
prefix-length
)
(
let
((
mismatch
(
apply
#'
mismatch
prefix
sequence
(
return-from
starts-with-subseq
(
values
nil
nil
)))
(
if
return-suffix-supplied-p
(
flet
((
make-suffix
(
start
)
(
remove-from-plist
args
:return-suffix
)
(
when
return-suffix
args
))))
(
cond
(
if
mismatch
((
not
(
arrayp
sequence
))
(
if
(
<
mismatch
prefix-length
)
(
if
start
(
values
nil
nil
)
(
subseq
sequence
start
)
(
values
t
(
when
return-suffix
(
subseq
sequence
0
0
)))
(
make-array
(
-
sequence-length
mismatch
)
((
not
start
)
:element-type
(
array-element-type
sequence
)
(
make-array
0
:displaced-to
sequence
:element-type
(
array-element-type
sequence
)
:displaced-index-offset
prefix-length
:adjustable
nil
))
:adjustable
nil
))))
(
t
(
values
t
(
when
return-suffix
(
make-array
(
-
sequence-length
start
)
(
make-array
0
:element-type
(
array-element-type
sequence
)
:element-type
(
array-element-type
sequence
)
:adjustable
nil
)))))
:displaced-to
sequence
(
values
nil
nil
))))
:displaced-index-offset
start
:adjustable
nil
))))))
(
let
((
mismatch
(
apply
#'
mismatch
prefix
sequence
(
if
return-suffix-supplied-p
(
remove-from-plist
args
:return-suffix
)
args
))))
(
cond
((
not
mismatch
)
(
values
t
(
make-suffix
nil
)))
((
=
mismatch
prefix-length
)
(
values
t
(
make-suffix
mismatch
)))
(
t
(
values
nil
nil
)))))))
(
defun
ends-with-subseq
(
suffix
sequence
&key
(
test
#'
eql
))
(
defun
ends-with-subseq
(
suffix
sequence
&key
(
test
#'
eql
))
"Test whether SEQUENCE ends with SUFFIX. In other words: return true if
"Test whether SEQUENCE ends with SUFFIX. In other words: return true if
...
...
tests.lisp
View file @
06a3725d
...
@@ -1960,6 +1960,21 @@
...
@@ -1960,6 +1960,21 @@
n
)
n
)
13
)
13
)
(
deftest
starts-with-subseq.string
(
starts-with-subseq
"f"
"foo"
:return-suffix
t
)
t
"oo"
)
(
deftest
starts-with-subseq.vector
(
starts-with-subseq
#(
1
)
#(
1
2
3
)
:return-suffix
t
)
t
#(
2
3
))
(
deftest
starts-with-subseq.list
(
starts-with-subseq
'
(
1
)
'
(
1
2
3
)
:return-suffix
t
)
t
(
2
3
))
(
deftest
starts-with-subseq.start1
(
deftest
starts-with-subseq.start1
(
starts-with-subseq
"foo"
"oop"
:start1
1
)
(
starts-with-subseq
"foo"
"oop"
:start1
1
)
t
t
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment