Re: [PATCH 2/6] strbuf: add string-chomping functions

2013-01-29 Thread Michael Haggerty
On 01/29/2013 10:15 AM, Jeff King wrote:
 Sometimes it is handy to cut a trailing string off the end
 of a strbuf (e.g., a file extension). These helper functions
 make it a one-liner.
 
 Signed-off-by: Jeff King p...@peff.net
 ---
  strbuf.c | 11 +++
  strbuf.h |  2 ++
  2 files changed, 13 insertions(+)
 
 diff --git a/strbuf.c b/strbuf.c
 index 9a373be..8199ced 100644
 --- a/strbuf.c
 +++ b/strbuf.c
 @@ -106,6 +106,17 @@ void strbuf_ltrim(struct strbuf *sb)
   sb-buf[sb-len] = '\0';
  }
  
 +void strbuf_chompmem(struct strbuf *sb, const void *data, size_t len)
 +{
 + if (sb-len = len  !memcmp(data, sb-buf + sb-len - len, len))
 + strbuf_setlen(sb, sb-len - len);
 +}
 +
 +void strbuf_chompstr(struct strbuf *sb, const char *str)
 +{
 + strbuf_chompmem(sb, str, strlen(str));
 +}
 +
  struct strbuf **strbuf_split_buf(const char *str, size_t slen,
int terminator, int max)
  {
 diff --git a/strbuf.h b/strbuf.h
 index ecae4e2..3aeb815 100644
 --- a/strbuf.h
 +++ b/strbuf.h
 @@ -42,6 +42,8 @@ extern void strbuf_ltrim(struct strbuf *);
  extern void strbuf_trim(struct strbuf *);
  extern void strbuf_rtrim(struct strbuf *);
  extern void strbuf_ltrim(struct strbuf *);
 +extern void strbuf_chompmem(struct strbuf *, const void *, size_t);
 +extern void strbuf_chompstr(struct strbuf *, const char *);
  extern int strbuf_cmp(const struct strbuf *, const struct strbuf *);
  
  /*
 

It might be handy to have these functions return true/false based on
whether the suffix was actually found.

Please document the new functions in
Documentation/technical/api-strbuf.txt.  Personally I would also
advocate a docstring in the header file, but obviously that preference
is the exception rather than the rule in the git project :-(

Michael

-- 
Michael Haggerty
mhag...@alum.mit.edu
http://softwareswirl.blogspot.com/
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/6] strbuf: add string-chomping functions

2013-01-29 Thread Jeff King
On Tue, Jan 29, 2013 at 11:15:34AM +0100, Michael Haggerty wrote:

  +void strbuf_chompmem(struct strbuf *sb, const void *data, size_t len)
  +{
  +   if (sb-len = len  !memcmp(data, sb-buf + sb-len - len, len))
  +   strbuf_setlen(sb, sb-len - len);
  +}
  +
  +void strbuf_chompstr(struct strbuf *sb, const char *str)
  +{
  +   strbuf_chompmem(sb, str, strlen(str));
  +}
  +
 It might be handy to have these functions return true/false based on
 whether the suffix was actually found.

Yeah, that sounds reasonable.

 Please document the new functions in
 Documentation/technical/api-strbuf.txt.  Personally I would also
 advocate a docstring in the header file, but obviously that preference
 is the exception rather than the rule in the git project :-(

Will do. I need to document the metapack functions, too, so I was thinking
about experimenting with some inline documentation systems.

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


Re: [PATCH 2/6] strbuf: add string-chomping functions

2013-01-29 Thread Michael Haggerty
On 01/29/2013 12:10 PM, Jeff King wrote:
 On Tue, Jan 29, 2013 at 11:15:34AM +0100, Michael Haggerty wrote:
 Please document the new functions in
 Documentation/technical/api-strbuf.txt.  Personally I would also
 advocate a docstring in the header file, but obviously that preference
 is the exception rather than the rule in the git project :-(
 
 Will do. I need to document the metapack functions, too, so I was thinking
 about experimenting with some inline documentation systems.

That would be great; it would make future API documentation much easier
and therefore (hopefully) more common.

Michael

-- 
Michael Haggerty
mhag...@alum.mit.edu
http://softwareswirl.blogspot.com/
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html