linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org, dsterba@suse.cz
Subject: [PATCH v3 1/4] btrfs-progs: utils: Introduce function to escape characters
Date: Tue,  1 Nov 2016 16:01:43 +0800	[thread overview]
Message-ID: <20161101080147.13163-2-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <20161101080147.13163-1-quwenruo@cn.fujitsu.com>

Introduce new function, escape_string_inplace(), to escape specified
characters in place.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 utils.c | 17 +++++++++++++++++
 utils.h |  2 ++
 2 files changed, 19 insertions(+)

diff --git a/utils.c b/utils.c
index 3f54245..69faae1 100644
--- a/utils.c
+++ b/utils.c
@@ -4251,3 +4251,20 @@ unsigned int rand_range(unsigned int upper)
 	 */
 	return (unsigned int)(jrand48(rand_seed) % upper);
 }
+
+void string_escape_inplace(char *restrict string, char *restrict escape_chars)
+{
+	int i, j;
+
+	for (i = 0; i < strlen(escape_chars); i++) {
+		j = 0;
+		while (j < strlen(string)) {
+			if (string[j] == escape_chars[i]) {
+				memmove(string + j, string + j + 1,
+					strlen(string) -j);
+				continue;
+			}
+			j++;
+		}
+	}
+}
diff --git a/utils.h b/utils.h
index 1a2dbcd..b36d411 100644
--- a/utils.h
+++ b/utils.h
@@ -457,4 +457,6 @@ unsigned int rand_range(unsigned int upper);
 /* Also allow setting the seed manually */
 void init_rand_seed(u64 seed);
 
+void string_escape_inplace(char *restrict string, char *restrict escape_chars);
+
 #endif
-- 
2.10.1




  reply	other threads:[~2016-11-01  8:02 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-01  8:01 [PATCH v3 0/4] Introduce dump option for btrfs-receive Qu Wenruo
2016-11-01  8:01 ` Qu Wenruo [this message]
2016-11-01 10:08   ` [PATCH v3 1/4] btrfs-progs: utils: Introduce function to escape characters David Sterba
2016-11-02  1:19     ` Qu Wenruo
2016-11-02 10:55       ` David Sterba
2016-11-03  0:24         ` Qu Wenruo
2016-11-03  1:14         ` Qu Wenruo
2016-11-01  8:01 ` [PATCH v3 2/4] btrfs-progs: introduce new send-dump object Qu Wenruo
2016-11-01 10:22   ` David Sterba
2016-11-02  0:37     ` Qu Wenruo
2016-11-02 10:52       ` David Sterba
2016-11-03  0:21         ` Qu Wenruo
2016-11-01  8:01 ` [PATCH v3 3/4] btrfs-progs: receive: introduce option to dump send stream Qu Wenruo
2016-11-01  8:01 ` [PATCH v3 4/4] btrfs-progs: remove send-test tool Qu Wenruo
2016-11-02 14:59   ` David Sterba
2016-11-01  8:01 ` [PATCH 5/5] btrfs-progs: misc-test: Add send stream dump test Qu Wenruo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161101080147.13163-2-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).