Skip to content

Commit

Permalink
Refactor: Extract function
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-cerny committed Feb 19, 2019
1 parent c02ccd4 commit 35b79db
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/XCCDF_POLICY/xccdf_policy_remediate.c
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,15 @@ static int _xccdf_item_recursive_gather_selected_rules(struct xccdf_policy *poli
return ret;
}

static void _comment_multiline_text_strip_trailing_whitespace(char *token, size_t token_len)
{
char *token_last_char = token + token_len - 1;
while (isspace(*token_last_char)) {
token_last_char--;
}
*(token_last_char + 1) = '\0';
}

/* Handles multiline strings in profile title and description.
* Puts a '#' at the beginning of each line.
* Also removes trailing and leading whitespaces on each line.
Expand Down Expand Up @@ -831,11 +840,7 @@ static char *_comment_multiline_text(char *text)
size_t token_len = strlen(token);
if (token_len > 0) {
/* Strip trailing whitespace */
char *token_last_char = token + token_len - 1;
while (isspace(*token_last_char)) {
token_last_char--;
}
*(token_last_char + 1) = '\0';
_comment_multiline_text_strip_trailing_whitespace(token, token_len);
token_len = strlen(token);
}
if (token_len > 0) {
Expand Down

0 comments on commit 35b79db

Please sign in to comment.