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
157ddcba
Commit
157ddcba
authored
Feb 15, 2021
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
protocol/RangeArg: add methods ClipRelaxed(), CheckClip(), CheckAdjustEnd()
parent
ab160aa3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
0 deletions
+50
-0
RangeArg.hxx
src/protocol/RangeArg.hxx
+50
-0
No files found.
src/protocol/RangeArg.hxx
View file @
157ddcba
...
...
@@ -90,6 +90,56 @@ struct RangeArg {
constexpr
unsigned
Count
()
const
noexcept
{
return
end
-
start
;
}
/**
* Make sure that both start and end are within the given
* count.
*/
constexpr
void
ClipRelaxed
(
unsigned
count
)
noexcept
{
if
(
end
>
count
)
end
=
count
;
if
(
start
>
end
)
start
=
end
;
}
/**
* Check if the start index is valid and clip the end of the
* range.
*
* @return false if the start is out of range
*/
[[
nodiscard
]]
constexpr
bool
CheckClip
(
unsigned
count
)
noexcept
{
if
(
start
>
count
)
return
false
;
if
(
end
>
count
)
end
=
count
;
return
true
;
}
/**
* Check if start and end index are valid and adjust the end if this
* is an open-ended range.
*
* @return false if start or end is out of range
*/
[[
nodiscard
]]
constexpr
bool
CheckAdjustEnd
(
unsigned
count
)
noexcept
{
if
(
start
>
count
)
return
false
;
if
(
end
>
count
)
{
if
(
!
IsOpenEnded
())
return
false
;
end
=
count
;
}
return
true
;
}
};
#endif
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