"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "jsonescape.h" between
xapian-omega-1.4.18.tar.xz and xapian-omega-1.4.19.tar.xz

About: Xapian Omega is an application built on Xapian, consisting of indexers and a CGI search frontend.

jsonescape.h  (xapian-omega-1.4.18.tar.xz):jsonescape.h  (xapian-omega-1.4.19.tar.xz)
/** @file /** @file
* @brief JSON escaping * @brief JSON escaping
*/ */
/* Copyright (C) 2013,2018,2019 Olly Betts /* Copyright (C) 2013,2018,2019,2021 Olly Betts
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to * of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the * deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is * sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. * all copies or substantial portions of the Software.
skipping to change at line 37 skipping to change at line 37
#include <string> #include <string>
void json_escape(std::string &s); void json_escape(std::string &s);
/// Convert a C++ std::map to JSON. /// Convert a C++ std::map to JSON.
template<typename C, typename F1, typename F2> template<typename C, typename F1, typename F2>
static inline std::string static inline std::string
to_json(const C& container, F1 func1, F2 func2) to_json(const C& container, F1 func1, F2 func2)
{ {
std::string result = "{\n \""; std::string result = "{\"";
bool first = true; bool first = true;
for (auto entry : container) { for (auto entry : container) {
if (first) { if (first) {
first = false; first = false;
} else { } else {
result += ",\n \""; result += ",\"";
} }
std::string key = func1(entry.first); std::string key = func1(entry.first);
json_escape(key); json_escape(key);
result += key; result += key;
result += "\": "; result += "\":";
result += func2(entry.second); result += func2(entry.second);
} }
if (first) { if (first) {
// Special case for an empty object. // Special case for an empty object.
result = "{}\n"; result = "{}";
} else { } else {
result += "\n}\n"; result += "}";
} }
return result; return result;
} }
#endif // OMEGA_INCLUDED_JSONESCAPE_H #endif // OMEGA_INCLUDED_JSONESCAPE_H
 End of changes. 6 change blocks. 
6 lines changed or deleted 6 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)