Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
olc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Byers
olc
Commits
d45a4388
Commit
d45a4388
authored
4 years ago
by
David Byers
Browse files
Options
Downloads
Plain Diff
Merge branch '6-allow-olc-is-valid-and-friends-recognize-compound-codes' into 'master'
Resolve "Allow olc-is-valid and friends recognize compound codes" Closes
#6
See merge request
!8
parents
941aca51
90c26599
No related branches found
Branches containing commit
Tags
1.3.0
Tags containing commit
1 merge request
!8
Resolve "Allow olc-is-valid and friends recognize compound codes"
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
CHANGELOG
+11
-0
11 additions, 0 deletions
CHANGELOG
olc.el
+52
-36
52 additions, 36 deletions
olc.el
olc.info
+22
-13
22 additions, 13 deletions
olc.info
olc.texi
+14
-6
14 additions, 6 deletions
olc.texi
test/olctest.el
+27
-0
27 additions, 0 deletions
test/olctest.el
with
126 additions
and
55 deletions
CHANGELOG
+
11
−
0
View file @
d45a4388
2020-07-25 David Byers <david.byers@liu.se>
Fix issue #6:
* olc.texi (Functions): Document "compound". Correct error in
documentation of return value for olc-is-full and olc-is-short.
* olc.el (olc-parse-code): Document that match data is changed.
(olc-is-valid): Added the "compound" keyword arg.
(olc-is-full): Added the "compound" keyword arg.
(olc-is-short): Added the "compound" keyword arg.
2020-07-24 David Byers <david.byers@liu.se>
Fix issue #4:
...
...
This diff is collapsed.
Click to expand it.
olc.el
+
52
−
36
View file @
d45a4388
...
...
@@ -3,7 +3,7 @@
;; Copyright (C) 2020 David Byers
;;
;; Author: David Byers <david.byers@liu.se>
;; Version: 1.
2
.0
;; Version: 1.
3
.0
;; Package-Requires: ((emacs "25.1"))
;; Keywords: extensions, lisp
;; URL: https://gitlab.liu.se/davby02/olc
...
...
@@ -247,7 +247,9 @@ raise, and args for the raised error.
(
/
(
expt
20
-3
)
(
expt
5
(
-
len
10
)))))
(
cl-defun
olc-parse-code
(
code
)
"Parse an open location code CODE."
"Parse an open location code CODE.
This function changes the match data."
(
if
(
olc-parse-p
code
)
code
(
cl-check-type
code
stringp
)
...
...
@@ -362,57 +364,71 @@ raise, and args for the raised error.
"Regular expression for parsing codes."
)
(
defun
olc-is-valid
(
code
)
"Return non-nil if CODE is a valid open location code."
(
or
(
olc-parse-p
code
)
(
save-match-data
(
let
((
case-fold-search
t
))
;; The code is decomposed into PAIRS PADDING "+" SUFFIX.
;;
;; Rules:
;;
;; - For all codes:
;; - Pairs has an even (zero counts) length of at most 8.
;; - Suffix is either zero or between 2 and 8 characters.
;; - One or both of pairs and suffix must not be empty.
;;
;; - If there is padding:
;; - The suffix must be empty
;; - The length of pairs and padding combined must be 8
(
when
(
string-match
olc-code-regexp
code
)
(
let
((
pair-len
(
-
(
match-end
1
)
(
match-beginning
1
)))
(
padd-len
(
-
(
match-end
2
)
(
match-beginning
2
)))
(
suff-len
(
-
(
match-end
3
)
(
match-beginning
3
))))
(
and
(
and
(
=
0
(
%
pair-len
2
))
(
<=
pair-len
8
))
; Check pairs
(
and
(
<=
suff-len
8
)
(
/=
suff-len
1
))
; Check suffix
(
>
(
+
pair-len
suff-len
)
0
)
; Check for not empty
(
or
(
=
padd-len
0
)
; Empty padding...
(
and
(
=
suff-len
0
)
; ...or suffix
(
=
(
+
padd-len
pair-len
)
8
))))))))))
(
defun
olc-is-short
(
code
)
(
cl-defun
olc-is-valid
(
code
&key
compound
)
"Return non-nil if CODE is a valid open location code.
If compound is non-nil, then return non-nil if CODE looks like a
compound open location code (i.e. everything up to the first
space character is a valid code)."
(
or
(
olc-parse-p
code
)
(
save-match-data
(
when
(
and
compound
(
string-match
" "
code
))
(
setq
code
(
substring
code
0
(
match-beginning
0
))))
(
let
((
case-fold-search
t
))
;; The code is decomposed into PAIRS PADDING "+" SUFFIX.
;;
;; Rules:
;;
;; - For all codes:
;; - Pairs has an even (zero counts) length of at most 8.
;; - Suffix is either zero or between 2 and 8 characters.
;; - One or both of pairs and suffix must not be empty.
;;
;; - If there is padding:
;; - The suffix must be empty
;; - The length of pairs and padding combined must be 8
(
when
(
string-match
olc-code-regexp
code
)
(
let
((
pair-len
(
-
(
match-end
1
)
(
match-beginning
1
)))
(
padd-len
(
-
(
match-end
2
)
(
match-beginning
2
)))
(
suff-len
(
-
(
match-end
3
)
(
match-beginning
3
))))
(
and
(
and
(
=
0
(
%
pair-len
2
))
(
<=
pair-len
8
))
; Check pairs
(
and
(
<=
suff-len
8
)
(
/=
suff-len
1
))
; Check suffix
(
>
(
+
pair-len
suff-len
)
0
)
; Check for not empty
(
or
(
=
padd-len
0
)
; Empty padding...
(
and
(
=
suff-len
0
)
; ...or suffix
(
=
(
+
padd-len
pair-len
)
8
))))))))))
(
cl-defun
olc-is-short
(
code
&key
compound
)
"Return non-nil if CODE is a valid short open location code.
If compound is non-nil, then return non-nil if CODE looks like a
compound open location code (i.e. everything up to the first
space character is a valid short code).
Note that nil means the code is either not short, or it is
invalid."
(
if
(
olc-parse-p
code
)
(
olc-parse-short
code
)
(
and
(
olc-is-valid
code
)
(
and
(
olc-is-valid
code
:compound
compound
)
(
or
(
<
(
length
code
)
9
)
(
and
(
>=
(
length
code
)
9
)
(
not
(
=
(
elt
code
8
)
?+
)))))))
(
defun
olc-is-full
(
code
)
(
cl-
defun
olc-is-full
(
code
&key
compound
)
"Return non-nil if CODE is a valid long open location code.
If compound is non-nil, then return non-nil if CODE looks like a
compound open location code (i.e. everything up to the first
space character is a valid short code).
Note that nil means the code is either not long, or it is
invalid."
(
if
(
olc-parse-p
code
)
(
not
(
olc-parse-short
code
))
(
and
(
olc-is-valid
code
)
(
and
(
olc-is-valid
code
:compound
compound
)
(
and
(
>=
(
length
code
)
9
)
(
=
(
elt
code
8
)
?+
)))))
...
...
This diff is collapsed.
Click to expand it.
olc.info
+
22
−
13
View file @
d45a4388
No preview for this file type
This diff is collapsed.
Click to expand it.
olc.texi
+
14
−
6
View file @
d45a4388
...
...
@@ -354,18 +354,26 @@ coordinates. Please make sure you follow the acceptable use policy for
the API (e.g., one request per second, tops, allowed).
@end defun
@defun olc-is-valid code
Returns non-@code
{
nil
}
if @var
{
code
}
is a valid open location code.
@defun olc-is-valid code
&
key compound
Returns non-@code
{
nil
}
if @var
{
code
}
is a valid open location code. If
@var
{
compound
}
is non-nil, then check only up to the first space
character so non-nil is returned for strings that look like compound
codes.
@end defun
@defun olc-is-short code
@defun olc-is-short code
&
key compound
Returns non-@code
{
nil
}
if @var
{
code
}
is a valid short location code.
Returns @code
{
nil
}
for valid short and for invalid codes.
If @var
{
compound
}
is non-nil, then check only up to the first space
character so non-nil is returned for strings that look like compound
codes. Returns @code
{
nil
}
for valid full and for invalid codes.
@end defun
@defun olc-is-full code
@defun olc-is-full code
&
key compound
Returns non-@code
{
nil
}
if @var
{
code
}
is a valid full open location
code. Returns @code
{
nil
}
for valid long and for invalid codes.
code. If @var
{
compound
}
is non-nil, then check only up to the first
space character so non-nil is returned for strings that look like
compound codes. Returns @code
{
nil
}
for valid short and for invalid
codes.
@end defun
...
...
This diff is collapsed.
Click to expand it.
test/olctest.el
+
27
−
0
View file @
d45a4388
...
...
@@ -511,6 +511,32 @@
:act
(
olc-nominatim-endpoint
"reverse"
)
:msg
"3"
))))
(
defun
olctest-issue-6
()
(
olctest-testcase
"issue-6"
(
olctest-equal
:exp
t
:act
(
olc-is-valid
"2222+"
))
(
olctest-equal
:exp
t
:act
(
olc-is-valid
"2222+"
:compound
t
))
(
olctest-equal
:exp
nil
:act
(
olc-is-valid
"2222+ Sweden"
))
(
olctest-equal
:exp
t
:act
(
olc-is-valid
"2222+ Sweden"
:compound
t
))
(
olctest-equal
:exp
t
:act
(
olc-is-short
"2222+"
))
(
olctest-equal
:exp
t
:act
(
olc-is-short
"2222+"
:compound
t
))
(
olctest-equal
:exp
nil
:act
(
olc-is-short
"2222+ Sweden"
))
(
olctest-equal
:exp
t
:act
(
olc-is-short
"2222+ Sweden"
:compound
t
))
(
olctest-equal
:exp
nil
:act
(
olc-is-short
"22222222+"
))
(
olctest-equal
:exp
nil
:act
(
olc-is-short
"22222222+"
:compound
t
))
(
olctest-equal
:exp
nil
:act
(
olc-is-short
"22222222+ Sweden"
))
(
olctest-equal
:exp
nil
:act
(
olc-is-short
"22222222+ Sweden"
:compound
t
))
(
olctest-equal
:exp
nil
:act
(
olc-is-full
"2222+"
))
(
olctest-equal
:exp
nil
:act
(
olc-is-full
"2222+"
:compound
t
))
(
olctest-equal
:exp
nil
:act
(
olc-is-full
"2222+ Sweden"
))
(
olctest-equal
:exp
nil
:act
(
olc-is-full
"2222+ Sweden"
:compound
t
))
(
olctest-equal
:exp
t
:act
(
olc-is-full
"22222222+"
))
(
olctest-equal
:exp
t
:act
(
olc-is-full
"22222222+"
:compound
t
))
(
olctest-equal
:exp
nil
:act
(
olc-is-full
"22222222+ Sweden"
))
(
olctest-equal
:exp
t
:act
(
olc-is-full
"22222222+ Sweden"
:compound
t
))
))
(
defvar
olctest-selected-tests
)
...
...
@@ -530,6 +556,7 @@
(
run-test
validity
)
(
run-test
localtests
)
(
run-test
errors
)
(
run-test
issue-6
)
(
run-test
issue-5
)
(
run-test
issue-3
)
(
run-test
issue-2
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment