Here you can find the source of bytesUtf8(int c)
Parameter | Description |
---|---|
c | one codePoint |
private static int bytesUtf8(int c)
//package com.java2s; /**/*from w w w . j a v a2 s .c om*/ * Copyright (c) 2000, Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * @param c one codePoint * @return the number of bytes needed to encode this codePoint in UTF-8 */ private static int bytesUtf8(int c) { if (c < 0x80) { return 1; } else if (c < 0x00800) { return 2; } else if (c < 0x10000) { return 3; } else if (c < 0x200000) { return 4; // RFC 3629 forbids the use of UTF-8 for codePoint greater than 0x10FFFF, // so if the caller respects this RFC, this should not happen } else if (c < 0x4000000) { return 5; } else { return 6; } } }