mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ingo Oeser <ioe-lkml@rameria.de>
To: "Pekka Enberg" <penberg@cs.helsinki.fi>
Cc: "Michael Holzheu" <holzheu@de.ibm.com>,
	linux-kernel@vger.kernel.org, schwidefsky@de.ibm.com
Subject: Re: [PATCH/RFC] s390: Hypervisor File System
Date: Sat, 22 Apr 2006 00:30:28 +0200	[thread overview]
Message-ID: <200604220030.29214.ioe-lkml@rameria.de> (raw)
In-Reply-To: <84144f020604210742j69222654s5ec68f34ea96999c@mail.gmail.com>

Hi Pekka, 

On Friday, 21. April 2006 16:42, Pekka Enberg wrote:
> On 4/21/06, Michael Holzheu <holzheu@de.ibm.com> wrote:
> > diff -urpN linux-2.6.16/fs/hypfs/hypfs.h linux-2.6.16-hypfs/fs/hypfs/hypfs.h
> > --- linux-2.6.16/fs/hypfs/hypfs.h	1970-01-01 01:00:00.000000000 +0100
> > +++ linux-2.6.16-hypfs/fs/hypfs/hypfs.h	2006-04-21 12:56:58.000000000 +0200
> > +static void inline remove_trailing_blanks(char *string)
> > +{
> > +	char *ptr;
> > +	for (ptr = string + strlen(string) - 1; ptr > string; ptr--) {
> > +		if (*ptr == ' ')
> > +			*ptr = 0;
> > +		else
> > +			break;
> > +	}
> > +}
> 
> Please consider moving this to lib/string.c and perhaps renaming it to
> strstrip().

Nearly.

- Just return the *ptr and let the caller modify the string.
- Take a string with characters to reject

Reasons: 
	- string might be read only
	- caller wants to copy it anyway
	- string might be a substring or sth. we like to parse further
	- Symmetry with strchr()

Otherwise it is a very good idea implemented in a patch similiar to this
untested one below against Linus' current tree.

use case would be:
char *s = strltrim(string, " \t");
char *e = strrtrim(s, " \t\n\r");
*e = '\0';

Regards

Ingo Oeser
----

diff --git a/include/linux/string.h b/include/linux/string.h
index c61306d..fc90a70 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -68,6 +68,12 @@ extern __kernel_size_t strnlen(const cha
 #ifndef __HAVE_ARCH_STRPBRK
 extern char * strpbrk(const char *,const char *);
 #endif
+#ifndef __HAVE_ARCH_STRLTRIM
+extern char * strltrim(const char *,const char *);
+#endif
+#ifndef __HAVE_ARCH_STRRTRIM
+extern char * strrtrim(const char *,const char *);
+#endif
 #ifndef __HAVE_ARCH_STRSEP
 extern char * strsep(char **,const char *);
 #endif
diff --git a/lib/string.c b/lib/string.c
index 064f631..4bdcd5e 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -408,6 +408,55 @@ char *strpbrk(const char *cs, const char
 EXPORT_SYMBOL(strpbrk);
 #endif
 
+#ifndef __HAVE_ARCH_STRLTRIM
+/**
+ * strltrim - Get pointer to first character of @s which is
+ * 	not contained in letters in @reject
+ * @s: The string to be searched
+ * @reject: The string of letters to avoid
+ */
+char *strltrim(const char *s, const char *reject)
+{
+	const char *p;
+	const char *r;
+
+	for (p = s; p != '\0'; ++p) {
+		for (r = reject; *r != '\0'; ++r) {
+			if (*p == *r)
+				continue;
+		}
+		return (char *)p;
+	}
+	return (char *)s;
+}
+EXPORT_SYMBOL(strltrim);
+#endif
+
+#ifndef __HAVE_ARCH_STRRTRIM
+/**
+ * strrtrim - Get pointer to last character of @s which is
+ * 	not contained in letters in @reject
+ * @s: The string to be searched
+ * @reject: The string of letters to avoid
+ */
+char *strrtrim(const char *s, const char *reject)
+{
+	const char *end = s + strlen(s);
+	const char *p;
+	const char *r;
+
+	for (p = end - 1; s <= p; --p) {
+		for (r = reject; *r != '\0'; ++r) {
+			if (*p == *r)
+				continue;
+		}
+		return (char *)p;
+	}
+	return (char *)end;
+}
+EXPORT_SYMBOL(strrtrim);
+#endif
+
 #ifndef __HAVE_ARCH_STRSEP
 /**
  * strsep - Split a string into tokens

  parent reply	other threads:[~2006-04-21 22:32 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-21 11:35 Michael Holzheu
2006-04-21 11:53 ` Pekka Enberg
2006-04-21 13:56   ` Michael Holzheu
2006-04-21 14:55     ` Arnd Bergmann
2006-04-21 15:31       ` Michael Holzheu
2006-04-21 13:32 ` Pekka Enberg
2006-04-21 14:08   ` Michael Holzheu
2006-04-21 15:38     ` Pekka Enberg
2006-04-21 16:40       ` Martin Schwidefsky
2006-04-25 14:04         ` Pekka Enberg
2006-04-21 14:42 ` Pekka Enberg
2006-04-21 14:59   ` Michael Holzheu
2006-04-21 15:41     ` Pekka Enberg
2006-04-21 15:18   ` Jörn Engel
2006-04-21 15:36     ` Michael Holzheu
2006-04-21 15:46       ` Jörn Engel
2006-04-21 22:30   ` Ingo Oeser [this message]
2006-04-24 17:17     ` Michael Holzheu
2006-04-24 19:57       ` Ingo Oeser
2006-04-25  6:27       ` Pekka Enberg
2006-04-24 17:19   ` Michael Holzheu
2006-04-24 17:19 Michael Holzheu
2006-04-25  6:58 ` Pekka Enberg
2006-04-25  7:32   ` Pekka Enberg
2006-04-25  7:47     ` Andrew Morton
2006-04-25  8:01       ` Pekka Enberg
2006-04-25  8:52     ` Jörn Engel
2006-04-25  9:00       ` Pekka Enberg
2006-04-25 12:22     ` Michael Holzheu
2006-04-25 14:33 ` Pekka Enberg
2006-04-25 14:45   ` Jörn Engel
2006-04-26  9:30   ` Michael Holzheu

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=200604220030.29214.ioe-lkml@rameria.de \
    --to=ioe-lkml@rameria.de \
    --cc=holzheu@de.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penberg@cs.helsinki.fi \
    --cc=schwidefsky@de.ibm.com \
    /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

all inboxes | Powered by JetHome®