26 #include "dbus-internals.h"
27 #include "dbus-string.h"
28 #define DBUS_CAN_USE_DBUS_STRING_PRIVATE 1
29 #include "dbus-string-private.h"
49 const unsigned char *ap;
50 const unsigned char *bp;
51 const unsigned char *a_end;
52 unsigned long c_str_len;
57 c_str_len = strlen (c_str);
58 if (((
unsigned long)real_a->
len) < c_str_len)
61 ap = real_a->
str + (real_a->
len - c_str_len);
62 bp = (
const unsigned char*) c_str;
63 a_end = real_a->
str + real_a->
len;
104 if (real->str[i] == byte)
118 #ifdef DBUS_BUILD_TESTS
119 #include "dbus-test.h"
143 test_hex_roundtrip (
const unsigned char *data,
178 printf (
"Original string %d bytes encoded %d bytes decoded %d bytes\n",
182 printf (
"Original: %s\n", data);
184 printf (
"Decoded: %s\n", s);
193 typedef void (* TestRoundtripFunc) (
const unsigned char *data,
196 test_roundtrips (TestRoundtripFunc func)
198 (* func) (
"Hello this is a string\n", -1);
199 (* func) (
"Hello this is a string\n1", -1);
200 (* func) (
"Hello this is a string\n12", -1);
201 (* func) (
"Hello this is a string\n123", -1);
202 (* func) (
"Hello this is a string\n1234", -1);
203 (* func) (
"Hello this is a string\n12345", -1);
208 (* func) (
"1234", 4);
209 (* func) (
"12345", 5);
214 (* func) (
"1234", 5);
215 (* func) (
"12345", 6);
217 unsigned char buf[512];
235 #ifdef DBUS_BUILD_TESTS
265 _dbus_string_test (
void)
272 int lens[] = { 0, 1, 2, 3, 4, 5, 10, 16, 17, 18, 25, 31, 32, 33, 34, 35, 63, 64, 65, 66, 67, 68, 69, 70, 71, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136 };
282 set_max_length (&str, lens[i]);
284 test_max_len (&str, lens[i]);
299 set_max_length (&str, lens[i]);
462 "Hello WorldHello World"));
470 "Hello WorldHello WorldHello World"));
503 "HelloHello WorldWorld"));
515 "HelloHello WorldWorle"));
526 if (!_dbus_string_append_unichar (&str, 0xfffc))
529 _dbus_string_get_unichar (&str, 0, &ch, &i);
597 if (!_dbus_string_append_double (&str, 50.3))
602 if (!_dbus_string_parse_double (&str, 0, &d, &end))
704 test_roundtrips (test_hex_roundtrip);
709 int found, found_len;
715 if (found != 3 || found_len != 2)
720 if (found != 8 || found_len != 1)
725 else if (found != 11 || found_len != 0)
756 #define FIRST_LINE "this is a line"
757 #define SECOND_LINE "this is a second line"
759 #define THIRD_LINE ""
760 #define FOURTH_LINE "this is a fourth line"
765 if (!
_dbus_string_append (&str, FIRST_LINE
"\n" SECOND_LINE
"\r\n" THIRD_LINE
"\n" FOURTH_LINE))
799 for (i = 0; i < 10000; i++)
852 const char two_strings[] =
"one\ttwo";
877 const char upper_string[] =
"TOUPPERSTRING";
878 const char lower_string[] =
"toupperstring";
879 const char lower2_string[] =
"toupperSTRING";
909 const char lower_string[] =
"toupperstring";
910 const char upper_string[] =
"TOUPPERSTRING";
911 const char upper2_string[] =
"TOUPPERstring";