<commit_before>/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set sw=4 sts=4 ts=4 expandtab: */
/*
   rsvg-image.c: Image loading and displaying

   Copyright (C) 2000 Eazel, Inc.
   Copyright (C) 2002, 2003, 2004, 2005 <NAME> <<EMAIL>>
   Copyright (C) 2003, 2004, 2005 <NAME> <<EMAIL>>

   This program 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 program 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 program; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   Authors: <NAME> <<EMAIL>>, 
            <NAME> <<EMAIL>>, 
            <NAME> <<EMAIL>>
*/

#include "config.h"

#include "rsvg-image.h"
#include <string.h>
#include <math.h>
#include <errno.h>
#include "rsvg-css.h"
#ifdef HAVE_GIO
#include <gio/gio.h>
#endif

static GByteArray *
rsvg_acquire_base64_resource (const char *data, GError ** error)
{
    GByteArray *array = NULL;
    guchar *bufptr;
    gsize buffer_len;

    rsvg_return_val_if_fail (data != NULL, NULL, error);

    while (*data)
        if (*data++ == ',')
            break;

    bufptr = g_base64_decode (data, &buffer_len);
    if (bufptr) {
        array = g_byte_array_sized_new (buffer_len);
        g_byte_array_append (array, bufptr, buffer_len);
        g_free (bufptr);
    }

    return array;
}

gchar *
rsvg_get_file_path (const gchar * filename, const gchar * base_uri)
{
    gchar *absolute_filename;

    if (g_file_test (filename, G_FILE_TEST_EXISTS) || g_path_is_absolute (filename)) {
        absolute_filename = g_strdup (filename);
    } else {
        gchar *tmpcdir;
        gchar *base_filename;

        if (base_uri) {
            base_filename = g_filename_from_uri (base_uri, NULL, NULL);
            if (base_filename != NULL) {
                tmpcdir = g_path_get_dirname (base_filename);
                g_free (base_filename);
            } else 
                return NULL;
        } else
            tmpcdir = g_get_current_dir ();

        absolute_filename = g_build_filename (tmpcdir, filename, NULL);
        g_free (tmpcdir);
    }
<commit_msg>Save an extra allocation by directly decoding the base64 data into a GByteArray.<commit_after>/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim: set sw=4 sts=4 ts=4 expandtab: */
/*
   rsvg-image.c: Image loading and displaying

   Copyright (C) 2000 Eazel, Inc.
   Copyright (C) 2002, 2003, 2004, 2005 <NAME> <<EMAIL>>
   Copyright (C) 2003, 2004, 2005 <NAME> <<EMAIL>.unsw.edu.au>

   This program 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 program 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 program; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   Authors: <NAME> <<EMAIL>>, 
            <NAME> <<EMAIL>>, 
            <NAME> <<EMAIL>>
*/

#include "config.h"

#include "rsvg-image.h"
#include <string.h>
#include <math.h>
#include <errno.h>
#include "rsvg-css.h"
#ifdef HAVE_GIO
#include <gio/gio.h>
#endif

static GByteArray *
rsvg_acquire_base64_resource (const char *data, GError ** error)
{
    GByteArray *array = NULL;
    gsize data_len, written_len;
    int state = 0;
    guint save = 0;

    rsvg_return_val_if_fail (data != NULL, NULL, error);

    while (*data)
        if (*data++ == ',')
            break;

    data_len = strlen (data);
    array = g_byte_array_sized_new (data_len / 4 * 3);
    written_len = g_base64_decode_step (data, data_len, array->data,
                                        &state, &save);
    g_byte_array_set_size (array, written_len);

    return array;
}

gchar *
rsvg_get_file_path (const gchar * filename, const gchar * base_uri)
{
    gchar *absolute_filename;

    if (g_file_test (filename, G_FILE_TEST_EXISTS) || g_path_is_absolute (filename)) {
        absolute_filename = g_strdup (filename);
    } else {
        gchar *tmpcdir;
        gchar *base_filename;

        if (base_uri) {
            base_filename = g_filename_from_uri (base_uri, NULL, NULL);
            if (base_filename != NULL) {
                tmpcdir = g_path_get_dirname (base_filename);
                g_free (base_filename);
            } else 
                return NULL;
        } else
            tmpcdir = g_get_current_dir ();

        absolute_filename = g_build_filename (tmpcdir, filename, NULL);
        g_free (tmpcdir);
    }

{'fraction_non_alphanumeric': 0.10125879303961496, 'fraction_numerical': 0.021843761569788966, 'mean_word_length': 2.752083333333333, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2791890', 'n_tokens_mistral': 1826, 'n_tokens_neox': 1679, 'n_words': 568}