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
af797033
Commit
af797033
authored
May 29, 2019
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config/Parser: get_bool() throws on error
parent
96a37da0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
32 deletions
+18
-32
Block.cxx
src/config/Block.cxx
+1
-7
Data.cxx
src/config/Data.cxx
+5
-13
Parser.cxx
src/config/Parser.cxx
+7
-10
Parser.hxx
src/config/Parser.hxx
+5
-2
No files found.
src/config/Block.cxx
View file @
af797033
...
...
@@ -75,13 +75,7 @@ BlockParam::GetPositiveValue() const
bool
BlockParam
::
GetBoolValue
()
const
{
bool
value2
;
if
(
!
get_bool
(
value
.
c_str
(),
&
value2
))
throw
FormatRuntimeError
(
"%s is not a boolean value (yes, true, 1) or "
"(no, false, 0) on line %i
\n
"
,
name
.
c_str
(),
line
);
return
value2
;
return
With
(
ParseBool
);
}
const
BlockParam
*
...
...
src/config/Data.cxx
View file @
af797033
...
...
@@ -126,19 +126,11 @@ ConfigData::GetPositive(ConfigOption option, unsigned default_value) const
bool
ConfigData
::
GetBool
(
ConfigOption
option
,
bool
default_value
)
const
{
const
auto
*
param
=
GetParam
(
option
);
bool
success
,
value
;
if
(
param
==
nullptr
)
return
default_value
;
success
=
get_bool
(
param
->
value
.
c_str
(),
&
value
);
if
(
!
success
)
throw
FormatRuntimeError
(
"Expected boolean value (yes, true, 1) or "
"(no, false, 0) on line %i
\n
"
,
param
->
line
);
return
value
;
return
With
(
option
,
[
default_value
](
const
char
*
s
){
return
s
!=
nullptr
?
ParseBool
(
s
)
:
default_value
;
});
}
ConfigBlock
&
...
...
src/config/Parser.cxx
View file @
af797033
/*
* Copyright 2003-201
8
The Music Player Daemon Project
* Copyright 2003-201
9
The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
...
...
@@ -18,23 +18,20 @@
*/
#include "Parser.hxx"
#include "util/RuntimeError.hxx"
#include "util/StringUtil.hxx"
bool
get_bool
(
const
char
*
value
,
bool
*
value_r
)
ParseBool
(
const
char
*
value
)
{
static
const
char
*
const
t
[]
=
{
"yes"
,
"true"
,
"1"
,
nullptr
};
static
const
char
*
const
f
[]
=
{
"no"
,
"false"
,
"0"
,
nullptr
};
if
(
StringArrayContainsCase
(
t
,
value
))
{
*
value_r
=
true
;
if
(
StringArrayContainsCase
(
t
,
value
))
return
true
;
}
if
(
StringArrayContainsCase
(
f
,
value
))
{
*
value_r
=
false
;
return
true
;
}
if
(
StringArrayContainsCase
(
f
,
value
))
return
false
;
return
false
;
throw
FormatRuntimeError
(
"Not a valid boolean (
\"
yes
\"
or
\"
no
\"
):
\"
%s
\"
"
,
value
)
;
}
src/config/Parser.hxx
View file @
af797033
/*
* Copyright 2003-201
8
The Music Player Daemon Project
* Copyright 2003-201
9
The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
...
...
@@ -20,7 +20,10 @@
#ifndef MPD_CONFIG_PARSER_HXX
#define MPD_CONFIG_PARSER_HXX
/**
* Throws on error.
*/
bool
get_bool
(
const
char
*
value
,
bool
*
value_r
);
ParseBool
(
const
char
*
value
);
#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