mirror of
https://github.com/ivabus/pantry
synced 2024-11-10 02:25:18 +03:00
+rapidjson (#1804)
* +rapidjson * don't mind me; i'm just weird about extra invocations --------- Co-authored-by: Jacob Heider <jacob@tea.xyz>
This commit is contained in:
parent
0e2e62d9e7
commit
d60a5090f9
69
projects/rapidjson.org/capitalize.cpp
Normal file
69
projects/rapidjson.org/capitalize.cpp
Normal file
|
@ -0,0 +1,69 @@
|
|||
// https://github.com/Tencent/rapidjson/blob/949c771b03de448bdedea80c44a4a5f65284bfeb/example/capitalize/capitalize.cpp#L4
|
||||
|
||||
// JSON condenser example
|
||||
|
||||
// This example parses JSON from stdin with validation,
|
||||
// and re-output the JSON content to stdout with all string capitalized, and without whitespace.
|
||||
|
||||
#include "rapidjson/reader.h"
|
||||
#include "rapidjson/writer.h"
|
||||
#include "rapidjson/filereadstream.h"
|
||||
#include "rapidjson/filewritestream.h"
|
||||
#include "rapidjson/error/en.h"
|
||||
#include <vector>
|
||||
#include <cctype>
|
||||
|
||||
using namespace rapidjson;
|
||||
|
||||
template<typename OutputHandler>
|
||||
struct CapitalizeFilter {
|
||||
CapitalizeFilter(OutputHandler& out) : out_(out), buffer_() {}
|
||||
|
||||
bool Null() { return out_.Null(); }
|
||||
bool Bool(bool b) { return out_.Bool(b); }
|
||||
bool Int(int i) { return out_.Int(i); }
|
||||
bool Uint(unsigned u) { return out_.Uint(u); }
|
||||
bool Int64(int64_t i) { return out_.Int64(i); }
|
||||
bool Uint64(uint64_t u) { return out_.Uint64(u); }
|
||||
bool Double(double d) { return out_.Double(d); }
|
||||
bool RawNumber(const char* str, SizeType length, bool copy) { return out_.RawNumber(str, length, copy); }
|
||||
bool String(const char* str, SizeType length, bool) {
|
||||
buffer_.clear();
|
||||
for (SizeType i = 0; i < length; i++)
|
||||
buffer_.push_back(static_cast<char>(std::toupper(str[i])));
|
||||
return out_.String(&buffer_.front(), length, true); // true = output handler need to copy the string
|
||||
}
|
||||
bool StartObject() { return out_.StartObject(); }
|
||||
bool Key(const char* str, SizeType length, bool copy) { return String(str, length, copy); }
|
||||
bool EndObject(SizeType memberCount) { return out_.EndObject(memberCount); }
|
||||
bool StartArray() { return out_.StartArray(); }
|
||||
bool EndArray(SizeType elementCount) { return out_.EndArray(elementCount); }
|
||||
|
||||
OutputHandler& out_;
|
||||
std::vector<char> buffer_;
|
||||
|
||||
private:
|
||||
CapitalizeFilter(const CapitalizeFilter&);
|
||||
CapitalizeFilter& operator=(const CapitalizeFilter&);
|
||||
};
|
||||
|
||||
int main(int, char*[]) {
|
||||
// Prepare JSON reader and input stream.
|
||||
Reader reader;
|
||||
char readBuffer[65536];
|
||||
FileReadStream is(stdin, readBuffer, sizeof(readBuffer));
|
||||
|
||||
// Prepare JSON writer and output stream.
|
||||
char writeBuffer[65536];
|
||||
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
|
||||
Writer<FileWriteStream> writer(os);
|
||||
|
||||
// JSON reader parse from the input stream and let writer generate the output.
|
||||
CapitalizeFilter<Writer<FileWriteStream> > filter(writer);
|
||||
if (!reader.Parse(is, filter)) {
|
||||
fprintf(stderr, "\nError(%u): %s\n", static_cast<unsigned>(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
34
projects/rapidjson.org/package.yml
Normal file
34
projects/rapidjson.org/package.yml
Normal file
|
@ -0,0 +1,34 @@
|
|||
distributable:
|
||||
url: https://github.com/Tencent/rapidjson/archive/refs/tags/v{{version}}.tar.gz
|
||||
strip-components: 1
|
||||
|
||||
versions:
|
||||
github: Tencent/rapidjson/tags
|
||||
strip: /^v/
|
||||
|
||||
build:
|
||||
dependencies:
|
||||
cmake.org: '*'
|
||||
tea.xyz/gx/cc: c99
|
||||
tea.xyz/gx/make: '*'
|
||||
doxygen.nl: 1
|
||||
script: |
|
||||
cmake . $ARGS
|
||||
sed -i.bak \
|
||||
-e "s/-march=native//" \
|
||||
-e "s/-Werror//" \
|
||||
CMakeLists.txt
|
||||
rm CMakeLists.txt.bak
|
||||
make . install
|
||||
env:
|
||||
ARGS:
|
||||
- -DCMAKE_BUILD_TYPE=Release
|
||||
- -DCMAKE_INSTALL_PREFIX={{prefix}}
|
||||
- -DRAPIDJSON_BUILD_EXAMPLES=OFF
|
||||
|
||||
test:
|
||||
dependencies:
|
||||
tea.xyz/gx/cc: c99
|
||||
script: |
|
||||
c++ ./capitalize.cpp -o capitalize
|
||||
test $(echo '{"a":"b"}' | ./capitalize) = '{"A":"B"}'
|
Loading…
Reference in a new issue