<commit_before>#include <string>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
#include "json11.hpp"
#include <cassert>
#include <list>
#include <set>
#include <unordered_map>

using namespace json11;
using std::string;

// Check that Json has the properties we want.
#include <type_traits>
#define CHECK_TRAIT(x) static_assert(std::x::value, #x)
CHECK_TRAIT(is_nothrow_constructible<Json>);
CHECK_TRAIT(is_nothrow_default_constructible<Json>);
CHECK_TRAIT(is_copy_constructible<Json>);
CHECK_TRAIT(is_nothrow_move_constructible<Json>);
CHECK_TRAIT(is_copy_assignable<Json>);
CHECK_TRAIT(is_nothrow_move_assignable<Json>);
CHECK_TRAIT(is_nothrow_destructible<Json>);

void parse_from_stdin() {
    string buf;
    string line;
    while (std::getline(std::cin, line)) {
        buf += line + "\n";
    }

    string err;
    auto json = Json::parse(buf, err);
    if (!err.empty()) {
        printf("Failed: %s\n", err.c_str());
    } else {
        printf("Result: %s\n", json.dump().c_str());
    }
}

int main(int argc, char **argv) {
    if (argc == 2 && argv[1] == string("--stdin")) {
        parse_from_stdin();
        return 0;
    }

    const string simple_test =
        R"({"k1":"v1", "k2":42, "k3":["a",123,true,false,null]})";

    string err;
    auto json = Json::parse(simple_test, err);

    std::cout << "k1: " << json["k1"].string_value() << "\n";
    std::cout << "k3: " << json["k3"].dump() << "\n";

    for (auto &k : json["k3"].array_items()) {
        std::cout << "    - " << k.dump() << "\n";
    }

    const string comment_test = R"({
      // comment /* with nested comment */
      "a": 1,
      // comment
      // continued
      "b": "text",
      /* multi
         line
         comment */
      // and single-line comment
      "c": [1, 2, 3]
    })";

    string err_comment;
    auto json_comment = Json::parse(
      comment_test, err_comment, /*detect_comments=*/ true);
    if (!err_comment.empty()) {
        printf("Failed: %s\n", err_comment.c_str());
    } else {
        printf("Result: %s\n", json_comment.dump().c_str());
    }

    string failing_comment_test = R"({
      /* bad comment
      "a": 1,
    })";

    string err_failing_comment;
    auto json_failing_comment = Json::parse(
      failing_comment_test, err_failing_comment, /*detect_comments=*/ true);
    if (!err_failing_comment.empty()) {
        printf("Failed: %s\n", err_failing_comment.c_str());
    } else {
        printf("Result: %s\n", json_failing_comment.dump().c_str());
    }

    failing_comment_test = R"({
      / / bad comment })";

    json_failing_comment = Json::parse(
      failing_comment_test, err_failing_comment, /*detect_comments=*/ true);
    if (!err_failing_comment.empty()) {
        printf("Failed: %s\n", err_failing_comment.c_str());
    } else {
        printf("Result: %s\n", json_failing_comment.dump().c_str());
    }

    failing_comment_test = R"({
          "a": 1
        }/)";

    json_failing_comment = Json::parse(
      failing_comment_test, err_failing_comment, /*detect_comments=*/ true);
    if (!err_failing_comment.empty()) {
        printf("Failed: %s\n", err_failing_comment.c_str());<commit_msg>add test for inline comment without trailing newline<commit_after>#include <string>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
#include "json11.hpp"
#include <cassert>
#include <list>
#include <set>
#include <unordered_map>

using namespace json11;
using std::string;

// Check that Json has the properties we want.
#include <type_traits>
#define CHECK_TRAIT(x) static_assert(std::x::value, #x)
CHECK_TRAIT(is_nothrow_constructible<Json>);
CHECK_TRAIT(is_nothrow_default_constructible<Json>);
CHECK_TRAIT(is_copy_constructible<Json>);
CHECK_TRAIT(is_nothrow_move_constructible<Json>);
CHECK_TRAIT(is_copy_assignable<Json>);
CHECK_TRAIT(is_nothrow_move_assignable<Json>);
CHECK_TRAIT(is_nothrow_destructible<Json>);

void parse_from_stdin() {
    string buf;
    string line;
    while (std::getline(std::cin, line)) {
        buf += line + "\n";
    }

    string err;
    auto json = Json::parse(buf, err);
    if (!err.empty()) {
        printf("Failed: %s\n", err.c_str());
    } else {
        printf("Result: %s\n", json.dump().c_str());
    }
}

int main(int argc, char **argv) {
    if (argc == 2 && argv[1] == string("--stdin")) {
        parse_from_stdin();
        return 0;
    }

    const string simple_test =
        R"({"k1":"v1", "k2":42, "k3":["a",123,true,false,null]})";

    string err;
    auto json = Json::parse(simple_test, err);

    std::cout << "k1: " << json["k1"].string_value() << "\n";
    std::cout << "k3: " << json["k3"].dump() << "\n";

    for (auto &k : json["k3"].array_items()) {
        std::cout << "    - " << k.dump() << "\n";
    }

    const string comment_test = R"({
      // comment /* with nested comment */
      "a": 1,
      // comment
      // continued
      "b": "text",
      /* multi
         line
         comment */
      // and single-line comment
      "c": [1, 2, 3]
    })";

    string err_comment;
    auto json_comment = Json::parse(
      comment_test, err_comment, /*detect_comments=*/ true);
    if (!err_comment.empty()) {
        printf("Failed: %s\n", err_comment.c_str());
    } else {
        printf("Result: %s\n", json_comment.dump().c_str());
    }

    string failing_comment_test = R"({
      /* bad comment
      "a": 1,
    })";

    string err_failing_comment;
    auto json_failing_comment = Json::parse(
      failing_comment_test, err_failing_comment, /*detect_comments=*/ true);
    if (!err_failing_comment.empty()) {
        printf("Failed: %s\n", err_failing_comment.c_str());
    } else {
        printf("Result: %s\n", json_failing_comment.dump().c_str());
    }

    failing_comment_test = R"({
      / / bad comment })";

    json_failing_comment = Json::parse(
      failing_comment_test, err_failing_comment, /*detect_comments=*/ true);
    if (!err_failing_comment.empty()) {
        printf("Failed: %s\n", err_failing_comment.c_str());
    } else {
        printf("Result: %s\n", json_failing_comment.dump().c_str());
    }

    failing_comment_test = R"({// bad comment })";

    json_failing_comment = Json::parse(
      failing_comment_test, err_failing_comment, /*detect_comments=*/ true);
    if (!err_failing_comment.empty()) {
        printf("Failed: %s\n", err_failing_comment.c_str());
    } else {
        printf("Result: %s\n", json_failing_comment.dump().c_str());
    }

    failing_comment_test = R"({
          "a": 1
        }/)";

    json_failing_comment = Json::parse(
      failing_comment_test, err_failing_comment, /*detect_comments=*/ true);
    if (!err_failing_comment.empty()) {
        printf("Failed: %s\n", err_failing_comment.c_str());
{'fraction_non_alphanumeric': 0.17402826855123674, 'fraction_numerical': 0.007950530035335688, 'mean_word_length': 3.1674846625766873, 'pattern_counts': {'":': 16, '<': 73, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '579566', 'n_tokens_mistral': 2414, 'n_tokens_neox': 2376, 'n_words': 453}