Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ghost opened this issue Sep 11, 2016 · 2 comments
Closed

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

ghost opened this issue Sep 11, 2016 · 2 comments

Comments

@ghost
Copy link

ghost commented Sep 11, 2016

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
Copy link
Owner

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
Copy link
Author

ghost commented Sep 11, 2016

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

@ghost ghost closed this as completed Sep 11, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant