* [PATCH 1/2] strbuf: Use _rtrim and _ltrim in strbuf_trim
@ 2014-04-30 8:58 Brian Gesiak
2014-04-30 8:58 ` [PATCH 2/2] api-strbuf.txt: Add docs for _trim and _ltrim Brian Gesiak
2014-04-30 17:11 ` [PATCH 1/2] strbuf: Use _rtrim and _ltrim in strbuf_trim Jeff King
0 siblings, 2 replies; 3+ messages in thread
From: Brian Gesiak @ 2014-04-30 8:58 UTC (permalink / raw)
To: GIT Mailing-list; +Cc: Brian Gesiak
strbuf_trim strips whitespace from the end, then the beginning of a
strbuf. Those operations are duplicated in strbuf_rtrim and
strbuf_ltrim.
Replace strbuf_trim implementation with calls to strbuf_rtrim,
then strbuf_ltrim.
Signed-off-by: Brian Gesiak <modocache@gmail.com>
---
This is tangential to my GSoC project; I noticed the duplication
and thought it could be remedied.
strbuf.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/strbuf.c b/strbuf.c
index 83caf4a..382cf68 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -96,15 +96,8 @@ void strbuf_grow(struct strbuf *sb, size_t extra)
void strbuf_trim(struct strbuf *sb)
{
- char *b = sb->buf;
- while (sb->len > 0 && isspace((unsigned char)sb->buf[sb->len - 1]))
- sb->len--;
- while (sb->len > 0 && isspace(*b)) {
- b++;
- sb->len--;
- }
- memmove(sb->buf, b, sb->len);
- sb->buf[sb->len] = '\0';
+ strbuf_rtrim(sb);
+ strbuf_ltrim(sb);
}
void strbuf_rtrim(struct strbuf *sb)
{
--
1.9.2.507.g779792a
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] api-strbuf.txt: Add docs for _trim and _ltrim
2014-04-30 8:58 [PATCH 1/2] strbuf: Use _rtrim and _ltrim in strbuf_trim Brian Gesiak
@ 2014-04-30 8:58 ` Brian Gesiak
2014-04-30 17:11 ` [PATCH 1/2] strbuf: Use _rtrim and _ltrim in strbuf_trim Jeff King
1 sibling, 0 replies; 3+ messages in thread
From: Brian Gesiak @ 2014-04-30 8:58 UTC (permalink / raw)
To: GIT Mailing-list; +Cc: Brian Gesiak
API documentation for strbuf does not document strbuf_trim or
strbuf_ltrim. Add documentation for these two functions.
Signed-off-by: Brian Gesiak <modocache@gmail.com>
---
Documentation/technical/api-strbuf.txt | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/Documentation/technical/api-strbuf.txt b/Documentation/technical/api-strbuf.txt
index 3350d97..4396be9 100644
--- a/Documentation/technical/api-strbuf.txt
+++ b/Documentation/technical/api-strbuf.txt
@@ -121,10 +121,19 @@ Functions
* Related to the contents of the buffer
+`strbuf_trim`::
+
+ Strip whitespace from the beginning and end of a string.
+ Equivalent to performing `strbuf_rtrim()` followed by `strbuf_ltrim()`.
+
`strbuf_rtrim`::
Strip whitespace from the end of a string.
+`strbuf_ltrim`::
+
+ Strip whitespace from the beginning of a string.
+
`strbuf_cmp`::
Compare two buffers. Returns an integer less than, equal to, or greater
--
1.9.2.507.g779792a
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] strbuf: Use _rtrim and _ltrim in strbuf_trim
2014-04-30 8:58 [PATCH 1/2] strbuf: Use _rtrim and _ltrim in strbuf_trim Brian Gesiak
2014-04-30 8:58 ` [PATCH 2/2] api-strbuf.txt: Add docs for _trim and _ltrim Brian Gesiak
@ 2014-04-30 17:11 ` Jeff King
1 sibling, 0 replies; 3+ messages in thread
From: Jeff King @ 2014-04-30 17:11 UTC (permalink / raw)
To: Brian Gesiak; +Cc: GIT Mailing-list
On Wed, Apr 30, 2014 at 05:58:06PM +0900, Brian Gesiak wrote:
> strbuf_trim strips whitespace from the end, then the beginning of a
> strbuf. Those operations are duplicated in strbuf_rtrim and
> strbuf_ltrim.
>
> Replace strbuf_trim implementation with calls to strbuf_rtrim,
> then strbuf_ltrim.
Thanks, this looks good. I wondered if perhaps doing them together
inline might have been more efficient, but there really is no overlap in
what they compute.
The documentation patch looks good to me, too.
-Peff
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-04-30 17:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-30 8:58 [PATCH 1/2] strbuf: Use _rtrim and _ltrim in strbuf_trim Brian Gesiak
2014-04-30 8:58 ` [PATCH 2/2] api-strbuf.txt: Add docs for _trim and _ltrim Brian Gesiak
2014-04-30 17:11 ` [PATCH 1/2] strbuf: Use _rtrim and _ltrim in strbuf_trim Jeff King
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).