Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
I3csstatus
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jiří Kalvoda
I3csstatus
Commits
72543e91
Commit
72543e91
authored
2 years ago
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
ConfigParser: More As... functions
parent
590d0dcb
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
ConfigParser.cs
+26
-1
26 additions, 1 deletion
ConfigParser.cs
Program.cs
+2
-2
2 additions, 2 deletions
Program.cs
with
28 additions
and
3 deletions
ConfigParser.cs
+
26
−
1
View file @
72543e91
...
...
@@ -222,6 +222,17 @@ class ConfigValue
throw
new
ConfigParseAttributeException
(
this
,
"String is not color"
);
}
}
public
bool
AsBool
()
{
if
(
Value
==
null
)
return
true
;
string
v
=
Value
.
ToLower
();
if
(
v
==
"true"
||
v
==
"yes"
||
v
==
"use"
||
v
==
"1"
)
return
true
;
if
(
v
==
"false"
||
v
==
"no"
||
v
==
"unuse"
||
v
==
"0"
)
return
false
;
throw
new
ConfigParseAttributeException
(
this
,
"String is not bool"
);
}
public
double
AsDouble
()
{
try
...
...
@@ -229,8 +240,22 @@ class ConfigValue
return
double
.
Parse
(
AsString
());
}
catch
(
ArgumentException
)
{
throw
new
ConfigParseAttributeException
(
this
,
"String is not color"
);
throw
new
ConfigParseAttributeException
(
this
,
"String is not number"
);
}
}
public
int
AsInt
()
{
try
{
return
int
.
Parse
(
AsString
());
}
catch
(
ArgumentException
)
{
throw
new
ConfigParseAttributeException
(
this
,
"String is not int"
);
}
}
public
int
AsMs
()
{
return
(
int
)(
1000
*
AsDouble
());
}
public
ConfigParser
AsConfig
()
{
...
...
This diff is collapsed.
Click to expand it.
Program.cs
+
2
−
2
View file @
72543e91
...
...
@@ -272,7 +272,7 @@ text = ERR
throw
new
ConfigMistake
(
section
[
"name"
],
"Duplicit i3status name."
);
if
(
section
.
Optional
(
"global_cache"
)
!=
null
)
{
int
cache_ms
=
(
int
)(
section
[
"global_cache"
].
As
Double
()*
1000
);
int
cache_ms
=
section
[
"global_cache"
].
As
Ms
(
);
if
(
g
.
cache_ms
!=
null
&&
g
.
cache_ms
!=
cache_ms
)
throw
new
ConfigMistake
(
section
[
"global_cache"
],
"Collision definition of global value."
);
g
.
cache_ms
=
cache_ms
;
...
...
@@ -349,7 +349,7 @@ text = ERR
}
override
protected
void
parseConfig
(
ConfigParser
p
)
{
refresh_ms
=
(
int
)((
p
.
MainSection
[
"refresh"
]?.
As
Double
()
??
1
.0
)*
1000
)
;
refresh_ms
=
p
.
MainSection
[
"refresh"
]?.
As
Ms
()
??
1
000
;
base
.
parseConfig
(
p
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment