<commit_before>/*
**
** Author(s):
**  - <NAME> <<EMAIL>>
**  - <NAME> <<EMAIL>>
**
** Copyright (C) 2010, 2011, 2012 Aldebaran Robotics
*/

#include <qitype/signature.hpp>
#include <qimessaging/c/signature_c.h>
#include "signature_c_p.h"

#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>

//return:
// pointer to current on success
// 0 on failure
const char* qi_signature_current(qi_signature_t *sig)
{
  return sig->_current;
}

qi_signature_type qi_signature_current_type(qi_signature_t *sig)
{
  return (qi_signature_type) sig->_it.signature().c_str()[0];
}

//return pointer on struct qi_signature_t containing qi::Signature and qi::Signature::iterator.
// iterator is set to signature->begin()
//return 0 on failure
qi_signature_t *qi_signature_create(const char *signature)
{
  qi_signature_t *sig;

  if (!signature)
    return 0;

  sig  = new qi_signature_t(signature);
  sig->_it = sig->_sig.begin();
  sig->_current = ::strdup(sig->_it.signature().c_str());

  return sig;
}

qi_signature_t *qi_signature_create_subsignature(const char *signature)
{
  if (!signature)
    return 0;

  std::string sig(signature);
  qi_signature_type  endType;

  switch (*signature)
  {
  case QI_TUPLE:
    endType = QI_TUPLE_END;
    break;
  case QI_LIST:
    endType = QI_LIST_END;
    break;
  case QI_MAP:
    endType = QI_MAP_END;
    break;
  default:
    return 0;
  }

  int end = sig.find_last_of(endType);
  if (end > sig.size() || end == std::string::npos)
    return 0;

  return qi_signature_create(sig.substr(1, end - 1).c_str());
}


void qi_signature_destroy(qi_signature_t *sig)
{
  if (sig->_current)
    ::free(sig->_current);

  delete sig;
}

int qi_signature_is_pointer(const qi_signature_t *sig)
{
  return sig->_it.pointer();
}

//return
// 0 on success
// 1 on EOL
// 2 on error
int qi_signature_next(qi_signature_t *sig)
{<commit_msg>Fix comparison type mismatch<commit_after>/*
**
** Author(s):
**  - <NAME> <<EMAIL>>
**  - <NAME> <<EMAIL>>
**
** Copyright (C) 2010, 2011, 2012 Aldebaran Robotics
*/

#include <qitype/signature.hpp>
#include <qimessaging/c/signature_c.h>
#include "signature_c_p.h"

#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>

//return:
// pointer to current on success
// 0 on failure
const char* qi_signature_current(qi_signature_t *sig)
{
  return sig->_current;
}

qi_signature_type qi_signature_current_type(qi_signature_t *sig)
{
  return (qi_signature_type) sig->_it.signature().c_str()[0];
}

//return pointer on struct qi_signature_t containing qi::Signature and qi::Signature::iterator.
// iterator is set to signature->begin()
//return 0 on failure
qi_signature_t *qi_signature_create(const char *signature)
{
  qi_signature_t *sig;

  if (!signature)
    return 0;

  sig  = new qi_signature_t(signature);
  sig->_it = sig->_sig.begin();
  sig->_current = ::strdup(sig->_it.signature().c_str());

  return sig;
}

qi_signature_t *qi_signature_create_subsignature(const char *signature)
{
  if (!signature)
    return 0;

  std::string sig(signature);
  qi_signature_type  endType;

  switch (*signature)
  {
  case QI_TUPLE:
    endType = QI_TUPLE_END;
    break;
  case QI_LIST:
    endType = QI_LIST_END;
    break;
  case QI_MAP:
    endType = QI_MAP_END;
    break;
  default:
    return 0;
  }

  long end = sig.find_last_of(endType);
  if (end > sig.size() || end == std::string::npos)
    return 0;

  return qi_signature_create(sig.substr(1, end - 1).c_str());
}


void qi_signature_destroy(qi_signature_t *sig)
{
  if (sig->_current)
    ::free(sig->_current);

  delete sig;
}

int qi_signature_is_pointer(const qi_signature_t *sig)
{
  return sig->_it.pointer();
}

//return
// 0 on success
// 1 on EOL
// 2 on error
int qi_signature_next(qi_signature_t *sig)
{
{'fraction_non_alphanumeric': 0.14091147197485596, 'fraction_numerical': 0.012572027239392353, 'mean_word_length': 4.188858695652174, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 51, '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': '7018712', 'n_tokens_mistral': 1509, 'n_tokens_neox': 1417, 'n_words': 323}