[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gnulib] new module proposal: strip

From: Bruno Haible
Subject: Re: [bug-gnulib] new module proposal: strip
Date: Fri, 1 Sep 2006 18:58:25 +0200
User-agent: KMail/1.9.1

[Re-added bug-gnulib in CC.]

Davide Angelocola wrote:
> On Friday 01 September 2006 15:01, you wrote:
> > About the function names: 'chug' and 'chomp' are not self-documenting
> > function names either. I'd propose trim_trailing and trim_leading.
> > (The Lisp name string-left-trim and string-right-trim come from a time
> > when people did not think about bidi.)
> done
> > About mbiter.h: If you can not understand the mbiter.h functions, then
> > can you please point out what can be improved about its documentation?
> > I'd like to improve the comments in mbiter.h then.
> I need a macro/function that instead of advand go backward. The 
> documentation is good but I don't figure out to resolve this issue.
> (see the comments in the code)
> Basically I've tried to re-inizialize the multi byte iterator but it doesn't 
> works. Can you fix it?
> > Using strdup is ok, but you need to check that its return value is not
> > NULL. We often use xstrdup instead, which incorporates this extra check.
> done
> > Also, trim2 does IMO not need to check against a NULL argument. Basic
> > string functions such as strlen and strcmp expect non-NULL arguments;
> > why should 'trim' then allow a NULL argument?
> done
> > About the copyright header: Please use as starting year the year when
> > you wrote the first line of code still present in the current code.
> > You didn't start it in 1996, did you? - The copyright header is otherwise
> > ok. At some point, you will have to file copyright assignment papers for
> > your contributions to gnulib, giving the copyright ownership to the FSF.
> done
> -- Davide Angelocola

Thanks; it looks already better.

In multibyte strings you cannot "go backwards". You have to write the
algorithm in a way that progresses from the first to the last multibyte
character. (*) In this case, you can do so by moving from first to last,
memorizing the position of the last non-whitespace character. More
precisely, a pointer pointing after this character. When you have
reached the end of the string, you put a '\0' where the memoized pointer
points to, and are done.

(*) If you have an algorithm which really needs to "go backwards",
you need to convert the entire string to a wide-character string,
process the wide-character string, and then convert back to multibyte.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]