djimenez / iconv-go

iconv support for Go
BSD 2-Clause "Simplified" License
418 stars 66 forks source link

Converts when in and out encoding are the same?? #30

Closed ghost closed 8 years ago

ghost commented 8 years ago

Does this library attempt to convert when the input and output encodings are the same? I wasn't able to find anything in the code but wanted to make sure I am not mistaken. For instance:

output, _ := iconv.ConvertString("Hello World!", "utf-8", "utf-8")

It would be more efficient to return the string unaffected.

djimenez commented 8 years ago

It does what libiconv does, that's kinda the point. Consider this snippet:

output, err := iconv.ConvertString("Am I \xfe valid?", "utf-8", "utf-8")

if err != nil {
     fmt.Printf("got %s for %q\n", err, output)
}

I'm doing a utf-8 to utf-8 conversion on a string with an invalid byte sequence, the output will be:

got invalid or incomplete multibyte or wide character for "Am I "

since it stops at the first invalid sequence.

I don't believe the behavior you're suggesting is necessarily something everyone wants and should be handled by the caller.

ghost commented 8 years ago

That's a good point....I can see it both ways.