<commit_before>#if HAVE_CONFIG_H
#include <config.h>
#endif

#include <assert.h>
#include <errno.h>
#include <json-c/json_object.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

#include "classifier.h"
#include "freesasa.h"
#include "freesasa_internal.h"

/** The functions in JSON-C do not seem to have any documented error
    return values. Therefore these errors are not caught. */

json_object *
freesasa_json_atom(freesasa_node *node,
                   int options)
{
    json_object *atom;
    const freesasa_nodearea *area;
    const char *name;
    char *trim_name;

    assert(node);

    atom = json_object_new_object();
    area = freesasa_node_area(node);
    name = freesasa_node_name(node);
    trim_name = malloc(strlen(name) + 1);

    if (!trim_name) {
        mem_fail();
        return NULL;
    }

    sscanf(name, "%s", trim_name);

    json_object_object_add(atom, "name", json_object_new_string(trim_name));
    json_object_object_add(atom, "area", json_object_new_double(area->total));
    json_object_object_add(atom, "is-polar",
                           json_object_new_boolean(freesasa_node_atom_is_polar(node)));
    json_object_object_add(atom, "is-main-chain",
                           json_object_new_boolean(freesasa_atom_is_backbone(name)));
    json_object_object_add(atom, "radius",
                           json_object_new_double(freesasa_node_atom_radius(node)));

    free(trim_name);
    return atom;
}

static void
freesasa_json_add_valid_num(const json_object *obj, const char *propName, double area)
{
    if (isnan(area) || isinf(area)) {
        return;
    }
    json_object_object_add(obj, propName,
                           json_object_new_double(area));
}<commit_msg>Fix const error in json.c.<commit_after>#if HAVE_CONFIG_H
#include <config.h>
#endif

#include <assert.h>
#include <errno.h>
#include <json-c/json_object.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

#include "classifier.h"
#include "freesasa.h"
#include "freesasa_internal.h"

/** The functions in JSON-C do not seem to have any documented error
    return values. Therefore these errors are not caught. */

json_object *
freesasa_json_atom(freesasa_node *node,
                   int options)
{
    json_object *atom;
    const freesasa_nodearea *area;
    const char *name;
    char *trim_name;

    assert(node);

    atom = json_object_new_object();
    area = freesasa_node_area(node);
    name = freesasa_node_name(node);
    trim_name = malloc(strlen(name) + 1);

    if (!trim_name) {
        mem_fail();
        return NULL;
    }

    sscanf(name, "%s", trim_name);

    json_object_object_add(atom, "name", json_object_new_string(trim_name));
    json_object_object_add(atom, "area", json_object_new_double(area->total));
    json_object_object_add(atom, "is-polar",
                           json_object_new_boolean(freesasa_node_atom_is_polar(node)));
    json_object_object_add(atom, "is-main-chain",
                           json_object_new_boolean(freesasa_atom_is_backbone(name)));
    json_object_object_add(atom, "radius",
                           json_object_new_double(freesasa_node_atom_radius(node)));

    free(trim_name);
    return atom;
}

static void
freesasa_json_add_valid_num(json_object *obj, const char *propName, double area)
{
    if (isnan(area) || isinf(area)) {
        return;
    }
    json_object_object_add(obj, propName,
                           json_object_new_double(area));
}
{'fraction_non_alphanumeric': 0.1125466551823141, 'fraction_numerical': 0.0005742176284811944, 'mean_word_length': 3.3012345679012345, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '164028', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1180, 'n_words': 225}