Skip to content

Instantly share code, notes, and snippets.

@JervenBolleman
Last active February 16, 2017 15:25
Show Gist options
  • Save JervenBolleman/63d8757cddee1e1d4594b9b42c127c71 to your computer and use it in GitHub Desktop.
Save JervenBolleman/63d8757cddee1e1d4594b9b42c127c71 to your computer and use it in GitHub Desktop.
Fix illegal encoded high/low surrogate pairs.
StringBuilder f = new StringBuilder(w.length());
for (int i = 0; i < w.length(); i++)
{
char c = w.charAt(i);
if (c >= 0xD800 && c <= 0xD8FF)
{
int h = ((c - 0xD800) * 0x400);
int l = ((w.charAt(++i) - 0xDC00) + 0x10000);
f.append((char) (h + l));
}
else
{
f.append(c);
}
}
return f.toString();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment