Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:16

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2023 Google LLC.  All rights reserved.
0003 //
0004 // Use of this source code is governed by a BSD-style
0005 // license that can be found in the LICENSE file or at
0006 // https://developers.google.com/open-source/licenses/bsd
0007 
0008 #ifndef UPB_LEX_UNICODE_H_
0009 #define UPB_LEX_UNICODE_H_
0010 
0011 #include <stdint.h>
0012 
0013 // Must be last.
0014 #include "upb/port/def.inc"
0015 
0016 #ifdef __cplusplus
0017 extern "C" {
0018 #endif
0019 
0020 // Returns true iff a codepoint is the value for a high surrogate.
0021 UPB_INLINE bool upb_Unicode_IsHigh(uint32_t cp) {
0022   return (cp >= 0xd800 && cp <= 0xdbff);
0023 }
0024 
0025 // Returns true iff a codepoint is the value for a low surrogate.
0026 UPB_INLINE bool upb_Unicode_IsLow(uint32_t cp) {
0027   return (cp >= 0xdc00 && cp <= 0xdfff);
0028 }
0029 
0030 // Returns the high 16-bit surrogate value for a supplementary codepoint.
0031 // Does not sanity-check the input.
0032 UPB_INLINE uint16_t upb_Unicode_ToHigh(uint32_t cp) {
0033   return (cp >> 10) + 0xd7c0;
0034 }
0035 
0036 // Returns the low 16-bit surrogate value for a supplementary codepoint.
0037 // Does not sanity-check the input.
0038 UPB_INLINE uint16_t upb_Unicode_ToLow(uint32_t cp) {
0039   return (cp & 0x3ff) | 0xdc00;
0040 }
0041 
0042 // Returns the 32-bit value corresponding to a pair of 16-bit surrogates.
0043 // Does not sanity-check the input.
0044 UPB_INLINE uint32_t upb_Unicode_FromPair(uint32_t high, uint32_t low) {
0045   return ((high & 0x3ff) << 10) + (low & 0x3ff) + 0x10000;
0046 }
0047 
0048 // Outputs a codepoint as UTF8.
0049 // Returns the number of bytes written (1-4 on success, 0 on error).
0050 // Does not sanity-check the input. Specifically does not check for surrogates.
0051 int upb_Unicode_ToUTF8(uint32_t cp, char* out);
0052 
0053 #ifdef __cplusplus
0054 } /* extern "C" */
0055 #endif
0056 
0057 #include "upb/port/undef.inc"
0058 
0059 #endif /* UPB_LEX_UNICODE_H_ */