I don't know whether you are replying to me from your following context.
But assuming so,

The reason it's string only is that I'm dealing with string only at the
moment, and you can see from the source that the code is not mine, and I
don't think I'm qualified enough to extend the functionality to bytes yet.

On Fri, Jul 1, 2016 at 4:39 PM, mhhcbon wrote:

> Pretty cool. Why string only ?
>
> Le vendredi 24 juin 2016 22:54:35 UTC+2, mhhcbon a écrit :
>>
>> Hi,
>>
>> I have a small func like this
>>
>>
>> func WriteAsWindows1252 (src string, dst string) error {
>>   bSrc, err := ioutil.ReadFile(src)
>>   if err != nil {
>>       return err
>>   }
>>
>>   bDst := make([]byte, len(bSrc)*2)
>>   replaceNonAscii := runes.Map(func(r rune) rune {
>>         if r > unicode.MaxASCII {
>>             return rune('?')
>>         }
>>         return r
>>   })
>>   transformer := transform.Chain(replaceNonAscii, charmap.Windows1252.
>> NewEncoder())
>>   _, _, err = transformer.Transform(bDst, bSrc, true)
>>   if err != nil {
>>       return err
>>   }
>>
>>   return ioutil.WriteFile(dst, bDst, 0644)
>> }
>>
>> I would like to add a new replacement of \n to \r\n.
>>
>> I don't see how i can do that as rune can take only \r or \n but not
>> both. And runes.Map take a function which returns a unique rune. If i don t
>> mistake.
>>
>> Is there a way to achieve this with Chain ? Or i got to go with a
>> []byte.Replace https://golang.org/pkg/bytes/#Replace ?
>>
>> BTW, is it the correct way to encode an utf-8 file to windows1252 ?
>>
>> thanks!
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/rSHo0N7yDeQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to