Slacker News Slacker News logo featuring a lazy sloth with a folded newspaper hat
  • top
  • new
  • show
  • ask
  • jobs
Library
← Back to context

Comment by emilfihlman

6 months ago

Can't edit anymore but a better (only slightly) and clearer version is

  u32 length = (code <= 0x7F) + (code <= 0x07FF) + (code <= 0xFFFF);
  u32 limit = (code <= 0x10FFFF);
  u32 allowed = ((code < 0xD800) || 
  (0xDFFF < code));
  u32 valid = (limit && allowed);
  return(-1 * !valid + valid * (4 - length));

0 comments

emilfihlman

Reply

No comments yet

Contribute on Hacker News ↗

Slacker News

Product

  • API Reference
  • Hacker News RSS
  • Source on GitHub

Community

  • Support Ukraine
  • Equal Justice Initiative
  • GiveWell Charities