<commit_before>#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <pango/pangocairo.h>
#include <string.h>
#include <js/jsapi.h>
#include "swfdec.h"
#include "swfdec_debug.h"
#include "swfdec_decoder.h"
#include "swfdec_edittext.h"
#include "swfdec_font.h"
#include "swfdec_movieclip.h"

static gboolean
swfdec_edit_text_mouse_in (SwfdecObject *object,
      double x, double y, int button)
{
  return swfdec_rect_contains (&object->extents, x, y);
}

SWFDEC_OBJECT_BOILERPLATE (SwfdecEditText, swfdec_edit_text)

static void swfdec_edit_text_base_init (gpointer g_class)
{

}

static void
swfdec_edit_text_class_init (SwfdecEditTextClass * g_class)
{
  SwfdecObjectClass *object_class = SWFDEC_OBJECT_CLASS (g_class);

  object_class->mouse_in = swfdec_edit_text_mouse_in;
}

static void
swfdec_edit_text_init (SwfdecEditText * text)
{
  text->max_length = G_MAXUINT;
}

static void
swfdec_edit_text_dispose (SwfdecEditText *text)
{
  g_free (text->text);
  if (text->path) {
    g_free (text->path);
  } else if (text->variable) {
    g_free (text->variable);
  }
  text->path = NULL;
  text->variable = NULL;
  
  G_OBJECT_CLASS (parent_class)->dispose (G_OBJECT (text));
}

static void
swfdec_edit_text_parse_variable (SwfdecEditText *text)
{
  char *s;

  if (text->variable && text->variable[0] == '\0') {
    g_free (text->variable);
    text->variable = NULL;
    return;
  }
  /* FIXME: check the variable for valid identifiers */
  s = strrchr (text->variable, '/');
  if (s == NULL)
    s = strrchr (text->variable, '.');
  if (s) {
    text->path = text->variable;
    text->variable = s + 1;
    *s = 0;
  }
  SWFDEC_LOG ("parsed variable name into path \"%s\" and variable \"%s\"",
      text->path ? text->path : "", text->variable);
}
int
tag_func_define_edit_text (SwfdecDecoder * s)<commit_msg>replace slash syntax with equivalent dot syntax<commit_after>#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <pango/pangocairo.h>
#include <string.h>
#include <js/jsapi.h>
#include "swfdec.h"
#include "swfdec_debug.h"
#include "swfdec_decoder.h"
#include "swfdec_edittext.h"
#include "swfdec_font.h"
#include "swfdec_movieclip.h"

static gboolean
swfdec_edit_text_mouse_in (SwfdecObject *object,
      double x, double y, int button)
{
  return swfdec_rect_contains (&object->extents, x, y);
}

SWFDEC_OBJECT_BOILERPLATE (SwfdecEditText, swfdec_edit_text)

static void swfdec_edit_text_base_init (gpointer g_class)
{

}

static void
swfdec_edit_text_class_init (SwfdecEditTextClass * g_class)
{
  SwfdecObjectClass *object_class = SWFDEC_OBJECT_CLASS (g_class);

  object_class->mouse_in = swfdec_edit_text_mouse_in;
}

static void
swfdec_edit_text_init (SwfdecEditText * text)
{
  text->max_length = G_MAXUINT;
}

static void
swfdec_edit_text_dispose (SwfdecEditText *text)
{
  g_free (text->text);
  if (text->path) {
    g_free (text->path);
  } else if (text->variable) {
    g_free (text->variable);
  }
  text->path = NULL;
  text->variable = NULL;
  
  G_OBJECT_CLASS (parent_class)->dispose (G_OBJECT (text));
}

static void
swfdec_edit_text_slash_to_dot (SwfdecEditText *text)
{
  char *cur = text->variable;
  GString *str = g_string_new ("");

  if (*cur == '/') {
    g_string_append (str, "_root");
  } else {
    cur--;
  }
  while (cur && *cur == '/') {
    cur++;
    if (str->len > 0)
      g_string_append_c (str, '.');
    if (cur[0] == '.' && cur[1] == '.') {
      g_string_append (str, "_parent");
      cur += 2;
    } else {
      char *slash = strchr (cur, '/');
      if (slash) {
	g_string_append_len (str, cur, slash - cur);
	cur = slash;
      } else {
	g_string_append (str, cur);
	cur = NULL;
      }
    }
    /* cur should now point to the slash */
  }
  if (cur) {
    if (*cur != '\0')
      goto fail;
  }
  g_free (text->variable);
  text->variable = g_string_free (str, FALSE);

fail:
  SWFDEC_ERROR ("failed to parse slash-notated string \"%s\" into dot notation",
      text->variable);
  g_string_free (str, TRUE);
  g_free (text->variable);
  text->variable = NULL;
}

static void
swfdec_edit_text_parse_variable (SwfdecEditText *text)
{
  char *s;

  if (text->variable && text->variable[0] == '\0') {
    g_free (text->variable);
    text->variable = NULL;
    return;
  }
  /* FIXME: check the variable for valid identifiers */
  s = strrchr (text->variable, '/');
  if (s != NULL)
    swfdec_edit_text_slash_to_dot (text);
  if (!text->variable)
    return;
  s = strrchr (text->variable, '.');
  if (s) {
    text->path = text->variable;
    text->variable = s + 1;
    *s = 0;
  }
  SWFDEC_LOG ("parsed variable name into path \"%s\" and variable \"%s\"",
      text->path ? text->path : "", text->variable);
}
int
tag_func_define_edit_text (SwfdecDecoder * s)
{'fraction_non_alphanumeric': 0.147139539793118, 'fraction_numerical': 0.002744352966012244, 'mean_word_length': 3.824847250509165, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 64, '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': '4122312', 'n_tokens_mistral': 1849, 'n_tokens_neox': 1833, 'n_words': 398}