Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
GNOME
gnumeric
Commits
edb8c481
Commit
edb8c481
authored
Jul 30, 1998
by
Arturo Espinosa
Browse files
Missing files from last commit
parent
69def31c
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/str.c
0 → 100644
View file @
edb8c481
/*
* 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
);
}
src/str.h
0 → 100644
View file @
edb8c481
#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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment