ne_buffer_append.3 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. '\" t
  2. .\" Title: ne_buffer_append
  3. .\" Author:
  4. .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
  5. .\" Date: 23 November 2025
  6. .\" Manual: neon API reference
  7. .\" Source: neon 0.36.0
  8. .\" Language: English
  9. .\"
  10. .TH "NE_BUFFER_APPEND" "3" "23 November 2025" "neon 0.36.0" "neon API reference"
  11. .\" -----------------------------------------------------------------
  12. .\" * Define some portability stuff
  13. .\" -----------------------------------------------------------------
  14. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  15. .\" http://bugs.debian.org/507673
  16. .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
  17. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. .ie \n(.g .ds Aq \(aq
  19. .el .ds Aq '
  20. .\" -----------------------------------------------------------------
  21. .\" * set default formatting
  22. .\" -----------------------------------------------------------------
  23. .\" disable hyphenation
  24. .nh
  25. .\" disable justification (adjust text to left margin only)
  26. .ad l
  27. .\" -----------------------------------------------------------------
  28. .\" * MAIN CONTENT STARTS HERE *
  29. .\" -----------------------------------------------------------------
  30. .SH "NAME"
  31. ne_buffer_append, ne_buffer_zappend, ne_buffer_qappend, ne_buffer_concat, ne_buffer_snprintf \- append data to a string buffer
  32. .SH "SYNOPSIS"
  33. .sp
  34. .ft B
  35. .nf
  36. #include <ne_string\&.h>
  37. .fi
  38. .ft
  39. .HP \w'void\ ne_buffer_append('u
  40. .BI "void ne_buffer_append(ne_buffer\ *" "buf" ", const\ char\ *" "string" ", size_t\ " "len" ");"
  41. .HP \w'void\ ne_buffer_zappend('u
  42. .BI "void ne_buffer_zappend(ne_buffer\ *" "buf" ", const\ char\ *" "string" ");"
  43. .HP \w'void\ ne_buffer_qappend('u
  44. .BI "void ne_buffer_qappend(ne_buffer\ *" "buf" ", const\ char\ *" "string" ", size_t\ " "len" ");"
  45. .HP \w'void\ ne_buffer_concat('u
  46. .BI "void ne_buffer_concat(ne_buffer\ *" "buf" ", \&.\&.\&.);"
  47. .HP \w'size_t\ ne_buffer_snprintf('u
  48. .BI "size_t ne_buffer_snprintf(ne_buffer\ *" "buf" ", size_t\ " "max" ", const\ char\ *" "format" ", \&.\&.\&.);"
  49. .SH "DESCRIPTION"
  50. .PP
  51. The
  52. \fBne_buffer_append\fR
  53. and
  54. \fBne_buffer_zappend\fR
  55. functions append a string to the end of a buffer; extending the buffer as necessary\&. The
  56. \fIlen\fR
  57. passed to
  58. \fBne_buffer_append\fR
  59. specifies the length of the string to append; there must be no
  60. NUL
  61. terminator in the first
  62. \fIlen\fR
  63. bytes of the string\&.
  64. \fBne_buffer_zappend\fR
  65. must be passed a
  66. NUL\-terminated string\&.
  67. .PP
  68. The
  69. \fBne_buffer_qappend\fR
  70. function behaves similarly to
  71. \fBne_buffer_append\fR, except that any non\-ASCII characters or ASCII control characters are escaped using C\-style hex escaping\&. For example, the C string
  72. "foo<TAB>bar", where TAB represents ASCII character 9, would be appended as
  73. "foo\ex09bar"\&. Any
  74. NUL
  75. bytes within the length specified are also escaped\&. This function is useful to make strings from untrusted sources safe for logging or output in a user interface\&.
  76. .PP
  77. The
  78. \fBne_buffer_concat\fR
  79. function takes a variable\-length argument list; each argument must be a
  80. \fBchar *\fR
  81. pointer to a
  82. NUL\-terminated string\&. A
  83. NULL
  84. pointer must be given as the last argument to mark the end of the list\&. The strings are appended to the buffer in the order given\&. None of the strings passed to
  85. \fBne_buffer_concat\fR
  86. are modified\&.
  87. .PP
  88. The
  89. \fBne_buffer_snprintf\fR
  90. function behaves like
  91. \fBsnprintf\fR, appending the output string formatted according to the
  92. \fIformat\fR
  93. parameter\&. At most
  94. \fImax\fR
  95. bytes are written including the trailing
  96. NUL
  97. terminator\&.
  98. .SH "RETURN VALUE"
  99. .PP
  100. The
  101. \fBne_buffer_snprintf\fR
  102. function returns the number of bytes appended
  103. \fIexcluding\fR
  104. the trailing
  105. NUL
  106. terminator\&.
  107. .SH "EXAMPLES"
  108. .PP
  109. The following code will output "Hello, world\&. And goodbye\&."\&.
  110. .sp
  111. .if n \{\
  112. .RS 4
  113. .\}
  114. .nf
  115. ne_buffer *buf = ne_buffer_create();
  116. ne_buffer_zappend(buf, "Hello");
  117. ne_buffer_concat(buf, ", world\&. ", "And ", NULL);
  118. ne_buffer_snprintf(buf, 10, "%s\&.", "goodbye");
  119. puts(buf\->data);
  120. ne_buffer_destroy(buf);
  121. .fi
  122. .if n \{\
  123. .RE
  124. .\}
  125. .SH "SEE ALSO"
  126. .PP
  127. ne_buffer,
  128. ne_buffer_create,
  129. ne_buffer_destroy
  130. .SH "COPYRIGHT"
  131. .br
  132. Copyright \(co 2001-2025 Joe Orton
  133. .br