<commit_before>/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
 * This file is part of the libkeynote project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include "libkeynote_xml.h"

namespace libkeynote
{

namespace
{

struct XMLException {};

}

bool moveToNextNode(xmlTextReaderPtr reader)
{
  int type = 0;
  do
  {
    const int ret = xmlTextReaderRead(reader);
    if (ret == -1)
      throw XMLException();
    else if (ret == 0)
      return false;
    type = xmlTextReaderNodeType(reader);
  }
  while (!((XML_READER_TYPE_ELEMENT == type) || (XML_READER_TYPE_END_ELEMENT == type) || (XML_READER_TYPE_TEXT == type)));

  return true;
}

void skipElement(xmlTextReaderPtr reader)
{
  if (xmlTextReaderIsEmptyElement(reader))
    return;

  int level = 1;

  int ret = xmlTextReaderRead(reader);
  while ((1 == ret) && (0 < level))
  {
    switch (xmlTextReaderNodeType(reader))
    {
    case XML_READER_TYPE_ELEMENT :
      if (!xmlTextReaderIsEmptyElement(reader))
        ++level;
      break;
    case XML_READER_TYPE_END_ELEMENT :
      --level;
      break;
    }

    ret = xmlTextReaderRead(reader);
  }

  if ((-1 == ret) || (0 != level))
    throw XMLException();
}

bool isElement(xmlTextReaderPtr reader)
{<commit_msg>do not read extra node at end<commit_after>/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
 * This file is part of the libkeynote project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include "libkeynote_xml.h"

namespace libkeynote
{

namespace
{

struct XMLException {};

}

bool moveToNextNode(xmlTextReaderPtr reader)
{
  int type = 0;
  do
  {
    const int ret = xmlTextReaderRead(reader);
    if (ret == -1)
      throw XMLException();
    else if (ret == 0)
      return false;
    type = xmlTextReaderNodeType(reader);
  }
  while (!((XML_READER_TYPE_ELEMENT == type) || (XML_READER_TYPE_END_ELEMENT == type) || (XML_READER_TYPE_TEXT == type)));

  return true;
}

void skipElement(xmlTextReaderPtr reader)
{
  if (xmlTextReaderIsEmptyElement(reader))
    return;

  int level = 1;

  int ret = xmlTextReaderRead(reader);
  while ((1 == ret) && (0 < level))
  {
    switch (xmlTextReaderNodeType(reader))
    {
    case XML_READER_TYPE_ELEMENT :
      if (!xmlTextReaderIsEmptyElement(reader))
        ++level;
      break;
    case XML_READER_TYPE_END_ELEMENT :
      --level;
      break;
    }

    if (0 < level)
      ret = xmlTextReaderRead(reader);
  }

  if ((-1 == ret) || (0 != level))
    throw XMLException();
}

bool isElement(xmlTextReaderPtr reader)
{
{'fraction_non_alphanumeric': 0.12795883361921098, 'fraction_numerical': 0.009948542024013723, 'mean_word_length': 3.1361702127659576, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 22}, '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': '4008984', 'n_tokens_mistral': 1015, 'n_tokens_neox': 978, 'n_words': 273}