Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mf
go-multiaddr-fmt
Commits
6ceb702e
Commit
6ceb702e
authored
Jan 18, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
a bit of cleanup
parent
8c6a494c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
10 deletions
+10
-10
patterns.go
patterns.go
+9
-9
patterns_test.go
patterns_test.go
+1
-1
No files found.
patterns.go
View file @
6ceb702e
package
bnf
package
mafmt
import
(
"strings"
...
...
@@ -14,20 +14,20 @@ var Reliable = Or(TCP, UTP)
var
IPFS
=
And
(
Reliable
,
Base
(
ma
.
P_IPFS
))
const
(
OR
=
iota
AND
=
iota
or
=
iota
and
=
iota
)
func
And
(
ps
...
Pattern
)
Pattern
{
return
&
pattern
{
Op
:
AND
,
Op
:
and
,
Args
:
ps
,
}
}
func
Or
(
ps
...
Pattern
)
Pattern
{
return
&
pattern
{
Op
:
OR
,
Op
:
or
,
Args
:
ps
,
}
}
...
...
@@ -50,7 +50,7 @@ func (ptrn *pattern) Matches(a ma.Multiaddr) bool {
func
(
ptrn
*
pattern
)
partialMatch
(
pcs
[]
ma
.
Protocol
)
(
bool
,
[]
ma
.
Protocol
)
{
switch
ptrn
.
Op
{
case
OR
:
case
or
:
for
_
,
a
:=
range
ptrn
.
Args
{
ok
,
rem
:=
a
.
partialMatch
(
pcs
)
if
ok
{
...
...
@@ -58,7 +58,7 @@ func (ptrn *pattern) partialMatch(pcs []ma.Protocol) (bool, []ma.Protocol) {
}
}
return
false
,
nil
case
AND
:
case
and
:
if
len
(
pcs
)
<
len
(
ptrn
.
Args
)
{
return
false
,
nil
}
...
...
@@ -85,9 +85,9 @@ func (ptrn *pattern) String() string {
}
switch
ptrn
.
Op
{
case
AND
:
case
and
:
return
strings
.
Join
(
sub
,
"/"
)
case
OR
:
case
or
:
return
"{"
+
strings
.
Join
(
sub
,
"|"
)
+
"}"
default
:
panic
(
"unrecognized pattern op!"
)
...
...
patterns_test.go
View file @
6ceb702e
package
bnf
package
mafmt
import
(
"testing"
...
...
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