<commit_before>#include "is_valid_char.hxx"
#include "../../Positive_Matrix_With_Prefactor_State.hxx"

#include <algorithm>
#include <iterator>
#include <string>

using namespace std::literals;

inline void check_iterator(const char character,
                           const std::vector<char>::const_iterator &begin,
                           const std::vector<char>::const_iterator &iterator,
                           const std::vector<char>::const_iterator &end)
{
  if(iterator == end)
    {
      throw std::runtime_error("Invalid polynomial string after '"s + character + "': "
                               + std::string(begin,end));
    }
}

std::vector<char>::const_iterator
parse_polynomial(const std::vector<char>::const_iterator &begin,
                 const std::vector<char>::const_iterator &end,
                 Polynomial &polynomial)
{
  const std::vector<char> delimiters({',', '}'});
  const auto delimiter(
    std::find_first_of(begin, end, delimiters.begin(), delimiters.end()));
  if(delimiter == end)
    {
      throw std::runtime_error("Missing '}' at end of array of polynomials");
    }

  std::string mantissa;
  for(auto c(begin); c < delimiter; ++c)
    {
      if(*c == '`')
        {
          do
            {
              ++c;
            }
          while(c != delimiter
                && (std::isdigit(*c) || *c == '.' || !is_valid_char(*c)
                    || *c == '`'));
        }
      if(*c == '*')
        {
          do
            {
              ++c;
              check_iterator('*',begin, c, delimiter);
            }
          while(!is_valid_char(*c));

          std::string exponent;
          if(*c == '^')
            {
              exponent = "E";
              ++c;
              check_iterator('^', begin, c, delimiter);
              while(c!=delimiter && (exponent.size() == 1 && (*c == '-' || *c == '+'))
                    || std::isdigit(*c) || !is_valid_char(*c))
                {
                  if(is_valid_char(*c))
                    {
                      exponent.push_back(*c);
                    }
                  ++c;<commit_msg>Fix logic when parsing exponents<commit_after>#include "is_valid_char.hxx"
#include "../../Positive_Matrix_With_Prefactor_State.hxx"

#include <algorithm>
#include <iterator>
#include <string>

using namespace std::literals;

inline void check_iterator(const char character,
                           const std::vector<char>::const_iterator &begin,
                           const std::vector<char>::const_iterator &iterator,
                           const std::vector<char>::const_iterator &end)
{
  if(iterator == end)
    {
      throw std::runtime_error("Invalid polynomial string after '"s + character + "': "
                               + std::string(begin,end));
    }
}

std::vector<char>::const_iterator
parse_polynomial(const std::vector<char>::const_iterator &begin,
                 const std::vector<char>::const_iterator &end,
                 Polynomial &polynomial)
{
  const std::vector<char> delimiters({',', '}'});
  const auto delimiter(
    std::find_first_of(begin, end, delimiters.begin(), delimiters.end()));
  if(delimiter == end)
    {
      throw std::runtime_error("Missing '}' at end of array of polynomials");
    }

  std::string mantissa;
  for(auto c(begin); c < delimiter; ++c)
    {
      if(*c == '`')
        {
          do
            {
              ++c;
            }
          while(c != delimiter
                && (std::isdigit(*c) || *c == '.' || !is_valid_char(*c)
                    || *c == '`'));
        }
      if(*c == '*')
        {
          do
            {
              ++c;
              check_iterator('*',begin, c, delimiter);
            }
          while(!is_valid_char(*c));

          std::string exponent;
          if(*c == '^')
            {
              exponent = "E";
              ++c;
              check_iterator('^', begin, c, delimiter);
              while(c != delimiter
                    && ((exponent.size() == 1 && (*c == '-' || *c == '+'))
                        || std::isdigit(*c) || !is_valid_char(*c)))
                {
                  if(is_valid_char(*c))
                    {
                      exponent.push_back(*c);
                    }
                  ++c;
{'fraction_non_alphanumeric': 0.15839739110179363, 'fraction_numerical': 0.0004658746797111577, 'mean_word_length': 1.6295162278015922, 'pattern_counts': {'":': 0, '<': 25, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1465427', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1223, 'n_words': 222}