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
a4eeaff6
Commit
a4eeaff6
authored
Jul 17, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config/File: move duplicate code to ExpectValueAndEnd()
parent
7807ddae
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
15 deletions
+20
-15
File.cxx
src/config/File.cxx
+20
-15
No files found.
src/config/File.cxx
View file @
a4eeaff6
...
...
@@ -40,6 +40,22 @@ static constexpr char CONF_COMMENT = '#';
static
constexpr
Domain
config_file_domain
(
"config_file"
);
/**
* Read a string value as the last token of a line. Throws on error.
*/
static
auto
ExpectValueAndEnd
(
Tokenizer
&
tokenizer
)
{
auto
value
=
tokenizer
.
NextString
();
if
(
!
value
)
throw
std
::
runtime_error
(
"Value missing"
);
if
(
!
tokenizer
.
IsEnd
()
&&
tokenizer
.
CurrentChar
()
!=
CONF_COMMENT
)
throw
std
::
runtime_error
(
"Unknown tokens after value"
);
return
value
;
}
static
void
config_read_name_value
(
ConfigBlock
&
block
,
char
*
input
,
unsigned
line
)
{
...
...
@@ -48,19 +64,14 @@ config_read_name_value(ConfigBlock &block, char *input, unsigned line)
const
char
*
name
=
tokenizer
.
NextWord
();
assert
(
name
!=
nullptr
);
const
char
*
value
=
tokenizer
.
NextString
();
if
(
value
==
nullptr
)
throw
std
::
runtime_error
(
"Value missing"
);
if
(
!
tokenizer
.
IsEnd
()
&&
tokenizer
.
CurrentChar
()
!=
CONF_COMMENT
)
throw
std
::
runtime_error
(
"Unknown tokens after value"
);
auto
value
=
ExpectValueAndEnd
(
tokenizer
);
const
BlockParam
*
bp
=
block
.
GetBlockParam
(
name
);
if
(
bp
!=
nullptr
)
throw
FormatRuntimeError
(
"
\"
%s
\"
is duplicate, first defined on line %i"
,
name
,
bp
->
line
);
block
.
AddBlockParam
(
name
,
value
,
line
);
block
.
AddBlockParam
(
name
,
std
::
move
(
value
)
,
line
);
}
static
ConfigBlock
*
...
...
@@ -171,14 +182,8 @@ ReadConfigParam(ConfigData &config_data, BufferedReader &reader,
/* now parse the block or the value */
const
char
*
value
=
tokenizer
.
NextString
();
if
(
value
==
nullptr
)
throw
std
::
runtime_error
(
"Value missing"
);
if
(
!
tokenizer
.
IsEnd
()
&&
tokenizer
.
CurrentChar
()
!=
CONF_COMMENT
)
throw
std
::
runtime_error
(
"Unknown tokens after value"
);
auto
*
param
=
new
ConfigParam
(
value
,
reader
.
GetLineNumber
());
auto
*
param
=
new
ConfigParam
(
ExpectValueAndEnd
(
tokenizer
),
reader
.
GetLineNumber
());
Append
(
head
,
param
);
}
...
...
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