00001 // Copyright 2017 The Abseil Authors. 00002 // 00003 // Licensed under the Apache License, Version 2.0 (the "License"); 00004 // you may not use this file except in compliance with the License. 00005 // You may obtain a copy of the License at 00006 // 00007 // https://www.apache.org/licenses/LICENSE-2.0 00008 // 00009 // Unless required by applicable law or agreed to in writing, software 00010 // distributed under the License is distributed on an "AS IS" BASIS, 00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 // See the License for the specific language governing permissions and 00013 // limitations under the License. 00014 // 00015 // UTF8 utilities, implemented to reduce dependencies. 00016 00017 #ifndef ABSL_STRINGS_INTERNAL_UTF8_H_ 00018 #define ABSL_STRINGS_INTERNAL_UTF8_H_ 00019 00020 #include <cstddef> 00021 #include <cstdint> 00022 00023 namespace absl { 00024 namespace strings_internal { 00025 00026 // For Unicode code points 0 through 0x10FFFF, EncodeUTF8Char writes 00027 // out the UTF-8 encoding into buffer, and returns the number of chars 00028 // it wrote. 00029 // 00030 // As described in https://tools.ietf.org/html/rfc3629#section-3 , the encodings 00031 // are: 00032 // 00 - 7F : 0xxxxxxx 00033 // 80 - 7FF : 110xxxxx 10xxxxxx 00034 // 800 - FFFF : 1110xxxx 10xxxxxx 10xxxxxx 00035 // 10000 - 10FFFF : 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx 00036 // 00037 // Values greater than 0x10FFFF are not supported and may or may not write 00038 // characters into buffer, however never will more than kMaxEncodedUTF8Size 00039 // bytes be written, regardless of the value of utf8_char. 00040 enum { kMaxEncodedUTF8Size = 4 }; 00041 size_t EncodeUTF8Char(char *buffer, char32_t utf8_char); 00042 00043 } // namespace strings_internal 00044 } // namespace absl 00045 00046 #endif // ABSL_STRINGS_INTERNAL_UTF8_H_