Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getByteLengthOfUtf8String #129

Open
gloriaJun opened this issue Aug 31, 2021 · 0 comments
Open

getByteLengthOfUtf8String #129

gloriaJun opened this issue Aug 31, 2021 · 0 comments
Assignees

Comments

@gloriaJun
Copy link
Owner

gloriaJun commented Aug 31, 2021

function getByteLengthOfUtf8String(s: string) {
  // returns the byte length of an utf8 string
  if (isEmptyString(s)) {
    return 0;
  }

  let b = 0;
  let c: number;

  for (let i = 0; (c = s.charCodeAt(i++)); b += c >> 11 ? 3 : c >> 7 ? 2 : 1);
  return b;
}
@gloriaJun gloriaJun self-assigned this Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant