Commit edb8c481 authored by Arturo Espinosa's avatar Arturo Espinosa

Missing files from last commit

parent 69def31c
/*
* String management for the Gnumeric Spreadsheet
*
* (C) 1998 the Free Software Foundation
*
* Author:
* Miguel de Icaza (miguel@kernel.org)
*
*/
#include <config.h>
#include <glib.h>
#include <string.h>
#include "str.h"
static GHashTable *string_hash_table;
String *
string_lookup (char *s)
{
String *string;
g_return_val_if_fail (s != NULL, NULL);
string = (String *) g_hash_table_lookup (string_hash_table, s);
return string;
}
String *
string_get (char *s)
{
String *string;
string = string_lookup (s);
if (string){
string_ref (string);
return string;
}
/* If non-existant, create */
string = g_new (String, 1);
string->ref_count = 1;
string->str = g_strdup (s);
g_hash_table_insert (string_hash_table, string->str, string);
return string;
}
void
string_ref (String *string)
{
g_return_if_fail (string != NULL);
string->ref_count++;
}
void
string_unref (String *string)
{
g_return_if_fail (string != NULL);
g_return_if_fail (string->ref_count > 0);
if (--(string->ref_count) == 0){
g_free (string->str);
g_free (string);
}
}
/*
* Decrements the reference count on *string, and if
* it reaches zero, it also clears the value pointed
* by string_ptr
*/
void
string_unref_ptr (String **string_ptr)
{
g_return_if_fail (string_ptr != NULL);
g_return_if_fail (*string_ptr != NULL);
g_return_if_fail ((*string_ptr)->ref_count > 0);
if (--((*string_ptr)->ref_count) == 0){
g_free ((*string_ptr)->str);
g_free (*string_ptr);
*string_ptr = NULL;
}
}
void
string_init (void)
{
string_hash_table = g_hash_table_new (g_str_hash, g_str_equal);
}
#ifndef STRING_H
#define STRING_H
typedef struct {
int ref_count;
char *str;
} String;
void string_init (void);
String *string_lookup (char *s);
String *string_get (char *s);
void string_ref (String *);
void string_unref (String *);
void string_unref_ptr (String **);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment