At 11/07/2016 06:20 PM, David Sterba wrote:
On Thu, Nov 03, 2016 at 12:07:31PM +0800, Qu Wenruo wrote:
Introduce new function, escape_string_inplace(), to escape specified
characters in place.

Signed-off-by: Qu Wenruo <quwen...@cn.fujitsu.com>
---
 utils.c | 24 ++++++++++++++++++++++++
 utils.h | 14 ++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/utils.c b/utils.c
index 3f54245..3c50d84 100644
--- a/utils.c
+++ b/utils.c
@@ -4251,3 +4251,27 @@ unsigned int rand_range(unsigned int upper)
         */
        return (unsigned int)(jrand48(rand_seed) % upper);
 }
+
+static void escape_one_char(char *restrict string, char escape)
+{
+       int i = 0;
+       int j = 0;
+
+       while (string[j] != '\0') {
+               if (string[j] != escape) {
+                       string[i] = string[j];
+                       i++;
+               }

So how does this actually escape the characters? I don't see anything
inserted. I think we don't have a common understanding of what's
supposed to be done here. I mean C-string-like escaping. And this cannot
be done inplace, as it increases string length. I've implemented it in a
different way, so this patch is left out. The final stream dump output
is preserved.


Oh, sorry.

I misunderstand the term "string escaping". I though it's just deleting special characters.

I checked your print_path_escaped() and finally got what string-escaping should do.

Sorry for the extra trouble.

While still some small comment.
+                         if (!isprint(c)) {
+                                 printf("\\%c%c%c",
+                                                 '0' + ((c & 0300) >> 6),
+                                                 '0' + ((c & 070) >> 3),
+                                                 '0' + (c & 07));

For non-printable chars, isn't it more common to print it as hex other than octal?

Thanks,
Qu


--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to