| 217 | } |
| 218 | |
| 219 | std::string CefValueTraverser::Dump_(int depth, int increment, bool labeled) const |
| 220 | { |
| 221 | std::ostringstream oss; |
| 222 | if (!labeled) { |
| 223 | oss << std::string(depth * increment, ' '); |
| 224 | } |
| 225 | switch (pCefValue->GetType()) { |
| 226 | case CefValueType::VTYPE_BOOL: |
| 227 | oss << (bool(*this) ? "true"s : "false"s) + " <bool>"; |
| 228 | break; |
| 229 | case CefValueType::VTYPE_INT: |
| 230 | oss << std::to_string(int(*this)) + " <int>"; |
| 231 | break; |
| 232 | case CefValueType::VTYPE_DOUBLE: |
| 233 | oss << std::to_string(double(*this)) + " <double>"; |
| 234 | break; |
| 235 | case CefValueType::VTYPE_STRING: |
| 236 | oss << AsString() + " <string>"; |
| 237 | break; |
| 238 | case CefValueType::VTYPE_BINARY: |
| 239 | oss << "# "s + std::to_string(pCefValue->GetBinary()->GetSize()) + " bytes # <binary>"; |
| 240 | break; |
| 241 | case CefValueType::VTYPE_DICTIONARY: |
| 242 | { |
| 243 | depth++; |
| 244 | const std::string istr(increment * depth, ' '); |
| 245 | const auto pDict = pCefValue->GetDictionary(); |
| 246 | CefDictionaryValue::KeyList keys; |
| 247 | pDict->GetKeys(keys); |
| 248 | if (keys.size() == 0) { |
| 249 | oss << "{}"; |
| 250 | } |
| 251 | else { |
| 252 | oss << "{\n"; |
| 253 | for (auto& key : keys) { |
| 254 | oss << istr << "\"" << key << "\": " << Traverse(pDict->GetValue(key)) |
| 255 | .Dump_(depth, increment, true) << "\n"; |
| 256 | } |
| 257 | oss << std::string(increment * (depth - 1), ' ') << "}"; |
| 258 | } |
| 259 | break; |
| 260 | } |
| 261 | case CefValueType::VTYPE_LIST: |
| 262 | { |
| 263 | depth++; |
| 264 | const std::string istr(increment * depth, ' '); |
| 265 | const auto pList = pCefValue->GetList(); |
| 266 | const auto size = pList->GetSize(); |
| 267 | if (size == 0) { |
| 268 | oss << "[]"; |
| 269 | } |
| 270 | else { |
| 271 | oss << "[\n"; |
| 272 | for (int i = 0; i < pList->GetSize(); i++) { |
| 273 | oss << istr << i << ": " << Traverse(pList->GetValue(i)) |
| 274 | .Dump_(depth, increment, true) << "\n"; |
| 275 | } |
| 276 | oss << std::string(increment * (depth - 1), ' ') << "]"; |