<commit_before>/*
 * Copyright (C) 2005 QSDN,Inc. All rights reserved.
 * Copyright (C) 2005 <NAME> All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <stdio.h>
#include "mod_chxj.h"
#include "chxj_load_emoji_data.h"

static char* s_load_emoji_set_tag( Doc* doc, apr_pool_t* p, mod_chxj_config* conf, Node* node);
static char* s_set_emoji_data( Doc* doc, apr_pool_t* p, mod_chxj_config* conf, Node* node);
static char* s_load_emoji_emoji_tag( Doc* doc, apr_pool_t* p, mod_chxj_config* conf, Node* node);
static void  s_emoji_add_to_tail( mod_chxj_config* conf, emoji_t* emoji);
static char* s_load_emoji_no_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
static char* s_load_emoji_imode_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
static char* s_load_emoji_ezweb_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
static char* s_load_emoji_jphone_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
static char  s_hexstring_to_byte(char* s);


/**
 * load emoji.xml
 */
char* 
chxj_load_emoji_data(
  Doc* doc,
  apr_pool_t *p,
  mod_chxj_config* conf) 
{
  char* rtn;

  conf->emoji      = NULL;
  conf->emoji_tail = NULL;

  if (rtn = s_set_emoji_data(doc, p, conf,qs_get_root(doc))
    return rtn;

  return NULL;
}

/**
 * <emoji>
 */
static char*
s_set_emoji_data(
  Doc* doc,
  apr_pool_t* p,
  mod_chxj_config* conf,
  Node* node) 
{
  Node* child;
  char* rtn;

  for (child = qs_get_child_node(doc,node);
       child;
       child = qs_get_next_node(doc,child)) {

    char* name = qs_get_node_name(doc,child);

    if ((*name == 'e' || *name == 'E') && strcasecmp(name, "emoji") == 0) {
      rtn = s_load_emoji_emoji_tag(doc, p, conf, child);
      if (rtn != NULL)
      {
        return rtn;
      }
    }
  }
  return NULL;
}

static char* 
s_load_emoji_emoji_tag(
  Doc* doc,
  apr_pool_t* p,
  mod_chxj_config* conf,
  Node* node)
{
  Node* child;
  char* rtn;
  for (child = qs_get_child_node(doc, node);
       child ;
       child = qs_get_next_node(doc, child))
  {
    char* name = qs_get_node_name(doc, child);
    if (strcasecmp(name, "set") == 0)
    {
      rtn = s_load_emoji_set_tag(doc, p, conf, child);
      if (rtn != NULL)
      {
        return rtn;
      }
    }<commit_msg>  * Writing is changed.<commit_after>/*
 * Copyright (C) 2005 QSDN,Inc. All rights reserved.
 * Copyright (C) 2005 <NAME> All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <stdio.h>
#include "mod_chxj.h"
#include "chxj_load_emoji_data.h"

static char* s_load_emoji_set_tag( Doc* doc, apr_pool_t* p, mod_chxj_config* conf, Node* node);
static char* s_set_emoji_data( Doc* doc, apr_pool_t* p, mod_chxj_config* conf, Node* node);
static char* s_load_emoji_emoji_tag( Doc* doc, apr_pool_t* p, mod_chxj_config* conf, Node* node);
static void  s_emoji_add_to_tail( mod_chxj_config* conf, emoji_t* emoji);
static char* s_load_emoji_no_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
static char* s_load_emoji_imode_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
static char* s_load_emoji_ezweb_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
static char* s_load_emoji_jphone_tag( Doc* doc, apr_pool_t* p, emoji_t* em, Node* node);
static char  s_hexstring_to_byte(char* s);


/**
 * load emoji.xml
 */
char* 
chxj_load_emoji_data(
  Doc* doc,
  apr_pool_t *p,
  mod_chxj_config* conf) 
{
  char* rtn;

  conf->emoji      = NULL;
  conf->emoji_tail = NULL;

  if (rtn = s_set_emoji_data(doc, p, conf,qs_get_root(doc))
    return rtn;

  return NULL;
}

/**
 * <emoji>
 */
static char*
s_set_emoji_data(
  Doc* doc,
  apr_pool_t* p,
  mod_chxj_config* conf,
  Node* node) 
{
  Node* child;
  char* rtn;

  for (child = qs_get_child_node(doc,node);
       child;
       child = qs_get_next_node(doc,child)) {

    char* name = qs_get_node_name(doc,child);

    if ((*name == 'e' || *name == 'E') && strcasecmp(name, "emoji") == 0) {
      if ((rtn = s_load_emoji_emoji_tag(doc, p, conf, child)))
        return rtn;
    }
  }
  return NULL;
}

static char* 
s_load_emoji_emoji_tag(
  Doc* doc,
  apr_pool_t* p,
  mod_chxj_config* conf,
  Node* node)
{
  Node* child;
  char* rtn;
  for (child = qs_get_child_node(doc, node);
       child ;
       child = qs_get_next_node(doc, child))
  {
    char* name = qs_get_node_name(doc, child);
    if (strcasecmp(name, "set") == 0)
    {
      rtn = s_load_emoji_set_tag(doc, p, conf, child);
      if (rtn != NULL)
      {
        return rtn;
      }
    }
{'fraction_non_alphanumeric': 0.12158988256549232, 'fraction_numerical': 0.005058717253839205, 'mean_word_length': 3.675675675675676, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '1176953', 'n_tokens_mistral': 2214, 'n_tokens_neox': 2206, 'n_words': 597}