<commit_before>/**
 * scanner.c - implementation of the chinstrap scanner module
 */

#include <string.h>
#include "chinstrap/scanner.h"

/**
 * init the scanner with a mustache template
 *
 * :param template const char*: mustache template to scan
 * :return &scanner: scanner context for the template
 */
scanner scanner_init(const char* thetemplate, int length)
{
  int len;
  len = (length < 0) ? (int)strlen(thetemplate) : length;
  scanner s = {0, 0, thetemplate, len, 0};
  return s;
}

/**
 * get (the next) char from the template
 *
 * :return scanner_token: struct {row, col, cargo}
 */
scanner_token get_char(scanner* s)
{
  // init the return value
  char c;
  c = s->thetemplate[s->pos];
  // check if there is a new row
  if (c == '\n')
  {
    // increase row number
    ++(s->current_row);
    // reset column number
    s->current_col = 0;
    ++(s->pos);
    c = s->thetemplate[s->pos];
  }
  ++s->current_col;
  scanner_token ret = {s->current_row, s->current_col, c };
  ++s->pos;

  return ret;
}
<commit_msg>scanner: fixed test-case "test_scanner_reach_end_of_template"<commit_after>/**
 * scanner.c - implementation of the chinstrap scanner module
 */

#include <string.h>
#include "chinstrap/scanner.h"

/**
 * init the scanner with a mustache template
 *
 * :param template const char*: mustache template to scan
 * :return &scanner: scanner context for the template
 */
scanner scanner_init(const char* thetemplate, int length)
{
  int len;
  len = (length < 0) ? (int)strlen(thetemplate) : length;
  scanner s = {0, 0, thetemplate, len, 0};
  return s;
}

/**
 * get (the next) char from the template
 *
 * :return scanner_token: struct {row, col, cargo}
 */
scanner_token get_char(scanner* s)
{
  // init the return value
  char c;
  c = s->thetemplate[s->pos];
  // check if there is a new row
  if (c == '\n')
  {
    // increase row number
    ++(s->current_row);
    // reset column number
    s->current_col = 0;
    ++(s->pos);
    c = s->thetemplate[s->pos];
  } /* if */

  /* Verify that we stop when the string is terminated */
  if (c != '\0')
  {
    ++s->current_col;
    ++s->pos;
  } /* if */

  scanner_token ret = { s->current_row, s->current_col, c };

  return ret;
}

{'fraction_non_alphanumeric': 0.15221318879855464, 'fraction_numerical': 0.004968383017163505, 'mean_word_length': 3.0867158671586714, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, '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': '6564930', 'n_tokens_mistral': 796, 'n_tokens_neox': 775, 'n_words': 239}