<commit_before>/*
 *  Database interface for DMAP sharing
 *
 *  Copyright (C) 2008 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <stdlib.h>
#include <string.h>
#include <libdmapsharing/dmap-db.h>

typedef struct FilterData
{
	DmapDb *db;
	GSList *filter_def;
	GHashTable *ht;
} FilterData;

static void
dmap_db_default_init (DmapDbInterface * iface)
{
}

G_DEFINE_INTERFACE(DmapDb, dmap_db, G_TYPE_OBJECT)

DmapRecord *
dmap_db_lookup_by_id (const DmapDb * db, guint id)
{
	return DMAP_DB_GET_INTERFACE (db)->lookup_by_id (db, id);
}

guint
dmap_db_lookup_id_by_location (const DmapDb * db, const gchar * location)
{
	return DMAP_DB_GET_INTERFACE (db)->lookup_id_by_location (db,
								  location);
}

void
dmap_db_foreach (const DmapDb * db, DmapIdRecordFunc func, gpointer data)
{
	DMAP_DB_GET_INTERFACE (db)->foreach (db, func, data);
}

guint
dmap_db_add (DmapDb *db, DmapRecord *record, GError **error)
{
	return DMAP_DB_GET_INTERFACE (db)->add (db, record, error);
}

guint
dmap_db_add_with_id (DmapDb *db, DmapRecord *record, guint id, GError **error)
{
	return DMAP_DB_GET_INTERFACE (db)->add_with_id (db, record, id, error);
}

guint
dmap_db_add_path (DmapDb *db, const gchar *path, GError **error)
{
	return DMAP_DB_GET_INTERFACE (db)->add_path (db, path, error);
}

gulong
dmap_db_count (const DmapDb * db)
{
	return DMAP_DB_GET_INTERFACE (db)->count (db);
}

static gchar **
_strsplit_using_quotes (const gchar * str)
{
	/* What we are splitting looks something like this:
	 * 'foo'text to ignore'bar'.
	 */

	gchar **fnval = NULL;

	if (str != NULL) {
		int i, j;

		fnval = g_strsplit (str, "\'", 0);

		for (i = j = 0; fnval[i]; i++) {
			gchar *token = fnval[i];

			/* Handle areas around ':
			 * 'foo' 'bar'
			 * ^
			 * 'foo' 'bar'
			 *      ^
			 * 'foo'+'bar'
			 *      ^
			 */
			if (*token == '\0' || *token == ' ' || *token == '+') {
				continue;
			}

			/* Handle mistaken split at escaped '. */
			if (token[strlen (token) - 1] == '\\') {
				token = g_strconcat (fnval[i], "'",
						     fnval[i + 1], NULL);
				g_free (fnval[i]);
				g_free (fnval[i + 1]);
				i++;
			}

			fnval[j++] = token;

		}

		fnval[j] = 0x00;
	}

	return fnval;
}

static gboolean
_compare_record_property (DmapRecord * record, const gchar * property_name,
                          const gchar * property_value)
{
	gboolean accept = FALSE;
	GParamSpec *pspec;
	GValue value = { 0, };
	/* Note that this string belongs to value and will not be freed explicitely. */
	const gchar *str_value;

	pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (record),
					      property_name);

	if (pspec == NULL) {
		// Can't find the property in this record, so don't accept it.
		goto done;<commit_msg>Remove unused _strsplit_using_quotes()<commit_after>/*
 *  Database interface for DMAP sharing
 *
 *  Copyright (C) 2008 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <stdlib.h>
#include <string.h>
#include <libdmapsharing/dmap-db.h>

typedef struct FilterData
{
	DmapDb *db;
	GSList *filter_def;
	GHashTable *ht;
} FilterData;

static void
dmap_db_default_init (DmapDbInterface * iface)
{
}

G_DEFINE_INTERFACE(DmapDb, dmap_db, G_TYPE_OBJECT)

DmapRecord *
dmap_db_lookup_by_id (const DmapDb * db, guint id)
{
	return DMAP_DB_GET_INTERFACE (db)->lookup_by_id (db, id);
}

guint
dmap_db_lookup_id_by_location (const DmapDb * db, const gchar * location)
{
	return DMAP_DB_GET_INTERFACE (db)->lookup_id_by_location (db,
								  location);
}

void
dmap_db_foreach (const DmapDb * db, DmapIdRecordFunc func, gpointer data)
{
	DMAP_DB_GET_INTERFACE (db)->foreach (db, func, data);
}

guint
dmap_db_add (DmapDb *db, DmapRecord *record, GError **error)
{
	return DMAP_DB_GET_INTERFACE (db)->add (db, record, error);
}

guint
dmap_db_add_with_id (DmapDb *db, DmapRecord *record, guint id, GError **error)
{
	return DMAP_DB_GET_INTERFACE (db)->add_with_id (db, record, id, error);
}

guint
dmap_db_add_path (DmapDb *db, const gchar *path, GError **error)
{
	return DMAP_DB_GET_INTERFACE (db)->add_path (db, path, error);
}

gulong
dmap_db_count (const DmapDb * db)
{
	return DMAP_DB_GET_INTERFACE (db)->count (db);
}

static gboolean
_compare_record_property (DmapRecord * record, const gchar * property_name,
                          const gchar * property_value)
{
	gboolean accept = FALSE;
	GParamSpec *pspec;
	GValue value = { 0, };
	/* Note that this string belongs to value and will not be freed explicitely. */
	const gchar *str_value;

	pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (record),
					      property_name);

	if (pspec == NULL) {
		// Can't find the property in this record, so don't accept it.
		goto done;
{'fraction_non_alphanumeric': 0.10887030660764059, 'fraction_numerical': 0.0073782587309394985, 'mean_word_length': 3.8760991207034374, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 29, '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': '2609730', 'n_tokens_mistral': 2277, 'n_tokens_neox': 2117, 'n_words': 683}