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
P
parrot-av
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
Nong Hoang Tu
parrot-av
Commits
e74bc2ed
Commit
e74bc2ed
authored
Nov 13, 2020
by
dmknght
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add glob matching
parent
153077b2
Pipeline
#1422
failed with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
134 additions
and
0 deletions
+134
-0
src/fglob.nim
src/fglob.nim
+5
-0
src/glob_matching.c
src/glob_matching.c
+129
-0
No files found.
src/fglob.nim
0 → 100644
View file @
e74bc2ed
{.
compile
:
"glob_matching.c"
.}
proc
g_match
(
s
,
p
:
cstring
):
cint
{.
importc
.}
echo
g_match
(
"abcdef"
,
"bc"
)
\ No newline at end of file
src/glob_matching.c
0 → 100644
View file @
e74bc2ed
/*
* robust glob pattern matcher
* ozan s. yigit/dec 1994
* public domain
*
* glob patterns:
* * matches zero or more characters
* ? matches any single character
* [set] matches any character in the set
* [!set] matches any character NOT in the set
* where a set is a group of characters or ranges. a range
* is written as two characters seperated with a hyphen: a-z denotes
* all characters between a to z inclusive.
* [-set] set matches a literal hypen and any character in the set
* []set] matches a literal close bracket and any character in the set
*
* char matches itself except where char is '*' or '?' or '['
* \char matches char, including any pattern character
*
* examples:
* a*c ac abc abbc ...
* a?c acc abc aXc ...
* a[a-z]c aac abc acc ...
* a[-a-z]c a-c aac abc ...
*
*/
#ifndef NEGATE
#define NEGATE '!'
/* std cset negation char */
#endif
#define TRUE 1
#define FALSE 0
int
g_match
(
const
char
*
str
,
const
char
*
p
)
{
int
negate
;
int
match
;
int
c
;
while
(
*
p
)
{
if
(
!*
str
&&
*
p
!=
'*'
)
return
FALSE
;
switch
(
c
=
*
p
++
)
{
case
'*'
:
while
(
*
p
==
'*'
)
p
++
;
if
(
!*
p
)
return
TRUE
;
if
(
*
p
!=
'?'
&&
*
p
!=
'['
&&
*
p
!=
'\\'
)
while
(
*
str
&&
*
p
!=
*
str
)
str
++
;
while
(
*
str
)
{
if
(
g_match
(
str
,
p
))
return
TRUE
;
str
++
;
}
return
FALSE
;
case
'?'
:
if
(
*
str
)
break
;
return
FALSE
;
/*
* set specification is inclusive, that is [a-z] is a, z and
* everything in between. this means [z-a] may be interpreted
* as a set that contains z, a and nothing in between.
*/
case
'['
:
if
(
*
p
!=
NEGATE
)
negate
=
FALSE
;
else
{
negate
=
TRUE
;
p
++
;
}
match
=
FALSE
;
while
(
!
match
&&
(
c
=
*
p
++
))
{
if
(
!*
p
)
return
FALSE
;
if
(
*
p
==
'-'
)
{
/* c-c */
if
(
!*++
p
)
return
FALSE
;
if
(
*
p
!=
']'
)
{
if
(
*
str
==
c
||
*
str
==
*
p
||
(
*
str
>
c
&&
*
str
<
*
p
))
match
=
TRUE
;
}
else
{
/* c-] */
if
(
*
str
>=
c
)
match
=
TRUE
;
break
;
}
}
else
{
/* cc or c] */
if
(
c
==
*
str
)
match
=
TRUE
;
if
(
*
p
!=
']'
)
{
if
(
*
p
==
*
str
)
match
=
TRUE
;
}
else
break
;
}
}
if
(
negate
==
match
)
return
FALSE
;
/*
* if there is a match, skip past the cset and continue on
*/
while
(
*
p
&&
*
p
!=
']'
)
p
++
;
if
(
!*
p
++
)
/* oops! */
return
FALSE
;
break
;
}
str
++
;
}
return
!*
str
;
}
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