Alex Rivera | Logout

Why UTF-32 instead of UTF-16 if we have surrogate pairs?

Asked 2009-03-09T04:31:34.070
15

If I understand correctly, UTF-32 can handle every character in the universe. So can UTF-16, through the use of surrogate pairs. So is there any good reason to use UTF-32 instead of UTF-16?

Edit
Report

1 Answer

9

Someone might prefer to deal with UTF-32 instead of UTF-16 because dealing with surrogate pairs is pretty much always handling 'special-cases', and having to deal with those special cases means you have areas where bugs may creep in because you deal with them incorrectly (or more likely just forget to deal with them at all).

If the increased memory usage of UTF-32 is not an issue, the reduced complexity might be enough of an advantage to choose it.

answered 2009-03-09T06:10:19.573

Your Answer