Skip to content

Commit

Permalink
fix comment parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirteenAG committed Jun 11, 2024
1 parent 4a1b0dc commit fcfcf77
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions mINI/src/mini/ini.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,17 @@ namespace mINI

inline size_t getCommentAt(std::string_view line)
{
auto commentAt = line.find_first_of(';');
auto commentAt = line.find_last_of(';');
if (commentAt == std::string::npos)
{
commentAt = line.find("//");
commentAt = line.rfind("//");
if (commentAt == std::string::npos)
commentAt = line.find_first_of('#');
commentAt = line.find_last_of('#');
}

if (commentAt != std::string::npos && line.at(commentAt - 1) != ' ')
commentAt = std::string::npos;

return commentAt;
}

Expand Down Expand Up @@ -374,7 +378,7 @@ namespace mINI
auto value = line.substr(equalsAt + 1);
auto comment = std::string();
auto commentAt = getCommentAt(line);
if (commentAt != std::string::npos) {
if (commentAt != std::string::npos && commentAt > equalsAt) {
value = line.substr(0, commentAt);
value = value.substr(equalsAt + 1);
comment = line.substr(commentAt);
Expand Down Expand Up @@ -668,7 +672,7 @@ namespace mINI

if (!outputComment.empty() && outputComment.front() == ' ')
{
int i = outputValue.size() - value.size();
std::ptrdiff_t i = outputValue.size() - value.size();
if (i < 0)
{
while (i < 0) {
Expand Down

0 comments on commit fcfcf77

Please sign in to comment.