795-string-desc-rename-functions.patch 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  1. From 9a26e7043fa95b4c9ee4576ce8c0ac15668e695e Mon Sep 17 00:00:00 2001
  2. From: Bruno Haible <[email protected]>
  3. Date: Thu, 2 Jan 2025 13:54:54 +0100
  4. Subject: [PATCH] string-desc, xstring-desc, string-desc-quotearg: Rename
  5. functions.
  6. * lib/string-desc.h (sd_equals): Renamed from string_desc_equals.
  7. (sd_startswith): Renamed from string_desc_startswith.
  8. (sd_endswith): Renamed from string_desc_endswith.
  9. (sd_cmp): Renamed from string_desc_cmp.
  10. (sd_c_casecmp): Renamed from string_desc_c_casecmp.
  11. (sd_index): Renamed from string_desc_index.
  12. (sd_last_index): Renamed from string_desc_last_index.
  13. (sd_contains): Renamed from string_desc_contains.
  14. (sd_new_empty): Renamed from string_desc_new_empty.
  15. (sd_new_addr): Renamed from string_desc_new_addr.
  16. (sd_from_c): Renamed from string_desc_from_c.
  17. (sd_substring): Renamed from string_desc_substring.
  18. (sd_write): Renamed from string_desc_write.
  19. (sd_fwrite): Renamed from string_desc_fwrite.
  20. (sd_new): Renamed from string_desc_new.
  21. (sd_new_filled): Renamed from string_desc_new_filled.
  22. (sd_copy): Renamed from string_desc_copy.
  23. (sd_concat): Renamed from string_desc_concat.
  24. (sd_c): Renamed from string_desc_c.
  25. (sd_set_char_at): Renamed from string_desc_set_char_at.
  26. (sd_fill): Renamed from string_desc_fill.
  27. (sd_overwrite): Renamed from string_desc_overwrite.
  28. (sd_free): Renamed from string_desc_free.
  29. (sd_length): Renamed from string_desc_length.
  30. (sd_char_at): Renamed from string_desc_char_at.
  31. (sd_data): Renamed from string_desc_data.
  32. (sd_is_empty): Renamed from string_desc_is_empty.
  33. * lib/string-desc.c (sd_equals): Renamed from string_desc_equals.
  34. (sd_startswith): Renamed from string_desc_startswith.
  35. (sd_endswith): Renamed from string_desc_endswith.
  36. (sd_cmp): Renamed from string_desc_cmp.
  37. (sd_c_casecmp): Renamed from string_desc_c_casecmp.
  38. (sd_index): Renamed from string_desc_index.
  39. (sd_last_index): Renamed from string_desc_last_index.
  40. (sd_new_empty): Renamed from string_desc_new_empty.
  41. (sd_new_addr): Renamed from string_desc_new_addr.
  42. (sd_from_c): Renamed from string_desc_from_c.
  43. (sd_substring): Renamed from string_desc_substring.
  44. (sd_write): Renamed from string_desc_write.
  45. (sd_fwrite): Renamed from string_desc_fwrite.
  46. (sd_new): Renamed from string_desc_new.
  47. (sd_new_filled): Renamed from string_desc_new_filled.
  48. (sd_copy): Renamed from string_desc_copy.
  49. (sd_concat): Renamed from string_desc_concat.
  50. (sd_c): Renamed from string_desc_c.
  51. (sd_set_char_at): Renamed from string_desc_set_char_at.
  52. (sd_fill): Renamed from string_desc_fill.
  53. (sd_overwrite): Renamed from string_desc_overwrite.
  54. (sd_free): Renamed from string_desc_free.
  55. * lib/xstring-desc.h (xsd_concat): Renamed from xstring_desc_concat.
  56. (xsd_new): Renamed from xstring_desc_new.
  57. (xsd_new_filled): Renamed from xstring_desc_new_filled.
  58. (xsd_copy): Renamed from xstring_desc_copy.
  59. (xsd_c): Renamed from xstring_desc_c.
  60. * lib/xstring-desc.c (xsd_concat): Renamed from xstring_desc_concat.
  61. * lib/string-desc-quotearg.h (sd_quotearg_buffer): Renamed from
  62. string_desc_quotearg_buffer.
  63. (sd_quotearg_alloc): Renamed from string_desc_quotearg_alloc.
  64. (sd_quotearg_n): Renamed from string_desc_quotearg_n.
  65. (sd_quotearg): Renamed from string_desc_quotearg.
  66. (sd_quotearg_n_style): Renamed from string_desc_quotearg_n_style.
  67. (sd_quotearg_style): Renamed from string_desc_quotearg_style.
  68. (sd_quotearg_char): Renamed from string_desc_quotearg_char.
  69. (sd_quotearg_colon): Renamed from string_desc_quotearg_colon.
  70. (sd_quotearg_n_custom): Renamed from string_desc_quotearg_n_custom.
  71. (sd_quotearg_custom): Renamed from sd_quotearg_n_custom.
  72. * lib/string-desc-contains.c (sd_contains): Renamed from
  73. string_desc_contains.
  74. * lib/string-buffer.h: Update.
  75. * lib/string-buffer.c (sb_append_desc, sb_contents, sb_dupfree): Update.
  76. * lib/xstring-buffer.c (sb_xdupfree): Update.
  77. * lib/sf-istream.c (sf_istream_init_from_string_desc): Update.
  78. * tests/test-string-desc.c (main): Update.
  79. * tests/test-string-desc.sh: Update.
  80. * tests/test-xstring-desc.c (main): Update.
  81. * tests/test-string-desc-quotearg.c (main): Update.
  82. * tests/test-string-buffer.c (main): Update.
  83. * tests/test-sf-istream.c (main): Update.
  84. * tests/test-sfl-istream.c (main): Update.
  85. * doc/string-desc.texi: Update.
  86. * doc/strings.texi: Update.
  87. * NEWS: Mention the change.
  88. ---
  89. ChangeLog | 86 +++++++++
  90. NEWS | 4 +
  91. doc/string-desc.texi | 4 +-
  92. doc/strings.texi | 18 +-
  93. lib/sf-istream.c | 4 +-
  94. lib/string-buffer.c | 12 +-
  95. lib/string-buffer.h | 4 +-
  96. lib/string-desc-contains.c | 2 +-
  97. lib/string-desc-quotearg.h | 114 ++++++------
  98. lib/string-desc.c | 52 +++---
  99. lib/string-desc.h | 62 +++----
  100. lib/xstring-buffer.c | 4 +-
  101. lib/xstring-desc.c | 2 +-
  102. lib/xstring-desc.h | 26 +--
  103. tests/test-sf-istream.c | 4 +-
  104. tests/test-sfl-istream.c | 4 +-
  105. tests/test-string-buffer.c | 18 +-
  106. tests/test-string-desc-quotearg.c | 44 ++---
  107. tests/test-string-desc.c | 296 +++++++++++++++---------------
  108. tests/test-string-desc.sh | 4 +-
  109. tests/test-xstring-desc.c | 68 +++----
  110. 21 files changed, 461 insertions(+), 371 deletions(-)
  111. --- a/lib/sf-istream.c
  112. +++ b/lib/sf-istream.c
  113. @@ -46,8 +46,8 @@ sf_istream_init_from_string_desc (sf_ist
  114. string_desc_t input)
  115. {
  116. stream->fp = NULL;
  117. - stream->input = string_desc_data (input);
  118. - stream->input_end = stream->input + string_desc_length (input);
  119. + stream->input = sd_data (input);
  120. + stream->input_end = stream->input + sd_length (input);
  121. }
  122. int
  123. --- a/lib/string-buffer.c
  124. +++ b/lib/string-buffer.c
  125. @@ -101,13 +101,13 @@ sb_append1 (struct string_buffer *buffer
  126. int
  127. sb_append_desc (struct string_buffer *buffer, string_desc_t s)
  128. {
  129. - size_t len = string_desc_length (s);
  130. + size_t len = sd_length (s);
  131. if (sb_ensure_more_bytes (buffer, len) < 0)
  132. {
  133. buffer->error = true;
  134. return -1;
  135. }
  136. - memcpy (buffer->data + buffer->length, string_desc_data (s), len);
  137. + memcpy (buffer->data + buffer->length, sd_data (s), len);
  138. buffer->length += len;
  139. return 0;
  140. }
  141. @@ -136,7 +136,7 @@ sb_free (struct string_buffer *buffer)
  142. string_desc_t
  143. sb_contents (struct string_buffer *buffer)
  144. {
  145. - return string_desc_new_addr (buffer->length, buffer->data);
  146. + return sd_new_addr (buffer->length, buffer->data);
  147. }
  148. const char *
  149. @@ -162,7 +162,7 @@ sb_dupfree (struct string_buffer *buffer
  150. if (copy == NULL)
  151. goto fail;
  152. memcpy (copy, buffer->data, length);
  153. - return string_desc_new_addr (length, copy);
  154. + return sd_new_addr (length, copy);
  155. }
  156. else
  157. {
  158. @@ -174,12 +174,12 @@ sb_dupfree (struct string_buffer *buffer
  159. if (contents == NULL)
  160. goto fail;
  161. }
  162. - return string_desc_new_addr (length, contents);
  163. + return sd_new_addr (length, contents);
  164. }
  165. fail:
  166. sb_free (buffer);
  167. - return string_desc_new_addr (0, NULL);
  168. + return sd_new_addr (0, NULL);
  169. }
  170. char *
  171. --- a/lib/string-buffer.h
  172. +++ b/lib/string-buffer.h
  173. @@ -115,7 +115,7 @@ extern const char * sb_contents_c (struc
  174. /* Returns the contents of BUFFER and frees all other memory held by BUFFER.
  175. Returns NULL upon failure or if there was an error earlier.
  176. - It is the responsibility of the caller to string_desc_free() the result. */
  177. + It is the responsibility of the caller to sd_free() the result. */
  178. extern string_desc_t sb_dupfree (struct string_buffer *buffer)
  179. _GL_ATTRIBUTE_RELEASE_CAPABILITY (buffer->data);
  180. @@ -182,7 +182,7 @@ extern const char * sb_xcontents_c (stru
  181. /* Returns the contents of BUFFER and frees all other memory held by BUFFER.
  182. Returns (0, NULL) if there was an error earlier.
  183. - It is the responsibility of the caller to string_desc_free() the result. */
  184. + It is the responsibility of the caller to sd_free() the result. */
  185. extern string_desc_t sb_xdupfree (struct string_buffer *buffer)
  186. _GL_ATTRIBUTE_RELEASE_CAPABILITY (buffer->data);
  187. --- a/lib/string-desc-contains.c
  188. +++ b/lib/string-desc-contains.c
  189. @@ -31,7 +31,7 @@
  190. which — depending on platforms — costs up to 2 KB of binary code. */
  191. ptrdiff_t
  192. -string_desc_contains (string_desc_t haystack, string_desc_t needle)
  193. +sd_contains (string_desc_t haystack, string_desc_t needle)
  194. {
  195. if (needle._nbytes == 0)
  196. return 0;
  197. --- a/lib/string-desc-quotearg.h
  198. +++ b/lib/string-desc-quotearg.h
  199. @@ -50,22 +50,22 @@ extern "C" {
  200. does not use backslash escapes and the flags of O do not request
  201. elision of null bytes. */
  202. #if 0
  203. -extern size_t string_desc_quotearg_buffer (char *restrict buffer,
  204. - size_t buffersize,
  205. - string_desc_t arg,
  206. - struct quoting_options const *o);
  207. +extern size_t sd_quotearg_buffer (char *restrict buffer,
  208. + size_t buffersize,
  209. + string_desc_t arg,
  210. + struct quoting_options const *o);
  211. #endif
  212. -/* Like string_desc_quotearg_buffer, except return the result in a newly
  213. +/* Like sd_quotearg_buffer, except return the result in a newly
  214. allocated buffer and store its length, excluding the terminating null
  215. byte, in *SIZE. It is the caller's responsibility to free the result.
  216. The result might contain embedded null bytes if the style of O does
  217. not use backslash escapes and the flags of O do not request elision
  218. of null bytes. */
  219. #if 0
  220. -extern char *string_desc_quotearg_alloc (string_desc_t arg,
  221. - size_t *size,
  222. - struct quoting_options const *o)
  223. +extern char *sd_quotearg_alloc (string_desc_t arg,
  224. + size_t *size,
  225. + struct quoting_options const *o)
  226. _GL_ATTRIBUTE_NONNULL ((2))
  227. _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
  228. _GL_ATTRIBUTE_RETURNS_NONNULL;
  229. @@ -77,68 +77,68 @@ extern char *string_desc_quotearg_alloc
  230. reused by the next call to this function with the same value of N.
  231. N must be nonnegative. */
  232. #if 0
  233. -extern char *string_desc_quotearg_n (int n, string_desc_t arg);
  234. +extern char *sd_quotearg_n (int n, string_desc_t arg);
  235. #endif
  236. -/* Equivalent to string_desc_quotearg_n (0, ARG). */
  237. +/* Equivalent to sd_quotearg_n (0, ARG). */
  238. #if 0
  239. -extern char *string_desc_quotearg (string_desc_t arg);
  240. +extern char *sd_quotearg (string_desc_t arg);
  241. #endif
  242. /* Use style S and storage slot N to return a quoted version of the string ARG.
  243. - This is like string_desc_quotearg_n (N, ARG), except that it uses S
  244. + This is like sd_quotearg_n (N, ARG), except that it uses S
  245. with no other options to specify the quoting method. */
  246. #if 0
  247. -extern char *string_desc_quotearg_n_style (int n, enum quoting_style s,
  248. - string_desc_t arg);
  249. +extern char *sd_quotearg_n_style (int n, enum quoting_style s,
  250. + string_desc_t arg);
  251. #endif
  252. -/* Equivalent to string_desc_quotearg_n_style (0, S, ARG). */
  253. +/* Equivalent to sd_quotearg_n_style (0, S, ARG). */
  254. #if 0
  255. -extern char *string_desc_quotearg_style (enum quoting_style s,
  256. - string_desc_t arg);
  257. +extern char *sd_quotearg_style (enum quoting_style s,
  258. + string_desc_t arg);
  259. #endif
  260. -/* Like string_desc_quotearg (ARG), except also quote any instances of CH.
  261. +/* Like sd_quotearg (ARG), except also quote any instances of CH.
  262. See set_char_quoting for a description of acceptable CH values. */
  263. #if 0
  264. -extern char *string_desc_quotearg_char (string_desc_t arg, char ch);
  265. +extern char *sd_quotearg_char (string_desc_t arg, char ch);
  266. #endif
  267. -/* Equivalent to string_desc_quotearg_char (ARG, ':'). */
  268. +/* Equivalent to sd_quotearg_char (ARG, ':'). */
  269. #if 0
  270. -extern char *string_desc_quotearg_colon (string_desc_t arg);
  271. +extern char *sd_quotearg_colon (string_desc_t arg);
  272. #endif
  273. -/* Like string_desc_quotearg_n_style (N, S, ARG) but with S as
  274. +/* Like sd_quotearg_n_style (N, S, ARG) but with S as
  275. custom_quoting_style with left quote as LEFT_QUOTE and right quote
  276. as RIGHT_QUOTE. See set_custom_quoting for a description of acceptable
  277. LEFT_QUOTE and RIGHT_QUOTE values. */
  278. #if 0
  279. -extern char *string_desc_quotearg_n_custom (int n,
  280. - char const *left_quote,
  281. - char const *right_quote,
  282. - string_desc_t arg);
  283. +extern char *sd_quotearg_n_custom (int n,
  284. + char const *left_quote,
  285. + char const *right_quote,
  286. + string_desc_t arg);
  287. #endif
  288. /* Equivalent to
  289. - string_desc_quotearg_n_custom (0, LEFT_QUOTE, RIGHT_QUOTE, ARG). */
  290. + sd_quotearg_n_custom (0, LEFT_QUOTE, RIGHT_QUOTE, ARG). */
  291. #if 0
  292. -extern char *string_desc_quotearg_custom (char const *left_quote,
  293. - char const *right_quote,
  294. - string_desc_t arg);
  295. +extern char *sd_quotearg_custom (char const *left_quote,
  296. + char const *right_quote,
  297. + string_desc_t arg);
  298. #endif
  299. /* ==== Inline function definitions ==== */
  300. GL_STRING_DESC_QUOTEARG_INLINE size_t
  301. -string_desc_quotearg_buffer (char *restrict buffer, size_t buffersize,
  302. - string_desc_t arg,
  303. - struct quoting_options const *o)
  304. +sd_quotearg_buffer (char *restrict buffer, size_t buffersize,
  305. + string_desc_t arg,
  306. + struct quoting_options const *o)
  307. {
  308. return quotearg_buffer (buffer, buffersize,
  309. - string_desc_data (arg), string_desc_length (arg),
  310. + sd_data (arg), sd_length (arg),
  311. o);
  312. }
  313. @@ -147,69 +147,69 @@ _GL_ATTRIBUTE_NONNULL ((2))
  314. _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
  315. _GL_ATTRIBUTE_RETURNS_NONNULL
  316. char *
  317. -string_desc_quotearg_alloc (string_desc_t arg,
  318. - size_t *size,
  319. - struct quoting_options const *o)
  320. +sd_quotearg_alloc (string_desc_t arg,
  321. + size_t *size,
  322. + struct quoting_options const *o)
  323. {
  324. - return quotearg_alloc_mem (string_desc_data (arg), string_desc_length (arg),
  325. + return quotearg_alloc_mem (sd_data (arg), sd_length (arg),
  326. size,
  327. o);
  328. }
  329. GL_STRING_DESC_QUOTEARG_INLINE char *
  330. -string_desc_quotearg_n (int n, string_desc_t arg)
  331. +sd_quotearg_n (int n, string_desc_t arg)
  332. {
  333. - return quotearg_n_mem (n, string_desc_data (arg), string_desc_length (arg));
  334. + return quotearg_n_mem (n, sd_data (arg), sd_length (arg));
  335. }
  336. GL_STRING_DESC_QUOTEARG_INLINE char *
  337. -string_desc_quotearg (string_desc_t arg)
  338. +sd_quotearg (string_desc_t arg)
  339. {
  340. - return quotearg_mem (string_desc_data (arg), string_desc_length (arg));
  341. + return quotearg_mem (sd_data (arg), sd_length (arg));
  342. }
  343. GL_STRING_DESC_QUOTEARG_INLINE char *
  344. -string_desc_quotearg_n_style (int n, enum quoting_style s, string_desc_t arg)
  345. +sd_quotearg_n_style (int n, enum quoting_style s, string_desc_t arg)
  346. {
  347. return quotearg_n_style_mem (n, s,
  348. - string_desc_data (arg), string_desc_length (arg));
  349. + sd_data (arg), sd_length (arg));
  350. }
  351. GL_STRING_DESC_QUOTEARG_INLINE char *
  352. -string_desc_quotearg_style (enum quoting_style s, string_desc_t arg)
  353. +sd_quotearg_style (enum quoting_style s, string_desc_t arg)
  354. {
  355. return quotearg_style_mem (s,
  356. - string_desc_data (arg), string_desc_length (arg));
  357. + sd_data (arg), sd_length (arg));
  358. }
  359. GL_STRING_DESC_QUOTEARG_INLINE char *
  360. -string_desc_quotearg_char (string_desc_t arg, char ch)
  361. +sd_quotearg_char (string_desc_t arg, char ch)
  362. {
  363. - return quotearg_char_mem (string_desc_data (arg), string_desc_length (arg),
  364. + return quotearg_char_mem (sd_data (arg), sd_length (arg),
  365. ch);
  366. }
  367. GL_STRING_DESC_QUOTEARG_INLINE char *
  368. -string_desc_quotearg_colon (string_desc_t arg)
  369. +sd_quotearg_colon (string_desc_t arg)
  370. {
  371. - return quotearg_colon_mem (string_desc_data (arg), string_desc_length (arg));
  372. + return quotearg_colon_mem (sd_data (arg), sd_length (arg));
  373. }
  374. GL_STRING_DESC_QUOTEARG_INLINE char *
  375. -string_desc_quotearg_n_custom (int n,
  376. - char const *left_quote, char const *right_quote,
  377. - string_desc_t arg)
  378. +sd_quotearg_n_custom (int n,
  379. + char const *left_quote, char const *right_quote,
  380. + string_desc_t arg)
  381. {
  382. return quotearg_n_custom_mem (n, left_quote, right_quote,
  383. - string_desc_data (arg), string_desc_length (arg));
  384. + sd_data (arg), sd_length (arg));
  385. }
  386. GL_STRING_DESC_QUOTEARG_INLINE char *
  387. -string_desc_quotearg_custom (char const *left_quote, char const *right_quote,
  388. - string_desc_t arg)
  389. +sd_quotearg_custom (char const *left_quote, char const *right_quote,
  390. + string_desc_t arg)
  391. {
  392. return quotearg_custom_mem (left_quote, right_quote,
  393. - string_desc_data (arg), string_desc_length (arg));
  394. + sd_data (arg), sd_length (arg));
  395. }
  396. --- a/lib/string-desc.c
  397. +++ b/lib/string-desc.c
  398. @@ -39,14 +39,14 @@
  399. /* Return true if A and B are equal. */
  400. bool
  401. -string_desc_equals (string_desc_t a, string_desc_t b)
  402. +sd_equals (string_desc_t a, string_desc_t b)
  403. {
  404. return (a._nbytes == b._nbytes
  405. && (a._nbytes == 0 || memcmp (a._data, b._data, a._nbytes) == 0));
  406. }
  407. bool
  408. -string_desc_startswith (string_desc_t s, string_desc_t prefix)
  409. +sd_startswith (string_desc_t s, string_desc_t prefix)
  410. {
  411. return (s._nbytes >= prefix._nbytes
  412. && (prefix._nbytes == 0
  413. @@ -54,7 +54,7 @@ string_desc_startswith (string_desc_t s,
  414. }
  415. bool
  416. -string_desc_endswith (string_desc_t s, string_desc_t suffix)
  417. +sd_endswith (string_desc_t s, string_desc_t suffix)
  418. {
  419. return (s._nbytes >= suffix._nbytes
  420. && (suffix._nbytes == 0
  421. @@ -63,7 +63,7 @@ string_desc_endswith (string_desc_t s, s
  422. }
  423. int
  424. -string_desc_cmp (string_desc_t a, string_desc_t b)
  425. +sd_cmp (string_desc_t a, string_desc_t b)
  426. {
  427. if (a._nbytes > b._nbytes)
  428. {
  429. @@ -86,14 +86,14 @@ string_desc_cmp (string_desc_t a, string
  430. }
  431. int
  432. -string_desc_c_casecmp (string_desc_t a, string_desc_t b)
  433. +sd_c_casecmp (string_desc_t a, string_desc_t b)
  434. {
  435. /* Don't use memcasecmp here, since it uses the current locale, not the
  436. "C" locale. */
  437. - idx_t an = string_desc_length (a);
  438. - idx_t bn = string_desc_length (b);
  439. - const char *ap = string_desc_data (a);
  440. - const char *bp = string_desc_data (b);
  441. + idx_t an = sd_length (a);
  442. + idx_t bn = sd_length (b);
  443. + const char *ap = sd_data (a);
  444. + const char *bp = sd_data (b);
  445. idx_t n = (an < bn ? an : bn);
  446. idx_t i;
  447. for (i = 0; i < n; i++)
  448. @@ -108,7 +108,7 @@ string_desc_c_casecmp (string_desc_t a,
  449. }
  450. ptrdiff_t
  451. -string_desc_index (string_desc_t s, char c)
  452. +sd_index (string_desc_t s, char c)
  453. {
  454. if (s._nbytes > 0)
  455. {
  456. @@ -120,7 +120,7 @@ string_desc_index (string_desc_t s, char
  457. }
  458. ptrdiff_t
  459. -string_desc_last_index (string_desc_t s, char c)
  460. +sd_last_index (string_desc_t s, char c)
  461. {
  462. if (s._nbytes > 0)
  463. {
  464. @@ -132,7 +132,7 @@ string_desc_last_index (string_desc_t s,
  465. }
  466. string_desc_t
  467. -string_desc_new_empty (void)
  468. +sd_new_empty (void)
  469. {
  470. string_desc_t result;
  471. @@ -144,7 +144,7 @@ string_desc_new_empty (void)
  472. }
  473. string_desc_t
  474. -string_desc_new_addr (idx_t n, char *addr)
  475. +sd_new_addr (idx_t n, char *addr)
  476. {
  477. string_desc_t result;
  478. @@ -158,7 +158,7 @@ string_desc_new_addr (idx_t n, char *add
  479. }
  480. string_desc_t
  481. -string_desc_from_c (const char *s)
  482. +sd_from_c (const char *s)
  483. {
  484. string_desc_t result;
  485. @@ -169,7 +169,7 @@ string_desc_from_c (const char *s)
  486. }
  487. string_desc_t
  488. -string_desc_substring (string_desc_t s, idx_t start, idx_t end)
  489. +sd_substring (string_desc_t s, idx_t start, idx_t end)
  490. {
  491. string_desc_t result;
  492. @@ -184,7 +184,7 @@ string_desc_substring (string_desc_t s,
  493. }
  494. int
  495. -string_desc_write (int fd, string_desc_t s)
  496. +sd_write (int fd, string_desc_t s)
  497. {
  498. if (s._nbytes > 0)
  499. if (full_write (fd, s._data, s._nbytes) != s._nbytes)
  500. @@ -194,7 +194,7 @@ string_desc_write (int fd, string_desc_t
  501. }
  502. int
  503. -string_desc_fwrite (FILE *fp, string_desc_t s)
  504. +sd_fwrite (FILE *fp, string_desc_t s)
  505. {
  506. if (s._nbytes > 0)
  507. if (fwrite (s._data, 1, s._nbytes, fp) != s._nbytes)
  508. @@ -206,7 +206,7 @@ string_desc_fwrite (FILE *fp, string_des
  509. /* ==== Memory-allocating operations on string descriptors ==== */
  510. int
  511. -string_desc_new (string_desc_t *resultp, idx_t n)
  512. +sd_new (string_desc_t *resultp, idx_t n)
  513. {
  514. string_desc_t result;
  515. @@ -230,7 +230,7 @@ string_desc_new (string_desc_t *resultp,
  516. }
  517. int
  518. -string_desc_new_filled (string_desc_t *resultp, idx_t n, char c)
  519. +sd_new_filled (string_desc_t *resultp, idx_t n, char c)
  520. {
  521. string_desc_t result;
  522. @@ -251,7 +251,7 @@ string_desc_new_filled (string_desc_t *r
  523. }
  524. int
  525. -string_desc_copy (string_desc_t *resultp, string_desc_t s)
  526. +sd_copy (string_desc_t *resultp, string_desc_t s)
  527. {
  528. string_desc_t result;
  529. idx_t n = s._nbytes;
  530. @@ -273,7 +273,7 @@ string_desc_copy (string_desc_t *resultp
  531. }
  532. int
  533. -string_desc_concat (string_desc_t *resultp, idx_t n, string_desc_t string1, ...)
  534. +sd_concat (string_desc_t *resultp, idx_t n, string_desc_t string1, ...)
  535. {
  536. if (n <= 0)
  537. /* Invalid argument. */
  538. @@ -327,7 +327,7 @@ string_desc_concat (string_desc_t *resul
  539. }
  540. char *
  541. -string_desc_c (string_desc_t s)
  542. +sd_c (string_desc_t s)
  543. {
  544. idx_t n = s._nbytes;
  545. char *result = (char *) imalloc (n + 1);
  546. @@ -345,7 +345,7 @@ string_desc_c (string_desc_t s)
  547. /* ==== Operations with side effects on string descriptors ==== */
  548. void
  549. -string_desc_set_char_at (string_desc_t s, idx_t i, char c)
  550. +sd_set_char_at (string_desc_t s, idx_t i, char c)
  551. {
  552. if (!(i >= 0 && i < s._nbytes))
  553. /* Invalid argument. */
  554. @@ -354,7 +354,7 @@ string_desc_set_char_at (string_desc_t s
  555. }
  556. void
  557. -string_desc_fill (string_desc_t s, idx_t start, idx_t end, char c)
  558. +sd_fill (string_desc_t s, idx_t start, idx_t end, char c)
  559. {
  560. if (!(start >= 0 && start <= end))
  561. /* Invalid arguments. */
  562. @@ -365,7 +365,7 @@ string_desc_fill (string_desc_t s, idx_t
  563. }
  564. void
  565. -string_desc_overwrite (string_desc_t s, idx_t start, string_desc_t t)
  566. +sd_overwrite (string_desc_t s, idx_t start, string_desc_t t)
  567. {
  568. if (!(start >= 0 && start + t._nbytes <= s._nbytes))
  569. /* Invalid arguments. */
  570. @@ -376,7 +376,7 @@ string_desc_overwrite (string_desc_t s,
  571. }
  572. void
  573. -string_desc_free (string_desc_t s)
  574. +sd_free (string_desc_t s)
  575. {
  576. free (s._data);
  577. }
  578. --- a/lib/string-desc.h
  579. +++ b/lib/string-desc.h
  580. @@ -69,82 +69,82 @@ struct string_desc_t
  581. /* Return the length of the string S. */
  582. #if 0 /* Defined inline below. */
  583. -extern idx_t string_desc_length (string_desc_t s);
  584. +extern idx_t sd_length (string_desc_t s);
  585. #endif
  586. /* Return the byte at index I of string S.
  587. I must be < length(S). */
  588. #if 0 /* Defined inline below. */
  589. -extern char string_desc_char_at (string_desc_t s, idx_t i);
  590. +extern char sd_char_at (string_desc_t s, idx_t i);
  591. #endif
  592. /* Return a read-only view of the bytes of S. */
  593. #if 0 /* Defined inline below. */
  594. -extern const char * string_desc_data (string_desc_t s);
  595. +extern const char * sd_data (string_desc_t s);
  596. #endif
  597. /* Return true if S is the empty string. */
  598. #if 0 /* Defined inline below. */
  599. -extern bool string_desc_is_empty (string_desc_t s);
  600. +extern bool sd_is_empty (string_desc_t s);
  601. #endif
  602. /* Return true if A and B are equal. */
  603. -extern bool string_desc_equals (string_desc_t a, string_desc_t b);
  604. +extern bool sd_equals (string_desc_t a, string_desc_t b);
  605. /* Return true if S starts with PREFIX. */
  606. -extern bool string_desc_startswith (string_desc_t s, string_desc_t prefix);
  607. +extern bool sd_startswith (string_desc_t s, string_desc_t prefix);
  608. /* Return true if S ends with SUFFIX. */
  609. -extern bool string_desc_endswith (string_desc_t s, string_desc_t suffix);
  610. +extern bool sd_endswith (string_desc_t s, string_desc_t suffix);
  611. /* Return > 0, == 0, or < 0 if A > B, A == B, A < B.
  612. This uses a lexicographic ordering, where the bytes are compared as
  613. 'unsigned char'. */
  614. -extern int string_desc_cmp (string_desc_t a, string_desc_t b);
  615. +extern int sd_cmp (string_desc_t a, string_desc_t b);
  616. /* Return > 0, == 0, or < 0 if A > B, A == B, A < B.
  617. Either A or B must be entirely ASCII.
  618. This uses a lexicographic ordering, where the bytes are compared as
  619. 'unsigned char', ignoring case, in the "C" locale. */
  620. -extern int string_desc_c_casecmp (string_desc_t a, string_desc_t b);
  621. +extern int sd_c_casecmp (string_desc_t a, string_desc_t b);
  622. /* Return the index of the first occurrence of C in S,
  623. or -1 if there is none. */
  624. -extern ptrdiff_t string_desc_index (string_desc_t s, char c);
  625. +extern ptrdiff_t sd_index (string_desc_t s, char c);
  626. /* Return the index of the last occurrence of C in S,
  627. or -1 if there is none. */
  628. -extern ptrdiff_t string_desc_last_index (string_desc_t s, char c);
  629. +extern ptrdiff_t sd_last_index (string_desc_t s, char c);
  630. /* Return the index of the first occurrence of NEEDLE in HAYSTACK,
  631. or -1 if there is none. */
  632. -extern ptrdiff_t string_desc_contains (string_desc_t haystack, string_desc_t needle);
  633. +extern ptrdiff_t sd_contains (string_desc_t haystack, string_desc_t needle);
  634. /* Return an empty string. */
  635. -extern string_desc_t string_desc_new_empty (void);
  636. +extern string_desc_t sd_new_empty (void);
  637. /* Construct and return a string of length N, at the given memory address. */
  638. -extern string_desc_t string_desc_new_addr (idx_t n, char *addr);
  639. +extern string_desc_t sd_new_addr (idx_t n, char *addr);
  640. /* Return a string that represents the C string S, of length strlen (S). */
  641. -extern string_desc_t string_desc_from_c (const char *s);
  642. +extern string_desc_t sd_from_c (const char *s);
  643. /* Return the substring of S, starting at offset START and ending at offset END.
  644. START must be <= END.
  645. The result is of length END - START.
  646. The result must not be freed (since its storage is part of the storage
  647. of S). */
  648. -extern string_desc_t string_desc_substring (string_desc_t s, idx_t start, idx_t end);
  649. +extern string_desc_t sd_substring (string_desc_t s, idx_t start, idx_t end);
  650. /* Output S to the file descriptor FD.
  651. Return 0 if successful.
  652. Upon error, return -1 with errno set. */
  653. -extern int string_desc_write (int fd, string_desc_t s);
  654. +extern int sd_write (int fd, string_desc_t s);
  655. /* Output S to the FILE stream FP.
  656. Return 0 if successful.
  657. Upon error, return -1. */
  658. -extern int string_desc_fwrite (FILE *fp, string_desc_t s);
  659. +extern int sd_fwrite (FILE *fp, string_desc_t s);
  660. /* ==== Memory-allocating operations on string descriptors ==== */
  661. @@ -153,61 +153,61 @@ extern int string_desc_fwrite (FILE *fp,
  662. Return 0 if successful.
  663. Upon error, return -1 with errno set. */
  664. _GL_ATTRIBUTE_NODISCARD
  665. -extern int string_desc_new (string_desc_t *resultp, idx_t n);
  666. +extern int sd_new (string_desc_t *resultp, idx_t n);
  667. /* Construct a string of length N, filled with C.
  668. Return 0 if successful.
  669. Upon error, return -1 with errno set. */
  670. _GL_ATTRIBUTE_NODISCARD
  671. -extern int string_desc_new_filled (string_desc_t *resultp, idx_t n, char c);
  672. +extern int sd_new_filled (string_desc_t *resultp, idx_t n, char c);
  673. /* Construct a copy of string S.
  674. Return 0 if successful.
  675. Upon error, return -1 with errno set. */
  676. _GL_ATTRIBUTE_NODISCARD
  677. -extern int string_desc_copy (string_desc_t *resultp, string_desc_t s);
  678. +extern int sd_copy (string_desc_t *resultp, string_desc_t s);
  679. /* Construct the concatenation of N strings. N must be > 0.
  680. Return 0 if successful.
  681. Upon error, return -1 with errno set. */
  682. _GL_ATTRIBUTE_NODISCARD
  683. -extern int string_desc_concat (string_desc_t *resultp, idx_t n, string_desc_t string1, ...);
  684. +extern int sd_concat (string_desc_t *resultp, idx_t n, string_desc_t string1, ...);
  685. /* Construct a copy of string S, as a NUL-terminated C string.
  686. Return it is successful.
  687. Upon error, return NULL with errno set. */
  688. -extern char * string_desc_c (string_desc_t s) _GL_ATTRIBUTE_DEALLOC_FREE;
  689. +extern char * sd_c (string_desc_t s) _GL_ATTRIBUTE_DEALLOC_FREE;
  690. /* ==== Operations with side effects on string descriptors ==== */
  691. /* Overwrite the byte at index I of string S with C.
  692. I must be < length(S). */
  693. -extern void string_desc_set_char_at (string_desc_t s, idx_t i, char c);
  694. +extern void sd_set_char_at (string_desc_t s, idx_t i, char c);
  695. /* Fill part of S, starting at offset START and ending at offset END,
  696. with copies of C.
  697. START must be <= END. */
  698. -extern void string_desc_fill (string_desc_t s, idx_t start, idx_t end, char c);
  699. +extern void sd_fill (string_desc_t s, idx_t start, idx_t end, char c);
  700. /* Overwrite part of S with T, starting at offset START.
  701. START + length(T) must be <= length (S). */
  702. -extern void string_desc_overwrite (string_desc_t s, idx_t start, string_desc_t t);
  703. +extern void sd_overwrite (string_desc_t s, idx_t start, string_desc_t t);
  704. /* Free S. */
  705. -extern void string_desc_free (string_desc_t s);
  706. +extern void sd_free (string_desc_t s);
  707. /* ==== Inline function definitions ==== */
  708. GL_STRING_DESC_INLINE idx_t
  709. -string_desc_length (string_desc_t s)
  710. +sd_length (string_desc_t s)
  711. {
  712. return s._nbytes;
  713. }
  714. GL_STRING_DESC_INLINE char
  715. -string_desc_char_at (string_desc_t s, idx_t i)
  716. +sd_char_at (string_desc_t s, idx_t i)
  717. {
  718. if (!(i >= 0 && i < s._nbytes))
  719. /* Invalid argument. */
  720. @@ -216,13 +216,13 @@ string_desc_char_at (string_desc_t s, id
  721. }
  722. GL_STRING_DESC_INLINE const char *
  723. -string_desc_data (string_desc_t s)
  724. +sd_data (string_desc_t s)
  725. {
  726. return s._data;
  727. }
  728. GL_STRING_DESC_INLINE bool
  729. -string_desc_is_empty (string_desc_t s)
  730. +sd_is_empty (string_desc_t s)
  731. {
  732. return s._nbytes == 0;
  733. }
  734. --- a/lib/xstring-buffer.c
  735. +++ b/lib/xstring-buffer.c
  736. @@ -59,10 +59,10 @@ sb_xdupfree (struct string_buffer *buffe
  737. if (buffer->error)
  738. {
  739. sb_free (buffer);
  740. - return string_desc_new_addr (0, NULL);
  741. + return sd_new_addr (0, NULL);
  742. }
  743. string_desc_t contents = sb_dupfree (buffer);
  744. - if (string_desc_data (contents) == NULL)
  745. + if (sd_data (contents) == NULL)
  746. xalloc_die ();
  747. return contents;
  748. }
  749. --- a/lib/xstring-desc.c
  750. +++ b/lib/xstring-desc.c
  751. @@ -22,7 +22,7 @@
  752. #include "ialloc.h"
  753. string_desc_t
  754. -xstring_desc_concat (idx_t n, string_desc_t string1, ...)
  755. +xsd_concat (idx_t n, string_desc_t string1, ...)
  756. {
  757. if (n <= 0)
  758. /* Invalid argument. */
  759. --- a/lib/xstring-desc.h
  760. +++ b/lib/xstring-desc.h
  761. @@ -43,53 +43,53 @@ extern "C" {
  762. /* Return a string of length N, with uninitialized contents. */
  763. #if 0 /* Defined inline below. */
  764. -extern string_desc_t xstring_desc_new (idx_t n);
  765. +extern string_desc_t xsd_new (idx_t n);
  766. #endif
  767. /* Return a string of length N, filled with C. */
  768. #if 0 /* Defined inline below. */
  769. -extern string_desc_t xstring_desc_new_filled (idx_t n, char c);
  770. +extern string_desc_t xsd_new_filled (idx_t n, char c);
  771. #endif
  772. /* Return a copy of string S. */
  773. #if 0 /* Defined inline below. */
  774. -extern string_desc_t xstring_desc_copy (string_desc_t s);
  775. +extern string_desc_t xsd_copy (string_desc_t s);
  776. #endif
  777. /* Return the concatenation of N strings. N must be > 0. */
  778. -extern string_desc_t xstring_desc_concat (idx_t n, string_desc_t string1, ...);
  779. +extern string_desc_t xsd_concat (idx_t n, string_desc_t string1, ...);
  780. /* Construct and return a copy of string S, as a NUL-terminated C string. */
  781. #if 0 /* Defined inline below. */
  782. -extern char * xstring_desc_c (string_desc_t s) _GL_ATTRIBUTE_DEALLOC_FREE;
  783. +extern char * xsd_c (string_desc_t s) _GL_ATTRIBUTE_DEALLOC_FREE;
  784. #endif
  785. /* ==== Inline function definitions ==== */
  786. GL_XSTRING_DESC_INLINE string_desc_t
  787. -xstring_desc_new (idx_t n)
  788. +xsd_new (idx_t n)
  789. {
  790. string_desc_t result;
  791. - if (string_desc_new (&result, n) < 0)
  792. + if (sd_new (&result, n) < 0)
  793. xalloc_die ();
  794. return result;
  795. }
  796. GL_XSTRING_DESC_INLINE string_desc_t
  797. -xstring_desc_new_filled (idx_t n, char c)
  798. +xsd_new_filled (idx_t n, char c)
  799. {
  800. string_desc_t result;
  801. - if (string_desc_new_filled (&result, n, c) < 0)
  802. + if (sd_new_filled (&result, n, c) < 0)
  803. xalloc_die ();
  804. return result;
  805. }
  806. GL_XSTRING_DESC_INLINE string_desc_t
  807. -xstring_desc_copy (string_desc_t s)
  808. +xsd_copy (string_desc_t s)
  809. {
  810. string_desc_t result;
  811. - if (string_desc_copy (&result, s) < 0)
  812. + if (sd_copy (&result, s) < 0)
  813. xalloc_die ();
  814. return result;
  815. }
  816. @@ -97,9 +97,9 @@ xstring_desc_copy (string_desc_t s)
  817. GL_XSTRING_DESC_INLINE
  818. _GL_ATTRIBUTE_DEALLOC_FREE
  819. char *
  820. -xstring_desc_c (string_desc_t s)
  821. +xsd_c (string_desc_t s)
  822. {
  823. - char *result = string_desc_c (s);
  824. + char *result = sd_c (s);
  825. if (result == NULL)
  826. xalloc_die ();
  827. return result;
  828. --- a/tests/test-string-desc-quotearg.c
  829. +++ b/tests/test-string-desc-quotearg.c
  830. @@ -28,75 +28,75 @@
  831. int
  832. main (void)
  833. {
  834. - string_desc_t s1 = string_desc_from_c ("Hello world!");
  835. - string_desc_t s2 = string_desc_new_addr (21, "The\0quick\0brown\0\0fox");
  836. + string_desc_t s1 = sd_from_c ("Hello world!");
  837. + string_desc_t s2 = sd_new_addr (21, "The\0quick\0brown\0\0fox");
  838. - /* Test string_desc_quotearg_buffer. */
  839. + /* Test sd_quotearg_buffer. */
  840. {
  841. char buf[80];
  842. - size_t n = string_desc_quotearg_buffer (buf, sizeof (buf), s2, NULL);
  843. + size_t n = sd_quotearg_buffer (buf, sizeof (buf), s2, NULL);
  844. ASSERT (n == 21);
  845. ASSERT (memcmp (buf, "The\0quick\0brown\0\0fox", n) == 0);
  846. }
  847. - /* Test string_desc_quotearg_alloc. */
  848. + /* Test sd_quotearg_alloc. */
  849. {
  850. size_t n;
  851. - char *ret = string_desc_quotearg_alloc (s2, &n, NULL);
  852. + char *ret = sd_quotearg_alloc (s2, &n, NULL);
  853. ASSERT (n == 21);
  854. ASSERT (memcmp (ret, "The\0quick\0brown\0\0fox", n) == 0);
  855. free (ret);
  856. }
  857. - /* Test string_desc_quotearg_n. */
  858. + /* Test sd_quotearg_n. */
  859. {
  860. - char *ret = string_desc_quotearg_n (1, s2);
  861. + char *ret = sd_quotearg_n (1, s2);
  862. ASSERT (memcmp (ret, "Thequickbrownfox", 16 + 1) == 0);
  863. }
  864. - /* Test string_desc_quotearg. */
  865. + /* Test sd_quotearg. */
  866. {
  867. - char *ret = string_desc_quotearg (s2);
  868. + char *ret = sd_quotearg (s2);
  869. ASSERT (memcmp (ret, "Thequickbrownfox", 16 + 1) == 0);
  870. }
  871. - /* Test string_desc_quotearg_n_style. */
  872. + /* Test sd_quotearg_n_style. */
  873. {
  874. - char *ret = string_desc_quotearg_n_style (1, clocale_quoting_style, s2);
  875. + char *ret = sd_quotearg_n_style (1, clocale_quoting_style, s2);
  876. ASSERT (memcmp (ret, "\"The\\0quick\\0brown\\0\\0fox\\0\"", 28 + 1) == 0
  877. || /* if the locale has UTF-8 encoding */
  878. memcmp (ret, "\342\200\230The\\0quick\\0brown\\0\\0fox\\0\342\200\231", 32 + 1) == 0);
  879. }
  880. - /* Test string_desc_quotearg_style. */
  881. + /* Test sd_quotearg_style. */
  882. {
  883. - char *ret = string_desc_quotearg_style (clocale_quoting_style, s2);
  884. + char *ret = sd_quotearg_style (clocale_quoting_style, s2);
  885. ASSERT (memcmp (ret, "\"The\\0quick\\0brown\\0\\0fox\\0\"", 28 + 1) == 0
  886. || /* if the locale has UTF-8 encoding */
  887. memcmp (ret, "\342\200\230The\\0quick\\0brown\\0\\0fox\\0\342\200\231", 32 + 1) == 0);
  888. }
  889. - /* Test string_desc_quotearg_char. */
  890. + /* Test sd_quotearg_char. */
  891. {
  892. - char *ret = string_desc_quotearg_char (s1, ' ');
  893. + char *ret = sd_quotearg_char (s1, ' ');
  894. ASSERT (memcmp (ret, "Hello world!", 12 + 1) == 0); /* ' ' not quoted?! */
  895. }
  896. - /* Test string_desc_quotearg_colon. */
  897. + /* Test sd_quotearg_colon. */
  898. {
  899. - char *ret = string_desc_quotearg_colon (string_desc_from_c ("a:b"));
  900. + char *ret = sd_quotearg_colon (sd_from_c ("a:b"));
  901. ASSERT (memcmp (ret, "a:b", 3 + 1) == 0); /* ':' not quoted?! */
  902. }
  903. - /* Test string_desc_quotearg_n_custom. */
  904. + /* Test sd_quotearg_n_custom. */
  905. {
  906. - char *ret = string_desc_quotearg_n_custom (2, "<", ">", s1);
  907. + char *ret = sd_quotearg_n_custom (2, "<", ">", s1);
  908. ASSERT (memcmp (ret, "<Hello world!>", 14 + 1) == 0);
  909. }
  910. - /* Test string_desc_quotearg_n_custom. */
  911. + /* Test sd_quotearg_n_custom. */
  912. {
  913. - char *ret = string_desc_quotearg_custom ("[[", "]]", s1);
  914. + char *ret = sd_quotearg_custom ("[[", "]]", s1);
  915. ASSERT (memcmp (ret, "[[Hello world!]]", 16 + 1) == 0);
  916. }
  917. --- a/tests/test-string-desc.sh
  918. +++ b/tests/test-string-desc.sh
  919. @@ -6,7 +6,7 @@ ${CHECKER} test-string-desc${EXEEXT} tes
  920. printf 'Hello world!The\0quick\0brown\0\0fox\0' > test-string-desc.ok
  921. : "${DIFF=diff}"
  922. -${DIFF} test-string-desc.ok test-string-desc-1.tmp || { echo "string_desc_fwrite KO" 1>&2; Exit 1; }
  923. -${DIFF} test-string-desc.ok test-string-desc-3.tmp || { echo "string_desc_write KO" 1>&2; Exit 1; }
  924. +${DIFF} test-string-desc.ok test-string-desc-1.tmp || { echo "sd_fwrite KO" 1>&2; Exit 1; }
  925. +${DIFF} test-string-desc.ok test-string-desc-3.tmp || { echo "sd_write KO" 1>&2; Exit 1; }
  926. Exit 0
  927. --- a/tests/test-xstring-desc.c
  928. +++ b/tests/test-xstring-desc.c
  929. @@ -28,53 +28,53 @@
  930. int
  931. main (void)
  932. {
  933. - string_desc_t s0 = string_desc_new_empty ();
  934. - string_desc_t s1 = string_desc_from_c ("Hello world!");
  935. - string_desc_t s2 = string_desc_new_addr (21, "The\0quick\0brown\0\0fox");
  936. + string_desc_t s0 = sd_new_empty ();
  937. + string_desc_t s1 = sd_from_c ("Hello world!");
  938. + string_desc_t s2 = sd_new_addr (21, "The\0quick\0brown\0\0fox");
  939. - /* Test xstring_desc_new. */
  940. - string_desc_t s4 = xstring_desc_new (5);
  941. - string_desc_set_char_at (s4, 0, 'H');
  942. - string_desc_set_char_at (s4, 4, 'o');
  943. - string_desc_set_char_at (s4, 1, 'e');
  944. - string_desc_fill (s4, 2, 4, 'l');
  945. - ASSERT (string_desc_length (s4) == 5);
  946. - ASSERT (string_desc_startswith (s1, s4));
  947. + /* Test xsd_new. */
  948. + string_desc_t s4 = xsd_new (5);
  949. + sd_set_char_at (s4, 0, 'H');
  950. + sd_set_char_at (s4, 4, 'o');
  951. + sd_set_char_at (s4, 1, 'e');
  952. + sd_fill (s4, 2, 4, 'l');
  953. + ASSERT (sd_length (s4) == 5);
  954. + ASSERT (sd_startswith (s1, s4));
  955. - /* Test xstring_desc_new_filled. */
  956. - string_desc_t s5 = xstring_desc_new_filled (5, 'l');
  957. - string_desc_set_char_at (s5, 0, 'H');
  958. - string_desc_set_char_at (s5, 4, 'o');
  959. - string_desc_set_char_at (s5, 1, 'e');
  960. - ASSERT (string_desc_length (s5) == 5);
  961. - ASSERT (string_desc_startswith (s1, s5));
  962. + /* Test xsd_new_filled. */
  963. + string_desc_t s5 = xsd_new_filled (5, 'l');
  964. + sd_set_char_at (s5, 0, 'H');
  965. + sd_set_char_at (s5, 4, 'o');
  966. + sd_set_char_at (s5, 1, 'e');
  967. + ASSERT (sd_length (s5) == 5);
  968. + ASSERT (sd_startswith (s1, s5));
  969. - /* Test xstring_desc_copy. */
  970. + /* Test xsd_copy. */
  971. {
  972. - string_desc_t s6 = xstring_desc_copy (s0);
  973. - ASSERT (string_desc_is_empty (s6));
  974. - string_desc_free (s6);
  975. + string_desc_t s6 = xsd_copy (s0);
  976. + ASSERT (sd_is_empty (s6));
  977. + sd_free (s6);
  978. }
  979. {
  980. - string_desc_t s6 = xstring_desc_copy (s2);
  981. - ASSERT (string_desc_equals (s6, s2));
  982. - string_desc_free (s6);
  983. + string_desc_t s6 = xsd_copy (s2);
  984. + ASSERT (sd_equals (s6, s2));
  985. + sd_free (s6);
  986. }
  987. - /* Test xstring_desc_concat. */
  988. + /* Test xsd_concat. */
  989. {
  990. string_desc_t s8 =
  991. - xstring_desc_concat (3, string_desc_new_addr (10, "The\0quick"),
  992. - string_desc_new_addr (7, "brown\0"),
  993. - string_desc_new_addr (4, "fox"),
  994. - string_desc_new_addr (7, "unused"));
  995. - ASSERT (string_desc_equals (s8, s2));
  996. - string_desc_free (s8);
  997. + xsd_concat (3, sd_new_addr (10, "The\0quick"),
  998. + sd_new_addr (7, "brown\0"),
  999. + sd_new_addr (4, "fox"),
  1000. + sd_new_addr (7, "unused"));
  1001. + ASSERT (sd_equals (s8, s2));
  1002. + sd_free (s8);
  1003. }
  1004. - /* Test xstring_desc_c. */
  1005. + /* Test xsd_c. */
  1006. {
  1007. - char *ptr = xstring_desc_c (s2);
  1008. + char *ptr = xsd_c (s2);
  1009. ASSERT (ptr != NULL);
  1010. ASSERT (memcmp (ptr, "The\0quick\0brown\0\0fox\0", 22) == 0);
  1011. free (ptr);