Added parse_ini_string, parse_ini_file functions#690
Added parse_ini_string, parse_ini_file functions#690pmswga wants to merge 5 commits intoVKCOM:masterfrom pmswga:pmswga/ini_parsing
Conversation
DrDet
left a comment
There was a problem hiding this comment.
In general, I'm not sure it's correct way of parsing ini string. For example, PHP use autogenerated parser for that. Can you explain your parsing method somehow?
I didn't use the automatically generated parsers, because:
Therefore, the solution that came to my mind is to check the resulting strings by regular expressions. |
Tsygankov-Slava
left a comment
There was a problem hiding this comment.
I have found several places where something can be improved. It would be great if you took these comments into attention.
- removed all std utils - removed all extra functions - code refactoring
| const int64_t SINGLE_QOUTES = 0; | ||
| const int64_t DOUBLE_QUOTES = 1; | ||
| const int64_t ALL_QUOTES = 2; |
There was a problem hiding this comment.
In this case, it's better to use enum.
enum qoutes_type {
SINGLE_QOUTES,
DOUBLE_QUOTES,
ALL_QUOTES
} qoutes_type_t;| const int64_t DOUBLE_QUOTES = 1; | ||
| const int64_t ALL_QUOTES = 2; | ||
|
|
||
| string clear_quotes(const string &str, int64_t flag) { |
There was a problem hiding this comment.
The variable named flag contains little information about what exactly is there, I think it's better to call this variable quotes_type.
Then the function declaration will look like this:
string clear_quotes(const string &str, qoutes_type_t quotes_type);| Optional<string> clear_str; | ||
|
|
||
| clear_str = f$preg_replace(string("/ +/"), string(" "), str); |
There was a problem hiding this comment.
In this case, it's better to take advantage of the opportunities that C++11 standard gives us and use auto.
auto clear_str = f$preg_replace(string("/ +/"), string(" "), str);| string ini_entry; | ||
| string ini_section; | ||
|
|
||
| for (string::size_type i = 0; i <= ini_string_copy.size(); ++i) { |
There was a problem hiding this comment.
Firstly, also it's better to use auto here.
Secondly, it looks very strange that your for goes to ini_string_copy.size(), suddenly there will be a situation that you turn to ini_string_copy[ini_string_copy.size()]) (for example, if a string of the form [text somehow gets to your function). It's not very good.
It's better to fix on
for (string::size_type i = 0; i < ini_string_copy.size(); ++i) {
...
}There was a problem hiding this comment.
Type of i is deduced as int, it is not an intention.
There was a problem hiding this comment.
Type of
iis deduced asint, it is not an intention.
Thanks, you're right.
Fixed
At the moment, the functions do not process an array of values.
Example:
[Section3.1]
var1[]=val_1_1
var1[]=val_1_2
var1[]=val_1_3
This section will skip.