Question

While reading the source code of SortableIntField, I noticed that this class avoids "UCS-16 surrogates" when converting an integer to a String (see method int int2sortableStr(int, char[], int) of NumberUtils.java).

What issue would these characters raise?

Was it helpful?

Solution

The comments of the given code are confusing, actually there is a mistake, Wikipedia:

Occasionally, articles about Unicode will mistakenly refer to UCS-2 as "UCS-16". UCS-16 does not exist; the authors who make this error usually intend to refer to UCS-2 or to UTF-16.

Your question #1: Why does SortableIntField avoid UCS-16 surrogates? To decrease running time and to save space by avoiding endiness, for instance.

Your question #2: What issue would these characters raise? Again, they would take more space and if the endiness is an issue, then also the running time would increase. And also remember to catch your exceptions, since otherwise you can put easily your server down.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top