<commit_before>/* --------------------------------------------------------------------------

   libmusicbrainz4 - Client library to access MusicBrainz

   Copyright (C) 2011 <NAME>

   This file is part of libmusicbrainz4.

   This library is free software; you can redistribute it and/or
   modify it under the terms of v2 of the GNU Lesser General Public
   License as published by the Free Software Foundation.

   libmusicbrainz4 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 General Public License
   along with this library.  If not, see <http://www.gnu.org/licenses/>.

     $Id$

----------------------------------------------------------------------------*/

#include "config.h"
#include "coverart/defines.h"

#include <iostream>
#include <string>

#include <jansson.h>

#include "coverart/ReleaseInfo.h"
#include "coverart/Images.h"

class CoverArtArchive::CReleaseInfoPrivate
{
	public:
		CReleaseInfoPrivate():
			m_Images(0)
		{
		};

		std::string m_Release;
		CoverArtArchive::CImages *m_Images;
};

CoverArtArchive::CReleaseInfo::CReleaseInfo(const std::string& JSON)
:	m_d(new CReleaseInfoPrivate)
{
	json_error_t error;
	json_t *Root=json_loads(JSON.c_str(),0,&error);
	if (Root && json_is_object(Root))
	{
		json_t *Release=json_object_get(Root,"release");
		if (Release && json_is_string(Release))
			m_d->m_Release=json_string_value(Release);

		json_t *Images=json_object_get(Root,"images");
		if (Images && json_is_array(Images))
			m_d->m_Images=new CImages(Images);
	}
}

CoverArtArchive::CReleaseInfo::CReleaseInfo(const CReleaseInfo& Other)
:	m_d(new CReleaseInfoPrivate)
{
	*this=Other;
}

CoverArtArchive::CReleaseInfo& CoverArtArchive::CReleaseInfo::operator =(const CReleaseInfo& Other)
{
	if (this!=&Other)
	{
		Cleanup();

		m_d->m_Release=Other.m_d->m_Release;
		m_d->m_Images=new CImages(*Other.m_d->m_Images);
	}

	return *this;
}

CoverArtArchive::CReleaseInfo::~CReleaseInfo()
{
	Cleanup();<commit_msg>Correctly cleanup after JSON parser<commit_after>/* --------------------------------------------------------------------------

   libmusicbrainz4 - Client library to access MusicBrainz

   Copyright (C) 2011 <NAME>

   This file is part of libmusicbrainz4.

   This library is free software; you can redistribute it and/or
   modify it under the terms of v2 of the GNU Lesser General Public
   License as published by the Free Software Foundation.

   libmusicbrainz4 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 General Public License
   along with this library.  If not, see <http://www.gnu.org/licenses/>.

     $Id$

----------------------------------------------------------------------------*/

#include "config.h"
#include "coverart/defines.h"

#include <iostream>
#include <string>

#include <jansson.h>

#include "coverart/ReleaseInfo.h"
#include "coverart/Images.h"

class CoverArtArchive::CReleaseInfoPrivate
{
	public:
		CReleaseInfoPrivate():
			m_Images(0)
		{
		};

		std::string m_Release;
		CoverArtArchive::CImages *m_Images;
};

CoverArtArchive::CReleaseInfo::CReleaseInfo(const std::string& JSON)
:	m_d(new CReleaseInfoPrivate)
{
	json_error_t error;
	json_t *Root=json_loads(JSON.c_str(),0,&error);
	if (Root && json_is_object(Root))
	{
		json_t *Release=json_object_get(Root,"release");
		if (Release && json_is_string(Release))
			m_d->m_Release=json_string_value(Release);

		json_t *Images=json_object_get(Root,"images");
		if (Images && json_is_array(Images))
			m_d->m_Images=new CImages(Images);
	}

	json_decref(Root);
}

CoverArtArchive::CReleaseInfo::CReleaseInfo(const CReleaseInfo& Other)
:	m_d(new CReleaseInfoPrivate)
{
	*this=Other;
}

CoverArtArchive::CReleaseInfo& CoverArtArchive::CReleaseInfo::operator =(const CReleaseInfo& Other)
{
	if (this!=&Other)
	{
		Cleanup();

		m_d->m_Release=Other.m_d->m_Release;
		m_d->m_Images=new CImages(*Other.m_d->m_Images);
	}

	return *this;
}

CoverArtArchive::CReleaseInfo::~CReleaseInfo()
{
	Cleanup();
{'fraction_non_alphanumeric': 0.17155192001817768, 'fraction_numerical': 0.0045444217223358325, 'mean_word_length': 3.4554655870445345, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5959895', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1402, 'n_words': 356}