<commit_before>#if HAVE_CONFIG_H
  #include <config.h>
#endif
#include <libxml/tree.h>
#include <libxml/xmlwriter.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include "freesasa_internal.h"

static xmlNodePtr
nodearea2xml(const freesasa_nodearea *area,
             const char *name)
{
    xmlNodePtr xml_node = xmlNewNode(NULL, BAD_CAST name);
    char buf[20];

    sprintf(buf, "%.3f", area->total);
    if (xmlNewProp(xml_node, BAD_CAST "total", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%.3f", area->polar);
    if (xmlNewProp(xml_node, BAD_CAST "polar", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }
    
    sprintf(buf, "%.3f", area->apolar);
    if (xmlNewProp(xml_node, BAD_CAST "apolar", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%.3f", area->main_chain);
    if (xmlNewProp(xml_node, BAD_CAST "mainChain", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%.3f", area->side_chain);
    if (xmlNewProp(xml_node, BAD_CAST "sideChain", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    return xml_node;

 cleanup:
    xmlFreeNode(xml_node);
    return NULL;
}

static xmlNodePtr
atom2xml(const freesasa_node *node,
         int options)
{
    assert(node);
    xmlNodePtr xml_node = NULL;
    const freesasa_nodearea *area = freesasa_node_area(node);
    const char *name = freesasa_node_name(node);
    int n_len = strlen(name);
    char trim_name[n_len+1], buf[20];

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

    xml_node = xmlNewNode(NULL, BAD_CAST "atom");
    if (xml_node == NULL) {
        fail_msg("");
        return NULL;
    }

    if (xmlNewProp(xml_node, BAD_CAST "name", BAD_CAST trim_name) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%.3f", area->total);
    if (xmlNewProp(xml_node, BAD_CAST "area", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%s", freesasa_node_atom_is_polar(node) == FREESASA_ATOM_POLAR ? "yes" : "no");
    if (xmlNewProp(xml_node, BAD_CAST "isPolar", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%s", freesasa_atom_is_backbone(name) ? "yes" : "no");
    if (xmlNewProp(xml_node, BAD_CAST "isMainChain", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%.3f", freesasa_node_atom_radius(node));
    if (xmlNewProp(xml_node, BAD_CAST "radius", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    return xml_node;

 cleanup:
    xmlFreeNode(xml_node);
    return NULL;
}

static xmlNodePtr
residue2xml(const freesasa_node *node,
            int options)
{
    assert(node);
    xmlNodePtr xml_node = NULL, xml_area = NULL, xml_relarea = NULL;
    const char *name = freesasa_node_name(node), *number;
    const freesasa_nodearea *abs = freesasa_node_area(node),
        *reference = freesasa_node_residue_reference(node);
    freesasa_nodearea rel;

    number = freesasa_node_residue_number(node);

    int n_len = strlen(number);
    char trim_number[n_len+1];
    sscanf(number, "%s", trim_number);
    xml_node = xmlNewNode(NULL, BAD_CAST "residue");
    if (xml_node == NULL) {
        fail_msg("");
        return NULL;
    }

    if (xmlNewProp(xml_node, BAD_CAST "name", BAD_CAST name) == NULL ||
        xmlNewProp(xml_node, BAD_CAST "number", BAD_CAST trim_number) == NULL) {<commit_msg>Add whitespace trimming of residue names in xml output<commit_after>#if HAVE_CONFIG_H
  #include <config.h>
#endif
#include <libxml/tree.h>
#include <libxml/xmlwriter.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include "freesasa_internal.h"

static xmlNodePtr
nodearea2xml(const freesasa_nodearea *area,
             const char *name)
{
    xmlNodePtr xml_node = xmlNewNode(NULL, BAD_CAST name);
    char buf[20];

    sprintf(buf, "%.3f", area->total);
    if (xmlNewProp(xml_node, BAD_CAST "total", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%.3f", area->polar);
    if (xmlNewProp(xml_node, BAD_CAST "polar", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }
    
    sprintf(buf, "%.3f", area->apolar);
    if (xmlNewProp(xml_node, BAD_CAST "apolar", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%.3f", area->main_chain);
    if (xmlNewProp(xml_node, BAD_CAST "mainChain", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%.3f", area->side_chain);
    if (xmlNewProp(xml_node, BAD_CAST "sideChain", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    return xml_node;

 cleanup:
    xmlFreeNode(xml_node);
    return NULL;
}

static xmlNodePtr
atom2xml(const freesasa_node *node,
         int options)
{
    assert(node);
    xmlNodePtr xml_node = NULL;
    const freesasa_nodearea *area = freesasa_node_area(node);
    const char *name = freesasa_node_name(node);
    int n_len = strlen(name);
    char trim_name[n_len+1], buf[20];

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

    xml_node = xmlNewNode(NULL, BAD_CAST "atom");
    if (xml_node == NULL) {
        fail_msg("");
        return NULL;
    }

    if (xmlNewProp(xml_node, BAD_CAST "name", BAD_CAST trim_name) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%.3f", area->total);
    if (xmlNewProp(xml_node, BAD_CAST "area", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%s", freesasa_node_atom_is_polar(node) == FREESASA_ATOM_POLAR ? "yes" : "no");
    if (xmlNewProp(xml_node, BAD_CAST "isPolar", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%s", freesasa_atom_is_backbone(name) ? "yes" : "no");
    if (xmlNewProp(xml_node, BAD_CAST "isMainChain", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%.3f", freesasa_node_atom_radius(node));
    if (xmlNewProp(xml_node, BAD_CAST "radius", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    return xml_node;

 cleanup:
    xmlFreeNode(xml_node);
    return NULL;
}

static xmlNodePtr
residue2xml(const freesasa_node *node,
            int options)
{
    assert(node);
    xmlNodePtr xml_node = NULL, xml_area = NULL, xml_relarea = NULL;
    const char *name = freesasa_node_name(node), *number;
    const freesasa_nodearea *abs = freesasa_node_area(node),
        *reference = freesasa_node_residue_reference(node);
    freesasa_nodearea rel;

    number = freesasa_node_residue_number(node);

    int num_len = strlen(number), name_len = strlen(name);
    char trim_number[num_len+1], trim_name[name_len+1];
    sscanf(number, "%s", trim_number);
    sscanf(name, "%s", trim_name);

    xml_node = xmlNewNode(NULL, BAD_CAST "residue");
    if (xml_node == NULL) {
        fail_msg("");
        return NULL;
    }

    if (xmlNewProp(xml_node, BAD_CAST "name", BAD_CAST trim_name) == NULL ||
        xmlNewProp(xml_node, BAD_CAST "number", BAD_CAST trim_number) == NULL) {
{'fraction_non_alphanumeric': 0.14096916299559473, 'fraction_numerical': 0.00454295154185022, 'mean_word_length': 3.111488398415393, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 109}, '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': '3125195', 'n_tokens_mistral': 2676, 'n_tokens_neox': 2661, 'n_words': 564}