| 174 | } |
| 175 | |
| 176 | bool JsonViewDlg::CheckForTokenUndefined(eMethod method, std::string selectedText, Result& res, HTREEITEM tree_root) |
| 177 | { |
| 178 | auto [le, lf, indentChar, indentLen] = GetFormatSetting(); |
| 179 | |
| 180 | if (m_pSetting->parseOptions.bReplaceUndefined) |
| 181 | { |
| 182 | auto text = selectedText.substr(res.error_pos, 9); |
| 183 | StringHelper::ToLower(text); |
| 184 | |
| 185 | if (text == "undefined") |
| 186 | { |
| 187 | try |
| 188 | { |
| 189 | std::regex regex("([:\\[,])([\\s]*?)undefined([\\s,}]*?)", std::regex_constants::icase); |
| 190 | text = std::regex_replace(selectedText, regex, "$1$2null"); |
| 191 | switch (method) |
| 192 | { |
| 193 | case eMethod::FormatJson: |
| 194 | res = JsonHandler(m_pSetting->parseOptions).FormatJson(text, le, lf, indentChar, indentLen); |
| 195 | break; |
| 196 | case eMethod::GetCompressedJson: |
| 197 | res = JsonHandler(m_pSetting->parseOptions).GetCompressedJson(text); |
| 198 | break; |
| 199 | case eMethod::ParseJson: |
| 200 | { |
| 201 | RapidJsonHandler handler(this, tree_root); |
| 202 | rapidjson::StringBuffer sb; |
| 203 | res = JsonHandler(m_pSetting->parseOptions).ParseJson<flgBaseReader>(text, sb, handler); |
| 204 | break; |
| 205 | } |
| 206 | case eMethod::ValidateJson: |
| 207 | res = JsonHandler(m_pSetting->parseOptions).ValidateJson(text); |
| 208 | break; |
| 209 | case eMethod::SortJsonByKey: |
| 210 | res = JsonHandler(m_pSetting->parseOptions).SortJsonByKey(text, le, lf, indentChar, indentLen); |
| 211 | break; |
| 212 | } |
| 213 | if (res.success) |
| 214 | { |
| 215 | bool bShouldReplace = method == eMethod::ParseJson || method == eMethod::ValidateJson || method == eMethod::SortJsonByKey; |
| 216 | m_pEditor->ReplaceSelection(bShouldReplace ? text : res.response); |
| 217 | HighlightAsJson(); |
| 218 | return true; |
| 219 | } |
| 220 | else |
| 221 | { |
| 222 | m_pEditor->ReplaceSelection(text); |
| 223 | m_pEditor->MakeSelection(m_pEditor->GetSelectionStart(), text.length()); |
| 224 | m_pEditor->RefreshSelectionPos(); |
| 225 | } |
| 226 | } |
| 227 | catch (const std::exception&) |
| 228 | { |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | return false; |
| 233 | } |
nothing calls this directly
no test coverage detected