summaryrefslogtreecommitdiffstats
path: root/rtemstoolkit/ConvertUTF.c
diff options
context:
space:
mode:
Diffstat (limited to 'rtemstoolkit/ConvertUTF.c')
-rw-r--r--rtemstoolkit/ConvertUTF.c79
1 files changed, 40 insertions, 39 deletions
diff --git a/rtemstoolkit/ConvertUTF.c b/rtemstoolkit/ConvertUTF.c
index 9b3deeb..4263952 100644
--- a/rtemstoolkit/ConvertUTF.c
+++ b/rtemstoolkit/ConvertUTF.c
@@ -1,8 +1,8 @@
/*
* Copyright 2001-2004 Unicode, Inc.
- *
+ *
* Disclaimer
- *
+ *
* This source code is provided as is by Unicode, Inc. No claims are
* made as to fitness for any particular purpose. No warranties of any
* kind are expressed or implied. The recipient agrees to determine
@@ -10,9 +10,9 @@
* purchased on magnetic or optical media from Unicode, Inc., the
* sole remedy for any claim will be exchange of defective media
* within 90 days of receipt.
- *
+ *
* Limitations on Rights to Redistribute This Code
- *
+ *
* Unicode, Inc. hereby grants the right to freely use the information
* supplied in this file in the creation of products supporting the
* Unicode Standard, and to make copies of this file in any form
@@ -59,7 +59,7 @@ static const UTF32 halfMask = 0x3FFUL;
/* --------------------------------------------------------------------- */
ConversionResult ConvertUTF32toUTF16 (
- const UTF32** sourceStart, const UTF32* sourceEnd,
+ const UTF32** sourceStart, const UTF32* sourceEnd,
UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags) {
ConversionResult result = conversionOK;
const UTF32* source = *sourceStart;
@@ -108,7 +108,7 @@ ConversionResult ConvertUTF32toUTF16 (
/* --------------------------------------------------------------------- */
ConversionResult ConvertUTF16toUTF32 (
- const UTF16** sourceStart, const UTF16* sourceEnd,
+ const UTF16** sourceStart, const UTF16* sourceEnd,
UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags) {
ConversionResult result = conversionOK;
const UTF16* source = *sourceStart;
@@ -187,7 +187,7 @@ static const char trailingBytesForUTF8[256] = {
* This table contains as many values as there might be trailing bytes
* in a UTF-8 sequence.
*/
-static const UTF32 offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL,
+static const UTF32 offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL,
0x03C82080UL, 0xFA082080UL, 0x82082080UL };
/*
@@ -212,7 +212,7 @@ static const UTF8 firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
/* --------------------------------------------------------------------- */
ConversionResult ConvertUTF16toUTF8 (
- const UTF16** sourceStart, const UTF16* sourceEnd,
+ const UTF16** sourceStart, const UTF16* sourceEnd,
UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags) {
ConversionResult result = conversionOK;
const UTF16* source = *sourceStart;
@@ -221,7 +221,7 @@ ConversionResult ConvertUTF16toUTF8 (
UTF32 ch;
unsigned short bytesToWrite = 0;
const UTF32 byteMask = 0xBF;
- const UTF32 byteMark = 0x80;
+ const UTF32 byteMark = 0x80;
const UTF16* oldSource = source; /* In case we have to back up because of target overflow. */
ch = *source++;
/* If we have a surrogate pair, convert to UTF32 first. */
@@ -267,10 +267,10 @@ ConversionResult ConvertUTF16toUTF8 (
target -= bytesToWrite; result = targetExhausted; break;
}
switch (bytesToWrite) { /* note: everything falls through. */
- case 4: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
- case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
- case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
- case 1: *--target = (UTF8)(ch | firstByteMark[bytesToWrite]);
+ case 4: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6; /* fall-thru */
+ case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6; /* fall-thru */
+ case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6; /* fall-thru */
+ case 1: *--target = (UTF8)(ch | firstByteMark[bytesToWrite]); /* fall-thru */
}
target += bytesToWrite;
}
@@ -298,9 +298,9 @@ static Boolean isLegalUTF8(const UTF8 *source, int length) {
switch (length) {
default: return false;
/* Everything else falls through when "true"... */
- case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
- case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
- case 2: if ((a = (*--srcptr)) > 0xBF) return false;
+ case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false; /* fall-thru */
+ case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false; /* fall-thru */
+ case 2: if ((a = (*--srcptr)) > 0xBF) return false; /* fall-thru */
switch (*source) {
/* no fall-through in this inner switch */
@@ -308,10 +308,10 @@ static Boolean isLegalUTF8(const UTF8 *source, int length) {
case 0xED: if (a > 0x9F) return false; break;
case 0xF0: if (a < 0x90) return false; break;
case 0xF4: if (a > 0x8F) return false; break;
- default: if (a < 0x80) return false;
+ default: if (a < 0x80) return false; break;
}
-
- case 1: if (*source >= 0x80 && *source < 0xC2) return false;
+ /* FALLTHRU */
+ case 1: if (*source >= 0x80 && *source < 0xC2) return false; /* fall-thru */
}
if (*source > 0xF4) return false;
return true;
@@ -334,7 +334,7 @@ Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd) {
/* --------------------------------------------------------------------- */
ConversionResult ConvertUTF8toUTF16 (
- const UTF8** sourceStart, const UTF8* sourceEnd,
+ const UTF8** sourceStart, const UTF8* sourceEnd,
UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags) {
ConversionResult result = conversionOK;
const UTF8* source = *sourceStart;
@@ -354,12 +354,12 @@ ConversionResult ConvertUTF8toUTF16 (
* The cases all fall through. See "Note A" below.
*/
switch (extraBytesToRead) {
- case 5: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
- case 4: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
- case 3: ch += *source++; ch <<= 6;
- case 2: ch += *source++; ch <<= 6;
- case 1: ch += *source++; ch <<= 6;
- case 0: ch += *source++;
+ case 5: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */ /* fall-thru */
+ case 4: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */ /* fall-thru */
+ case 3: ch += *source++; ch <<= 6; /* fall-thru */
+ case 2: ch += *source++; ch <<= 6; /* fall-thru */
+ case 1: ch += *source++; ch <<= 6; /* fall-thru */
+ case 0: ch += *source++; /* fall-thru */
}
ch -= offsetsFromUTF8[extraBytesToRead];
@@ -407,7 +407,7 @@ ConversionResult ConvertUTF8toUTF16 (
/* --------------------------------------------------------------------- */
ConversionResult ConvertUTF32toUTF8 (
- const UTF32** sourceStart, const UTF32* sourceEnd,
+ const UTF32** sourceStart, const UTF32* sourceEnd,
UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags) {
ConversionResult result = conversionOK;
const UTF32* source = *sourceStart;
@@ -416,7 +416,7 @@ ConversionResult ConvertUTF32toUTF8 (
UTF32 ch;
unsigned short bytesToWrite = 0;
const UTF32 byteMask = 0xBF;
- const UTF32 byteMark = 0x80;
+ const UTF32 byteMark = 0x80;
ch = *source++;
if (flags == strictConversion ) {
/* UTF-16 surrogate values are illegal in UTF-32 */
@@ -438,7 +438,7 @@ ConversionResult ConvertUTF32toUTF8 (
ch = UNI_REPLACEMENT_CHAR;
result = sourceIllegal;
}
-
+
target += bytesToWrite;
if (target > targetEnd) {
--source; /* Back up source pointer! */
@@ -446,9 +446,10 @@ ConversionResult ConvertUTF32toUTF8 (
}
switch (bytesToWrite) { /* note: everything falls through. */
case 4: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
- case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
- case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
- case 1: *--target = (UTF8) (ch | firstByteMark[bytesToWrite]);
+ /* fall-thru */
+ case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6; /* fall-thru */
+ case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6; /* fall-thru */
+ case 1: *--target = (UTF8) (ch | firstByteMark[bytesToWrite]); /* fall-thru */
}
target += bytesToWrite;
}
@@ -460,7 +461,7 @@ ConversionResult ConvertUTF32toUTF8 (
/* --------------------------------------------------------------------- */
ConversionResult ConvertUTF8toUTF32 (
- const UTF8** sourceStart, const UTF8* sourceEnd,
+ const UTF8** sourceStart, const UTF8* sourceEnd,
UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags) {
ConversionResult result = conversionOK;
const UTF8* source = *sourceStart;
@@ -480,12 +481,12 @@ ConversionResult ConvertUTF8toUTF32 (
* The cases all fall through. See "Note A" below.
*/
switch (extraBytesToRead) {
- case 5: ch += *source++; ch <<= 6;
- case 4: ch += *source++; ch <<= 6;
- case 3: ch += *source++; ch <<= 6;
- case 2: ch += *source++; ch <<= 6;
- case 1: ch += *source++; ch <<= 6;
- case 0: ch += *source++;
+ case 5: ch += *source++; ch <<= 6; /* fall-thru */
+ case 4: ch += *source++; ch <<= 6; /* fall-thru */
+ case 3: ch += *source++; ch <<= 6; /* fall-thru */
+ case 2: ch += *source++; ch <<= 6; /* fall-thru */
+ case 1: ch += *source++; ch <<= 6; /* fall-thru */
+ case 0: ch += *source++; /* fall-thru */
}
ch -= offsetsFromUTF8[extraBytesToRead];