Re: [dev] [PATCH][RFC] Add a basic version of tr
* Silvan Jegen <s.jegen_AT_gmail.com> [2014-01-15 22:32:28 +0100]:
> On Wed, Jan 15, 2014 at 09:36:07PM +0100, Szabolcs Nagy wrote:
> > > +handleescapes(char *s)
> > > +{
> > > + switch(*s) {
> > > + case 'n':
> > > + *s = '\x0A';
> > > + break;
> > > + case 't':
> > > + *s = '\x09';
> > > + break;
> > > + case '\\':
> > > + *s = '\x5c';
> >
> > what's wrong with '\n' etc here?
>
> I am not sure what you mean. My interpretations:
>
i mean instead of *s='\x0a' you can write *s='\n' and it's clearer
same for '\t' and '\\'
> a cold so that has to wait...). I noticed that it uses the threadsafe
> version of the mbtowc function. Do you think that is advisable in
> general?
the point of mbrtowc is not to be thread-safe but to be able to
restart the decoding (it records the decoding state)
so you can feed a buffer into mbrtowc by looping until the end
and continue later even if the buffer ended in the middle of a
character sequence (or you can use it to decode the input one
char at a time)
mbtowc reports an error on an incomplete sequence and you don't
know if it's an illegal sequence or you just need more input
(not a problem if you have all input in one buffer)
Received on Thu Jan 16 2014 - 01:41:45 CET
This archive was generated by hypermail 2.3.0
: Thu Jan 16 2014 - 01:48:06 CET