<commit_before>/*
 * AT-SPI - Assistive Technology Service Provider Interface
 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
 *
 * Copyright 2007 IBM Corp.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/* collection.c: implements the Collection interface */

#include <string.h>

#include <atk/atk.h>
#include <droute/droute.h>

#include "bitarray.h"
#include "spi-dbus.h"
#include "accessible-stateset.h"

#include "accessible-register.h"
#include "object.h"
#include "introspection.h"

typedef struct _MatchRulePrivate MatchRulePrivate;
struct _MatchRulePrivate
{
  gint *states;
  AtspiCollectionMatchType statematchtype;
  AtkAttributeSet *attributes;
  AtspiCollectionMatchType attributematchtype;
  gint *roles;
  AtspiCollectionMatchType rolematchtype;
  gchar **ifaces;
  AtspiCollectionMatchType interfacematchtype;
  gboolean invert;
};

static gboolean
child_interface_p (AtkObject * child, gchar * repo_id)
{
  if (!strcasecmp (repo_id, "action"))
    return ATK_IS_ACTION (child);
  if (!strcasecmp (repo_id, "component"))
    return ATK_IS_COMPONENT (child);
  if (!strcasecmp (repo_id, "editabletext"))
    return ATK_IS_EDITABLE_TEXT (child);
  if (!strcasecmp (repo_id, "text"))
    return ATK_IS_TEXT (child);
  if (!strcasecmp (repo_id, "hypertext"))
    return ATK_IS_HYPERTEXT (child);
  if (!strcasecmp (repo_id, "image"))
    return ATK_IS_IMAGE (child);
  if (!strcasecmp (repo_id, "selection"))
    return ATK_IS_SELECTION (child);
  if (!strcasecmp (repo_id, "table"))
    return ATK_IS_TABLE (child);
  if (!strcasecmp (repo_id, "value"))
    return ATK_IS_VALUE (child);
  if (!strcasecmp (repo_id, "streamablecontent"))
    return ATK_IS_STREAMABLE_CONTENT (child);
  if (!strcasecmp (repo_id, "document"))
    return ATK_IS_DOCUMENT (child);
  return FALSE;
}

#define child_collection_p(ch) (TRUE)

static gboolean
match_states_all_p (AtkObject * child, gint * set)
{
  AtkStateSet *chs;
  gint i;
  gboolean ret = TRUE;

  if (set == NULL || set[0] == BITARRAY_SEQ_TERM)
    return TRUE;

  chs = atk_object_ref_state_set (child);

  // TODO: use atk-state_set_contains_states; would be more efficient
  for (i = 0; set[i] != BITARRAY_SEQ_TERM; i++)
    {
      if (!atk_state_set_contains_state (chs, set[i]))
        {
          ret = FALSE;
          break;
        }
    }

  g_object_unref (chs);
  return ret;
}

static gboolean
match_states_any_p (AtkObject * child, gint * set)
{
  AtkStateSet *chs;
  gint i;
  gboolean ret = FALSE;

  if (set == NULL || set[0] == BITARRAY_SEQ_TERM)
    return TRUE;

  chs = atk_object_ref_state_set (child);

  for (i = 0; set[i] != BITARRAY_SEQ_TERM; i++)
    {
      if (!atk_state_set_contains_state (chs, set[i]))
        {
          ret = TRUE;
          break;
        }
    }

  g_object_unref (chs);
  return ret;
}

static gboolean
match_states_none_p (AtkObject * child, gint * set)
{
  AtkStateSet *chs;
  gint i;
  gboolean ret = TRUE;

  if (set == NULL || set[0] == BITARRAY_SEQ_TERM)
    return TRUE;

  chs = atk_object_ref_state_set (child);

  for (i = 0; set[i] != BITARRAY_SEQ_TERM; i++)
    {<commit_msg>Fix for bug 677211 - The collection interface's MATCH_ANY fails for states<commit_after>/*
 * AT-SPI - Assistive Technology Service Provider Interface
 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
 *
 * Copyright 2007 IBM Corp.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/* collection.c: implements the Collection interface */

#include <string.h>

#include <atk/atk.h>
#include <droute/droute.h>

#include "bitarray.h"
#include "spi-dbus.h"
#include "accessible-stateset.h"

#include "accessible-register.h"
#include "object.h"
#include "introspection.h"

typedef struct _MatchRulePrivate MatchRulePrivate;
struct _MatchRulePrivate
{
  gint *states;
  AtspiCollectionMatchType statematchtype;
  AtkAttributeSet *attributes;
  AtspiCollectionMatchType attributematchtype;
  gint *roles;
  AtspiCollectionMatchType rolematchtype;
  gchar **ifaces;
  AtspiCollectionMatchType interfacematchtype;
  gboolean invert;
};

static gboolean
child_interface_p (AtkObject * child, gchar * repo_id)
{
  if (!strcasecmp (repo_id, "action"))
    return ATK_IS_ACTION (child);
  if (!strcasecmp (repo_id, "component"))
    return ATK_IS_COMPONENT (child);
  if (!strcasecmp (repo_id, "editabletext"))
    return ATK_IS_EDITABLE_TEXT (child);
  if (!strcasecmp (repo_id, "text"))
    return ATK_IS_TEXT (child);
  if (!strcasecmp (repo_id, "hypertext"))
    return ATK_IS_HYPERTEXT (child);
  if (!strcasecmp (repo_id, "image"))
    return ATK_IS_IMAGE (child);
  if (!strcasecmp (repo_id, "selection"))
    return ATK_IS_SELECTION (child);
  if (!strcasecmp (repo_id, "table"))
    return ATK_IS_TABLE (child);
  if (!strcasecmp (repo_id, "value"))
    return ATK_IS_VALUE (child);
  if (!strcasecmp (repo_id, "streamablecontent"))
    return ATK_IS_STREAMABLE_CONTENT (child);
  if (!strcasecmp (repo_id, "document"))
    return ATK_IS_DOCUMENT (child);
  return FALSE;
}

#define child_collection_p(ch) (TRUE)

static gboolean
match_states_all_p (AtkObject * child, gint * set)
{
  AtkStateSet *chs;
  gint i;
  gboolean ret = TRUE;

  if (set == NULL || set[0] == BITARRAY_SEQ_TERM)
    return TRUE;

  chs = atk_object_ref_state_set (child);

  // TODO: use atk-state_set_contains_states; would be more efficient
  for (i = 0; set[i] != BITARRAY_SEQ_TERM; i++)
    {
      if (!atk_state_set_contains_state (chs, set[i]))
        {
          ret = FALSE;
          break;
        }
    }

  g_object_unref (chs);
  return ret;
}

static gboolean
match_states_any_p (AtkObject * child, gint * set)
{
  AtkStateSet *chs;
  gint i;
  gboolean ret = FALSE;

  if (set == NULL || set[0] == BITARRAY_SEQ_TERM)
    return TRUE;

  chs = atk_object_ref_state_set (child);

  for (i = 0; set[i] != BITARRAY_SEQ_TERM; i++)
    {
      if (atk_state_set_contains_state (chs, set[i]))
        {
          ret = TRUE;
          break;
        }
    }

  g_object_unref (chs);
  return ret;
}

static gboolean
match_states_none_p (AtkObject * child, gint * set)
{
  AtkStateSet *chs;
  gint i;
  gboolean ret = TRUE;

  if (set == NULL || set[0] == BITARRAY_SEQ_TERM)
    return TRUE;

  chs = atk_object_ref_state_set (child);

  for (i = 0; set[i] != BITARRAY_SEQ_TERM; i++)
    {
{'fraction_non_alphanumeric': 0.1081046090108752, 'fraction_numerical': 0.0072501294665976174, 'mean_word_length': 3.8554368321810184, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6426711', 'n_tokens_mistral': 2739, 'n_tokens_neox': 2621, 'n_words': 782}