add `string(JSON ... SET_STRING ...)` to set string values in json
currently, i have to quote strings before passing them to string(JSON ... SET ...)
expected: pass string values directly to string(JSON ... SET_STRING ...)
# actual
function(quote_string output_name str)
string(REPLACE "\\" "\\\\" str "${str}") # escape \ -> \\
string(REPLACE "\"" "\\\"" str "${str}") # escape " -> \"
set(str "\"${str}\"") # wrap string in quotes
set(${output_name} "${str}" PARENT_SCOPE)
endfunction()
set(json_str "[]")
set(value "aaa\"bbb\\ccc\nddd")
quote_string(value "${value}")
string(JSON json_str SET "${json_str}" 0 "${value}")
message("json_str = ${json_str}")
# expected: no need for quote_string
set(json_str "[]")
set(value "aaa\"bbb\\ccc\nddd")
string(JSON json_str SET_STRING "${json_str}" 0 "${value}")
message("json_str = ${json_str}")
Edited by milahu