]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/unicode/utf8.h
ICU-59117.0.1.tar.gz
[apple/icu.git] / icuSources / common / unicode / utf8.h
index 21e5f3d0479053155f294c42884f4274da544eb8..18e7e9455c97f9fe74b64891ea1efc7c4a75a00d 100644 (file)
@@ -1,12 +1,14 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
 *******************************************************************************
 *
-*   Copyright (C) 1999-2013, International Business Machines
+*   Copyright (C) 1999-2015, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
 *   file name:  utf8.h
-*   encoding:   US-ASCII
+*   encoding:   UTF-8
 *   tab size:   8 (not used)
 *   indentation:4
 *
 
 /* internal definitions ----------------------------------------------------- */
 
-/**
- * \var utf8_countTrailBytes
- * Internal array with numbers of trail bytes for any given byte used in
- * lead byte position.
- *
- * This is internal since it is not meant to be called directly by external clients;
- * however it is called by public macros in this file and thus must remain stable,
- * and should not be hidden when other internal functions are hidden (otherwise
- * public macros would fail to compile).
- * @internal
- */
-#ifdef U_UTF8_IMPL
-U_EXPORT const uint8_t 
-#elif defined(U_STATIC_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION)
-U_CFUNC const uint8_t
-#else
-U_CFUNC U_IMPORT const uint8_t /* U_IMPORT2? */ /*U_IMPORT*/ 
-#endif
-utf8_countTrailBytes[256];
+
 
 /**
  * Counts the trail bytes for a UTF-8 lead byte.
@@ -78,9 +62,9 @@ utf8_countTrailBytes[256];
  * @internal
  */
 #define U8_COUNT_TRAIL_BYTES(leadByte) \
-    ((leadByte)<0xf0 ? \
-        ((leadByte)>=0xc0)+((leadByte)>=0xe0) : \
-        (leadByte)<0xfe ? 3+((leadByte)>=0xf8)+((leadByte)>=0xfc) : 0)
+    ((uint8_t)(leadByte)<0xf0 ? \
+        ((uint8_t)(leadByte)>=0xc0)+((uint8_t)(leadByte)>=0xe0) : \
+        (uint8_t)(leadByte)<0xfe ? 3+((uint8_t)(leadByte)>=0xf8)+((uint8_t)(leadByte)>=0xfc) : 0)
 
 /**
  * Counts the trail bytes for a UTF-8 lead byte of a valid UTF-8 sequence.
@@ -253,7 +237,6 @@ utf8_back1SafeBody(const uint8_t *s, int32_t start, int32_t i);
     U8_NEXT(s, _u8_get_index, length, c); \
 }
 
-#ifndef U_HIDE_DRAFT_API
 /**
  * Get a code point from a string at a random-access offset,
  * without changing the offset.
@@ -277,14 +260,13 @@ utf8_back1SafeBody(const uint8_t *s, int32_t start, int32_t i);
  * @param length int32_t string length
  * @param c output UChar32 variable, set to U+FFFD in case of an error
  * @see U8_GET
- * @draft ICU 51
+ * @stable ICU 51
  */
 #define U8_GET_OR_FFFD(s, start, i, length, c) { \
     int32_t _u8_get_index=(i); \
     U8_SET_CP_START(s, start, _u8_get_index); \
     U8_NEXT_OR_FFFD(s, _u8_get_index, length, c); \
 }
-#endif /* U_HIDE_DRAFT_API */
 
 /* definitions with forward iteration --------------------------------------- */
 
@@ -368,7 +350,6 @@ utf8_back1SafeBody(const uint8_t *s, int32_t start, int32_t i);
     } \
 }
 
-#ifndef U_HIDE_DRAFT_API
 /**
  * Get a code point from a string at a code point boundary offset,
  * and advance the offset to the next code point boundary.
@@ -391,7 +372,7 @@ utf8_back1SafeBody(const uint8_t *s, int32_t start, int32_t i);
  * @param length int32_t string length
  * @param c output UChar32 variable, set to U+FFFD in case of an error
  * @see U8_NEXT
- * @draft ICU 51
+ * @stable ICU 51
  */
 #define U8_NEXT_OR_FFFD(s, i, length, c) { \
     (c)=(uint8_t)(s)[(i)++]; \
@@ -419,7 +400,6 @@ utf8_back1SafeBody(const uint8_t *s, int32_t start, int32_t i);
         } \
     } \
 }
-#endif /* U_HIDE_DRAFT_API */
 
 /**
  * Append a code point to a string, overwriting 1 to 4 bytes.
@@ -676,7 +656,6 @@ utf8_back1SafeBody(const uint8_t *s, int32_t start, int32_t i);
     } \
 }
 
-#ifndef U_HIDE_DRAFT_API
 /**
  * Move the string offset from one code point boundary to the previous one
  * and get the code point between them.
@@ -699,7 +678,7 @@ utf8_back1SafeBody(const uint8_t *s, int32_t start, int32_t i);
  * @param i int32_t string offset, must be start<i
  * @param c output UChar32 variable, set to U+FFFD in case of an error
  * @see U8_PREV
- * @draft ICU 51
+ * @stable ICU 51
  */
 #define U8_PREV_OR_FFFD(s, start, i, c) { \
     (c)=(uint8_t)(s)[--(i)]; \
@@ -707,7 +686,6 @@ utf8_back1SafeBody(const uint8_t *s, int32_t start, int32_t i);
         (c)=utf8_prevCharSafeBody((const uint8_t *)s, start, &(i), c, -3); \
     } \
 }
-#endif /* U_HIDE_DRAFT_API */
 
 /**
  * Move the string offset from one code point boundary to the previous one.
@@ -821,7 +799,7 @@ utf8_back1SafeBody(const uint8_t *s, int32_t start, int32_t i);
  * @stable ICU 2.4
  */
 #define U8_SET_CP_LIMIT(s, start, i, length) { \
-    if((start)<(i) && ((i)<(length) || ((length)<0 && (s)[i]!=0))) { \
+    if((start)<(i) && ((i)<(length) || (length)<0)) { \
         U8_BACK_1(s, start, i); \
         U8_FWD_1(s, i, length); \
     } \