Skip to content

Commit

Permalink
clean code (#12)
Browse files Browse the repository at this point in the history
* feat: Support unbalanced quotes in log details parsing

* clean code
  • Loading branch information
jubilee2 authored Dec 30, 2024
1 parent 085850f commit 7266476
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions R/logParse.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ logDetailsParseRecord <- function(details) {
result[[key]] <- value
} else if(grepl("(Erase all data|\\[instance = \\d+\\]|\\[Erase survey responses and start survey over\\])", pair)) {
} else {
warning(paste('During parse logging details, encountered unparseable content: "', pair, '"'))
warning(paste('In function logDetailsParseRecord: encountered unparseable content: "', pair, '"'))
}
}
return(result)
Expand All @@ -53,21 +53,22 @@ logDetailsParseRecordInstance <- function(details) {
}

logDetailsParseDQ <- function(details) {
dq_log_selctor <- grepl("^(Open|Respond to|Send|Close) data query", details)
dq_log_selector <- grepl("^(Open|Respond to|Send|Close) data query", details)

pattern <- ',\\s(?=(?:[^"]|"[^"]*")*$)'

actions <- sub("\\s?\\(.*$", "", details)
info <- gsub("^[^\\(]+\\(|\\)$", "", details)
info <- paste0("Action: ", actions, ", ", info)
info[!dq_log_selctor] <- ''
info[!dq_log_selector] <- ''
pairs <- strsplit(info, pattern, perl = TRUE)

lapply(pairs, function(x) {
if (length(x) == 1 && x == "") {
return(list())
}

# Split the string by ': ' but only if it is not inside quotes
kv <- strsplit(x, ': (?=(?:[^"]|"[^"]*")*$)', perl = TRUE)
kv <- lapply(kv, function(x) gsub('^"|"$', "", x))

Expand Down

0 comments on commit 7266476

Please sign in to comment.