From c167562b38b13f09e208574c52152d62cf26c7f5 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 18 May 2024 23:09:23 +0200 Subject: [PATCH] docs: Describe g_strcompress processing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GVariant Text Format section on bytestrings links to `g_strcompress` but what it does was only briefly described in the header file, which is not visible in the gi-docgen-built reference. To really find out one would have to guess to continue through the rabbit hole to `g_strescape`. Let’s merge the description from the header and elaborate on it a bit. --- glib/gstrfuncs.c | 15 +++++++++++++-- glib/gstrfuncs.h | 4 ---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c index 861ccbd9e..122de736c 100644 --- a/glib/gstrfuncs.c +++ b/glib/gstrfuncs.c @@ -2109,9 +2109,20 @@ g_strcanon (gchar *string, * g_strcompress: * @source: a string to compress * - * Replaces all escaped characters with their one byte equivalent. + * Makes a copy of a string replacing C string-style escape + * sequences with their one byte equivalent: * - * This function does the reverse conversion of [func@GLib.strescape]. + * - `\b` → [U+0008 Backspace](https://en.wikipedia.org/wiki/Backspace) + * - `\f` → [U+000C Form Feed](https://en.wikipedia.org/wiki/Form_feed) + * - `\n` → [U+000A Line Feed](https://en.wikipedia.org/wiki/Newline) + * - `\r` → [U+000D Carriage Return](https://en.wikipedia.org/wiki/Carriage_return) + * - `\t` → [U+0009 Horizontal Tabulation](https://en.wikipedia.org/wiki/Tab_character) + * - `\v` → [U+000B Vertical Tabulation](https://en.wikipedia.org/wiki/Vertical_Tab) + * - `\` followed by one to three octal digits → the numeric value (mod 255) + * - `\` followed by any other character → the character as is. + * For example, `\\` will turn into a backslash (`\`) and `\"` into a double quote (`"`). + * + * [func@GLib.strescape] does the reverse conversion. * * Returns: a newly-allocated copy of @source with all escaped * character compressed diff --git a/glib/gstrfuncs.h b/glib/gstrfuncs.h index bd6a2c19b..9a0123724 100644 --- a/glib/gstrfuncs.h +++ b/glib/gstrfuncs.h @@ -327,10 +327,6 @@ g_strdup_inline (const char *str) #endif /* !defined (__GTK_DOC_IGNORE__) */ #endif /* G_GNUC_CHECK_VERSION (2, 0) */ -/* Make a copy of a string interpreting C string -style escape - * sequences. Inverse of g_strescape. The recognized sequences are \b - * \f \n \r \t \\ \" and the octal format. - */ GLIB_AVAILABLE_IN_ALL gchar* g_strcompress (const gchar *source) G_GNUC_MALLOC;