Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
6c6947b0
Commit
6c6947b0
authored
Jan 08, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/UriUtil: add uri_get_path()
parent
78c91e9e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
0 deletions
+65
-0
UriUtil.cxx
src/util/UriUtil.cxx
+57
-0
UriUtil.hxx
src/util/UriUtil.hxx
+8
-0
No files found.
src/util/UriUtil.cxx
View file @
6c6947b0
...
...
@@ -19,10 +19,57 @@
#include "UriUtil.hxx"
#include "StringCompare.hxx"
#include "CharUtil.hxx"
#include <assert.h>
#include <string.h>
static
constexpr
bool
IsValidSchemeStart
(
char
ch
)
{
return
IsLowerAlphaASCII
(
ch
);
}
static
constexpr
bool
IsValidSchemeChar
(
char
ch
)
{
return
IsLowerAlphaASCII
(
ch
)
||
IsDigitASCII
(
ch
)
||
ch
==
'+'
||
ch
==
'.'
||
ch
==
'-'
;
}
gcc_pure
static
bool
IsValidScheme
(
StringView
p
)
{
if
(
p
.
IsEmpty
()
||
!
IsValidSchemeStart
(
p
.
front
()))
return
false
;
for
(
size_t
i
=
1
;
i
<
p
.
size
;
++
i
)
if
(
!
IsValidSchemeChar
(
p
[
i
]))
return
false
;
return
true
;
}
/**
* Return the URI part after the scheme specification (and after the
* double slash).
*/
gcc_pure
static
const
char
*
uri_after_scheme
(
const
char
*
uri
)
{
if
(
uri
[
0
]
==
'/'
&&
uri
[
1
]
==
'/'
&&
uri
[
2
]
!=
'/'
)
return
uri
+
2
;
const
char
*
colon
=
strchr
(
uri
,
':'
);
return
colon
!=
nullptr
&&
IsValidScheme
({
uri
,
colon
})
&&
colon
[
1
]
==
'/'
&&
colon
[
2
]
==
'/'
?
colon
+
3
:
nullptr
;
}
bool
uri_has_scheme
(
const
char
*
uri
)
{
return
strstr
(
uri
,
"://"
)
!=
nullptr
;
...
...
@@ -38,6 +85,16 @@ uri_get_scheme(const char *uri)
return
std
::
string
(
uri
,
end
);
}
const
char
*
uri_get_path
(
const
char
*
uri
)
{
const
char
*
ap
=
uri_after_scheme
(
uri
);
if
(
ap
!=
nullptr
)
return
strchr
(
ap
,
'/'
);
return
uri
;
}
/* suffixes should be ascii only characters */
const
char
*
uri_get_suffix
(
const
char
*
uri
)
...
...
src/util/UriUtil.hxx
View file @
6c6947b0
...
...
@@ -38,6 +38,14 @@ gcc_pure
std
::
string
uri_get_scheme
(
const
char
*
uri
);
/**
* Returns the URI path (including the query string) or nullptr if the
* given URI has no path.
*/
gcc_pure
gcc_nonnull_all
const
char
*
uri_get_path
(
const
char
*
uri
);
gcc_pure
const
char
*
uri_get_suffix
(
const
char
*
uri
);
...
...
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