def _to_unicode_scalar_value(s):
if len(s) == <NUM_LIT:1>:<EOL><INDENT>return ord(s)<EOL><DEDENT>elif len(s) == <NUM_LIT:2>:<EOL><INDENT>return (ord(s[<NUM_LIT:0>]) - <NUM_LIT>) * <NUM_LIT> + (ord(s[<NUM_LIT:1>]) - <NUM_LIT>) + <NUM_LIT><EOL><DEDENT>else:<EOL><INDENT>raise ValueError<EOL><DEDENT>
Helper function for converting a character or surrogate pair into a Unicode scalar value e.g.
"\ud800\udc00" -> 0x10000

The algorithm can be found in older versions of the Unicode Standard.

https://unicode.org/versions/Unicode3.0.0/ch03.pdf, Section 3.7, D28

Unicode scalar value: a number N from 0 to 0x10FFFF is defined by applying the following algorithm to a
character sequence S:
If S is a single, non-surrogate value U:
N = U
If S is a surrogate pair H, L:
N = (H - 0xD800) * 0x0400 + (L - 0xDC00) + 0x10000

:param s:
:return: