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 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