public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] strstrip API
@ 2006-04-25  9:11 Pekka Enberg
  2006-04-25 20:35 ` Ingo Oeser
  0 siblings, 1 reply; 3+ messages in thread
From: Pekka Enberg @ 2006-04-25  9:11 UTC (permalink / raw)
  To: akpm; +Cc: holzheu, ioe-lkml, joern, minyard, linux-kernel

From: Pekka Enberg <penberg@cs.helsinki.fi>

This patch adds a new strstrip() function to lib/string.c for removing
leading and trailing whitespace from a string.

Cc: Michael Holzheu <holzheu@de.ibm.com>
Cc: Ingo Oeser <ioe-lkml@rameria.de>
Cc: Jörn Engel <joern@wohnheim.fh-wedel.de>
Cc: Corey Minyard <minyard@acm.org>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>

---

 include/linux/string.h |    1 +
 lib/string.c           |   30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)

1a360da62131fb81460ca4abf93d20b9d0d390ff
diff --git a/include/linux/string.h b/include/linux/string.h
index c61306d..e4c7558 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -56,6 +56,7 @@ #endif
 #ifndef __HAVE_ARCH_STRRCHR
 extern char * strrchr(const char *,int);
 #endif
+extern char * strstrip(char *);
 #ifndef __HAVE_ARCH_STRSTR
 extern char * strstr(const char *,const char *);
 #endif
diff --git a/lib/string.c b/lib/string.c
index 064f631..6307726 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -301,6 +301,36 @@ char *strnchr(const char *s, size_t coun
 EXPORT_SYMBOL(strnchr);
 #endif
 
+/**
+ * strstrip - Removes leading and trailing whitespace from @s.
+ * @s: The string to be stripped.
+ *
+ * Note that the first trailing whitespace is replaced with a %NUL-terminator
+ * in the given string @s. Returns a pointer to the first non-whitespace
+ * character in @s.
+ */
+char *strstrip(char *s)
+{
+	size_t size;
+	char *end;
+
+	size = strlen(s);
+
+	if (!size)
+		return s;
+
+	end = s + size - 1;
+	while (end != s && isspace(*end))
+		end--;
+	*(end + 1) = '\0';
+
+	while (*s && isspace(*s))
+		s++;
+
+	return s;
+}
+EXPORT_SYMBOL(strstrip);
+
 #ifndef __HAVE_ARCH_STRLEN
 /**
  * strlen - Find the length of a string
-- 
1.3.0




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] strstrip API
  2006-04-25  9:11 [PATCH 1/2] strstrip API Pekka Enberg
@ 2006-04-25 20:35 ` Ingo Oeser
  2006-04-26  9:36   ` Jörn Engel
  0 siblings, 1 reply; 3+ messages in thread
From: Ingo Oeser @ 2006-04-25 20:35 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: akpm, holzheu, joern, minyard, linux-kernel

Hi Pekka,

On Tuesday, 25. April 2006 11:11, Pekka Enberg wrote:
> From: Pekka Enberg <penberg@cs.helsinki.fi>
> 
> This patch adds a new strstrip() function to lib/string.c for removing
> leading and trailing whitespace from a string.
> 
> Cc: Michael Holzheu <holzheu@de.ibm.com>
> Cc: Ingo Oeser <ioe-lkml@rameria.de>
> Cc: Jörn Engel <joern@wohnheim.fh-wedel.de>
> Cc: Corey Minyard <minyard@acm.org>
> Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>

Acked-by: Ingo Oeser <ioe-lkml@rameria.de>

Simple enough and fits all users so far.
Good work!


Regards

Ingo Oeser

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] strstrip API
  2006-04-25 20:35 ` Ingo Oeser
@ 2006-04-26  9:36   ` Jörn Engel
  0 siblings, 0 replies; 3+ messages in thread
From: Jörn Engel @ 2006-04-26  9:36 UTC (permalink / raw)
  To: Ingo Oeser; +Cc: Pekka Enberg, akpm, holzheu, minyard, linux-kernel

On Tue, 25 April 2006 22:35:24 +0200, Ingo Oeser wrote:
> On Tuesday, 25. April 2006 11:11, Pekka Enberg wrote:
> > From: Pekka Enberg <penberg@cs.helsinki.fi>
> > 
> > This patch adds a new strstrip() function to lib/string.c for removing
> > leading and trailing whitespace from a string.
> > 
> > Cc: Michael Holzheu <holzheu@de.ibm.com>
> > Cc: Ingo Oeser <ioe-lkml@rameria.de>
> > Cc: Jörn Engel <joern@wohnheim.fh-wedel.de>
> > Cc: Corey Minyard <minyard@acm.org>
> > Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
> 
> Acked-by: Ingo Oeser <ioe-lkml@rameria.de>
Acked-by: Joern Engel <joern@wh.fh-wedel.de>

> Simple enough and fits all users so far.
> Good work!

Agreed.

Jörn

-- 
When in doubt, use brute force.
-- Ken Thompson

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-04-26  9:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-25  9:11 [PATCH 1/2] strstrip API Pekka Enberg
2006-04-25 20:35 ` Ingo Oeser
2006-04-26  9:36   ` Jörn Engel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox