Skip to content

Instantly share code, notes, and snippets.

@vinniefalco
Created October 14, 2019 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinniefalco/c693a08bf010bcec5eb5f91aaf6e62da to your computer and use it in GitHub Desktop.
Save vinniefalco/c693a08bf010bcec5eb5f91aaf6e62da to your computer and use it in GitHub Desktop.
// handles 1 or 2 surrogates
case state::u_surr:
{
// one code unit
if(u0_ == -1)
{
if( u_ >= 0xd800)
{
if(u_ <= 0xdbff)
{
// need 2nd surrogate
u0_ = u_;
stack_.front() = state::u_pair1;
goto loop;
}
else if(u_ <= 0xdfff)
{
ec = error::illegal_leading_surrogate;
goto finish;
}
}
// emit {u_} as utf8
stack_.pop_front();
goto loop;
}
// both code units
if( u_ < 0xdc00 ||
u_ >= 0xdfff)
{
ec = error::illegal_trailing_surrogate;
goto finish;
}
// emit {u0_, u_} as utf8
//unsigned long cp =
//(u0_ - 0xd800) << 10;
//if(u_ - 0xdc00
u0_ = -1;
stack_.pop_front();
goto loop;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment