<commit_before>/*
 *  Copyright 2006-2007 FLWOR Foundation.
 *
 *  Authors: <NAME>
 */

#include <string>
#include <exception>
#include "util/datetime/gregorian.h"
#include "util/datetime/timezone.h"
#include "util/datetime/parse.h"

#define RETURN_FALSE_ON_EXCEPTION(sequence)     \
  try                                           \
  {                                             \
    sequence;                                   \
  }                                             \
  catch (std::exception& ex)                    \
  {                                             \
    return false;                               \
  }


#include <iostream>
using namespace std;

namespace xqp
{

/**
 * GYearMonth
 *
 */
bool GYearMonth::parse_string(const xqpString& s, GYearMonth_t& gym_t)
{
  unsigned int position = 0;
  bool is_negative = false;
  std::string ss = *s.getStore();
  TimeZone_t tz_t;

  // GYearMonth of form: '-'? yyyy '-' mm zzzzzz?

  skip_whitespace(ss, position);
  if (position == ss.size())
    return false;
    
  if (ss[position] == '-')
  {
    is_negative = 1;
    position++;
  }

  if (ss.size()-position > 7) // we might have a timezone
  {
    RETURN_FALSE_ON_EXCEPTION( gym_t = new GYearMonth(boost::gregorian::from_simple_string(ss.substr(position, 7) + "-01")); );
    if (TimeZone::parse_string(ss.substr(position+7, ss.size() - position - 7), tz_t))
      gym_t->the_time_zone = *tz_t;
    else
      return false;
  }
  else
  {
    RETURN_FALSE_ON_EXCEPTION( gym_t = new GYearMonth(boost::gregorian::from_simple_string(ss.substr(position) + "-01")); );
  }

  // TODO: they day should not be "01" but the last day of the given month
  // TODO: can be negative

  return true;
}

GYearMonth& GYearMonth::operator=(const GYearMonth_t& gym_t)
{
  the_gyear_month = gym_t->the_gyear_month;
  return *this;
}

bool GYearMonth::operator<(const GYearMonth& gym) const
{
  return (the_gyear_month < gym.the_gyear_month);
}

bool GYearMonth::operator==(const GYearMonth& gym) const
{
  return (the_gyear_month == gym.the_gyear_month);
}

xqpString GYearMonth::toString() const
{
  xqpString result = boost::gregorian::to_iso_extended_string(the_gyear_month).substr(0, 7);
  result += the_time_zone.toString();
  // TODO:
  return result;
}

int GYearMonth::compare(const GYearMonth& gym) const
{
  // TODO: handle timezone
  if (operator<(gym))
    return -1;
  else if (operator==(gym))
    return 0;
  else
    return 1;
}


/**
 * GYear
 *
 */
bool GYear::parse_string(const xqpString& s, GYear_t& gy_t)
{
  unsigned int position = 0;
  bool is_negative = false;
  std::string ss = *s.getStore();
  TimeZone_t tz_t;

  // GYear of form: '-'? yyyy zzzzzz?

  skip_whitespace(ss, position);
  if (position == ss.size())
    return false;

  if (ss[position] == '-')
  {
    is_negative = 1;
    position++;
  }

  if (ss.size()-position > 4) // we might have a timezone
  {
    RETURN_FALSE_ON_EXCEPTION( gy_t = new GYear(boost::gregorian::from_simple_string(ss.substr(position, 4) + "-01-01")); );
    if (TimeZone::parse_string(ss.substr(position+4, ss.size() - position - 4), tz_t))
      gy_t->the_time_zone = *tz_t;
    else
      return false;
  }
  else
  {
    RETURN_FALSE_ON_EXCEPTION( gy_t = new GYear(boost::gregorian::from_simple_string(ss.substr(position) + "-01-01")); );
  }

  // TODO: check what month/day should be filled in
  // TODO: can be negative

  return true;
}

GYear& GYear::operator=(const GYear_t& gy_t)
{
  the_gyear = gy_t->the_gyear;
  return *this;
}
<commit_msg>Minor modification<commit_after>/*
 *  Copyright 2006-2007 FLWOR Foundation.
 *
 *  Authors: <NAME>
 */

#include <string>
#include <exception>
#include "util/datetime/gregorian.h"
#include "util/datetime/timezone.h"
#include "util/datetime/parse.h"

#define RETURN_FALSE_ON_EXCEPTION(sequence)     \
  try                                           \
  {                                             \
    sequence;                                   \
  }                                             \
  catch (std::exception& ex)                    \
  {                                             \
    return false;                               \
  }


#include <iostream>
using namespace std;

namespace xqp
{

/**
 * GYearMonth
 *
 */
bool GYearMonth::parse_string(const xqpString& s, GYearMonth_t& gym_t)
{
  unsigned int position = 0;
  bool is_negative = false;
  std::string ss = *s.getStore();
  TimeZone_t tz_t;

  // GYearMonth of form: '-'? yyyy '-' mm zzzzzz?

  skip_whitespace(ss, position);
  if (position == ss.size())
    return false;
    
  if (ss[position] == '-')
  {
    is_negative = 1;
    position++;
  }

  if (ss.size()-position > 7) // we might have a timezone
  {
    RETURN_FALSE_ON_EXCEPTION( gym_t = new GYearMonth(boost::gregorian::from_simple_string(ss.substr(position, 7) + "-01")); );
    if (TimeZone::parse_string(ss.substr(position+7, ss.size() - position - 7), tz_t))
      gym_t->the_time_zone = *tz_t;
    else
      return false;
  }
  else
  {
    RETURN_FALSE_ON_EXCEPTION( gym_t = new GYearMonth(boost::gregorian::from_simple_string(ss.substr(position) + "-01")); );
  }

  // TODO: they day should not be "01" but the last day of the given month
  // TODO: can be negative

  return true;
}

GYearMonth& GYearMonth::operator=(const GYearMonth_t& gym_t)
{
  the_gyear_month = gym_t->the_gyear_month;
  return *this;
}

bool GYearMonth::operator<(const GYearMonth& gym) const
{
  return (the_gyear_month < gym.the_gyear_month);
}

bool GYearMonth::operator==(const GYearMonth& gym) const
{
  return (the_gyear_month == gym.the_gyear_month);
}

xqpString GYearMonth::toString() const
{
  xqpString result = boost::gregorian::to_iso_extended_string(the_gyear_month).substr(0, 7);
  result += the_time_zone.toString();
  // TODO:
  return result;
}

int GYearMonth::compare(const GYearMonth& gym) const
{
  // TODO: handle timezone
  if (operator<(gym))
    return -1;
  else if (operator==(gym))
    return 0;
  else
    return 1;
}


/**
 * GYear
 *
 */
bool GYear::parse_string(const xqpString& s, GYear_t& gy_t)
{
  unsigned int position = 0;
  bool is_negative = false;
  std::string ss = *s.getStore();
  TimeZone_t tz_t;

  // GYear of form: '-'? yyyy zzzzzz?

  skip_whitespace(ss, position);
  if (position == ss.size())
    return false;

  if (ss[position] == '-')
  {
    is_negative = 1;
    position++;
  }

  if (ss.size()-position > 4) // we might have a timezone
  {
    RETURN_FALSE_ON_EXCEPTION( gy_t = new GYear(boost::gregorian::from_simple_string(ss.substr(position, 4) + "-01-01")); );

    if (TimeZone::parse_string(ss.substr(position+4), tz_t))
      gy_t->the_time_zone = *tz_t;
    else
      return false;
  }
  else
  {
    RETURN_FALSE_ON_EXCEPTION( gy_t = new GYear(boost::gregorian::from_simple_string(ss.substr(position) + "-01-01")); );
  }

  // TODO: check what month/day should be filled in
  // TODO: can be negative

  return true;
}

GYear& GYear::operator=(const GYear_t& gy_t)
{
  the_gyear = gy_t->the_gyear;
  return *this;
}

{'fraction_non_alphanumeric': 0.13613159387407828, 'fraction_numerical': 0.010918888258650028, 'mean_word_length': 2.6150691952844696, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2340292', 'n_tokens_mistral': 2578, 'n_tokens_neox': 2449, 'n_words': 532}