mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-12 05:28:50 +02:00
changed g_str_hash() to a 31 bit version based on a submission by Karl
Thu Feb 17 12:53:44 2000 Tim Janik <timj@gtk.org> * gstring.c: changed g_str_hash() to a 31 bit version based on a submission by Karl Nelson and hand optimized ad absurdum by various people ;) * gstring.c: applied patch from havoc for new gstring functions, added some more sanity checks, coding style fixups. 2000-02-13 Havoc Pennington <hp@pobox.com> * tests/string-test.c (main): Add tests for the new GString features * testglib.c (main): Add tests for the new GString features * gstring.c (g_string_insert_len): New function; insert a given length of string at a given position. (g_string_append): reimplement in terms of g_string_insert_len (g_string_append_len): new function (g_string_insert_c): accept -1 for "pos" arg to mean "append" (g_string_append_c): reimplement in terms of g_string_insert_c (g_string_prepend): reimplement in terms of g_string_insert_len (g_string_prepend_len): new function (g_string_prepend_c): reimplement in terms of g_string_insert_c (g_string_insert): reimplement in terms of g_string_insert_len * glib.h: Declare g_string_insert_len, g_string_append_len, g_string_prepend_len
This commit is contained in:
committed by
Tim Janik
parent
b97261860c
commit
cf24ff7121
@ -120,6 +120,65 @@ main (int argc,
|
||||
string1->str,
|
||||
10, 666, 15, 15, 666.666666666, 666.666666666);
|
||||
#endif
|
||||
|
||||
g_string_free (string1, TRUE);
|
||||
g_string_free (string2, TRUE);
|
||||
|
||||
/* append */
|
||||
string1 = g_string_new ("firsthalf");
|
||||
g_string_append (string1, "lasthalf");
|
||||
g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
|
||||
g_string_free (string1, TRUE);
|
||||
|
||||
/* append_len */
|
||||
|
||||
string1 = g_string_new ("firsthalf");
|
||||
g_string_append_len (string1, "lasthalfjunkjunk", strlen ("lasthalf"));
|
||||
g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
|
||||
g_string_free (string1, TRUE);
|
||||
|
||||
/* prepend */
|
||||
string1 = g_string_new ("lasthalf");
|
||||
g_string_prepend (string1, "firsthalf");
|
||||
g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
|
||||
g_string_free (string1, TRUE);
|
||||
|
||||
/* prepend_len */
|
||||
string1 = g_string_new ("lasthalf");
|
||||
g_string_prepend_len (string1, "firsthalfjunkjunk", strlen ("firsthalf"));
|
||||
g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
|
||||
g_string_free (string1, TRUE);
|
||||
|
||||
/* insert */
|
||||
string1 = g_string_new ("firstlast");
|
||||
g_string_insert (string1, 5, "middle");
|
||||
g_assert (strcmp (string1->str, "firstmiddlelast") == 0);
|
||||
g_string_free (string1, TRUE);
|
||||
|
||||
/* insert with pos == end of the string */
|
||||
string1 = g_string_new ("firstmiddle");
|
||||
g_string_insert (string1, strlen ("firstmiddle"), "last");
|
||||
g_assert (strcmp (string1->str, "firstmiddlelast") == 0);
|
||||
g_string_free (string1, TRUE);
|
||||
|
||||
/* insert_len */
|
||||
|
||||
string1 = g_string_new ("firstlast");
|
||||
g_string_insert_len (string1, 5, "middlejunkjunk", strlen ("middle"));
|
||||
g_assert (strcmp (string1->str, "firstmiddlelast") == 0);
|
||||
g_string_free (string1, TRUE);
|
||||
|
||||
/* insert_len with magic -1 pos for append */
|
||||
string1 = g_string_new ("first");
|
||||
g_string_insert_len (string1, -1, "lastjunkjunk", strlen ("last"));
|
||||
g_assert (strcmp (string1->str, "firstlast") == 0);
|
||||
g_string_free (string1, TRUE);
|
||||
|
||||
/* insert_len with magic -1 len for strlen-the-string */
|
||||
string1 = g_string_new ("first");
|
||||
g_string_insert_len (string1, 5, "last", -1);
|
||||
g_assert (strcmp (string1->str, "firstlast") == 0);
|
||||
g_string_free (string1, TRUE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user