+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
******************************************************************************
*
- * Copyright (C) 2000-2012, International Business Machines
+ * Copyright (C) 2000-2016, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
* file name: ushape.cpp
- * encoding: US-ASCII
+ * encoding: UTF-8
* tab size: 8 (not used)
* indentation:4
*
#include "ubidi_props.h"
#include "uassert.h"
-#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
-
/*
* This implementation is designed for 16-bit Unicode strings.
* The main assumption is that the Arabic characters and their
* as a glyph fragment of wide-glyph letters
* + IBM Unicode conversion tables map it to U+200B (ZWSP)
* + IBM Egypt has proposed to encode the tail in Unicode among Arabic Presentation Forms
+ * + Unicode 3.2 added U+FE73 ARABIC TAIL FRAGMENT
*/
/* definitions for Arabic letter shaping ------------------------------------ */
0, /*0x0674*/
1 + 32, /*0x0675*/
1, 1, /*0x0676-0x0677*/
- 1+2, 1+2, 1+2, 1+2, 1+2, 1+2, /*0x0678-0x067D*/
+ 1 + 2, /*0x0678*/
+ 1 + 2 + 8 + 256 * 0x16,/*0x0679*/
+ 1 + 2 + 8 + 256 * 0x0E,/*0x067A*/
+ 1 + 2 + 8 + 256 * 0x02,/*0x067B*/
+ 1+2, 1+2, /*0x67C-0x067D*/
1+2+8+256 * 0x06, 1+2, 1+2, 1+2, 1+2, 1+2, /*0x067E-0x0683*/
1+2, 1+2, 1+2+8+256 * 0x2A, 1+2, /*0x0684-0x0687*/
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*0x0688-0x0691*/
+ 1 + 8 + 256 * 0x38,/*0x0688*/
+ 1, 1, 1, /*0x0689-0x068B*/
+ 1 + 8 + 256 * 0x34,/*0x068C*/
+ 1 + 8 + 256 * 0x32,/*0x068D*/
+ 1 + 8 + 256 * 0x36,/*0x068E*/
+ 1, 1, /*0x068F-0x0690*/
+ 1 + 8 + 256 * 0x3C,/*0x0691*/
1, 1, 1, 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x94,/*0x06D0*/
+ 1+2, /*0x06D1*/
+ 1 + 8 + 256 * 0x5E,/*0x06D2*/
+ 1 + 8 + 256 * 0x60 /*0x06D3*/
};
static const uint8_t presALink[] = {
static const UChar convertFBto06[] =
{
/***********0******1******2******3******4******5******6******7******8******9******A******B******C******D******E******F***/
-/*FB5*/ 0x671, 0x671, 0, 0, 0, 0, 0x07E, 0x07E, 0x07E, 0x07E, 0, 0, 0, 0, 0, 0,
-/*FB6*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+/*FB5*/ 0x671, 0x671, 0x67B, 0x67B, 0x67B, 0x67B, 0x67E, 0x67E, 0x67E, 0x67E, 0, 0, 0, 0, 0x67A, 0x67A,
+/*FB6*/ 0x67A, 0x67A, 0, 0, 0, 0, 0x679, 0x679, 0x679, 0x679, 0, 0, 0, 0, 0, 0,
/*FB7*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x686, 0x686, 0x686, 0x686, 0, 0,
-/*FB8*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x698, 0x698, 0, 0, 0x6A9, 0x6A9,
-/*FB9*/ 0x6A9, 0x6A9, 0x6AF, 0x6AF, 0x6AF, 0x6AF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/*FBA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/*FBB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+/*FB8*/ 0, 0, 0x68D, 0x68D, 0x68C, 0x68C, 0x68E, 0x68E, 0x688, 0x688, 0x698, 0x698, 0x691, 0x691, 0x6A9, 0x6A9,
+/*FB9*/ 0x6A9, 0x6A9, 0x6AF, 0x6AF, 0x6AF, 0x6AF, 0, 0, 0, 0, 0, 0, 0, 0, 0x6BA, 0x6BA,
+/*FBA*/ 0x6BB, 0x6BB, 0x6BB, 0x6BB, 0x6C0, 0x6C0, 0x6C1, 0x6C1, 0x6C1, 0x6C1, 0x6BE, 0x6BE, 0x6BE, 0x6BE, 0x6d2, 0x6D2,
+/*FBB*/ 0x6D3, 0x6D3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/*FBC*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/*FBD*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/*FBE*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+/*FBD*/ 0, 0, 0, 0, 0, 0, 0, 0x6C7, 0x6C7, 0x6C6, 0x6C6, 0x6C8, 0x6C8, 0, 0x6CB, 0x6CB,
+/*FBE*/ 0x6C5, 0x6C5, 0x6C9, 0x6C9, 0x6D0, 0x6D0, 0x6D0, 0x6D0, 0, 0, 0, 0, 0, 0, 0, 0,
/*FBF*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x6CC, 0x6CC, 0x6CC, 0x6CC
};
_shapeToArabicDigitsWithContext(UChar *s, int32_t length,
UChar digitBase,
UBool isLogical, UBool lastStrongWasAL) {
- const UBiDiProps *bdp;
int32_t i;
UChar c;
- bdp=ubidi_getSingleton();
digitBase-=0x30;
/* the iteration direction depends on the type of input */
if(isLogical) {
for(i=0; i<length; ++i) {
c=s[i];
- switch(ubidi_getClass(bdp, c)) {
+ switch(ubidi_getClass(c)) {
case U_LEFT_TO_RIGHT: /* L */
case U_RIGHT_TO_LEFT: /* R */
lastStrongWasAL=FALSE;
} else {
for(i=length; i>0; /* pre-decrement in the body */) {
c=s[--i];
- switch(ubidi_getClass(bdp, c)) {
+ switch(ubidi_getClass(c)) {
case U_LEFT_TO_RIGHT: /* L */
case U_RIGHT_TO_LEFT: /* R */
lastStrongWasAL=FALSE;
count--;
}
- uprv_memcpy(dest, tempbuffer, sourceLength*U_SIZEOF_UCHAR);
+ u_memcpy(dest, tempbuffer, sourceLength);
destSize = u_strlen(dest);
}
tempbuffer[i] = SPACE_CHAR;
}
- uprv_memcpy(dest, tempbuffer, sourceLength*U_SIZEOF_UCHAR);
+ u_memcpy(dest, tempbuffer, sourceLength);
destSize = sourceLength;
}
count--;
}
- uprv_memcpy(dest,tempbuffer, sourceLength*U_SIZEOF_UCHAR);
+ u_memcpy(dest, tempbuffer, sourceLength);
destSize = sourceLength;
}
tempbuffer[j] = LAM_CHAR;
/* to ensure the array index is within the range */
U_ASSERT(dest[i] >= 0xFEF5u
- && dest[i]-0xFEF5u < sizeof(convertLamAlef)/sizeof(convertLamAlef[0]));
+ && dest[i]-0xFEF5u < UPRV_LENGTHOF(convertLamAlef));
tempbuffer[j-1] = convertLamAlef[ dest[i] - 0xFEF5 ];
j--;
countl--;
i--;
j--;
}
- uprv_memcpy(dest, tempbuffer, sourceLength*U_SIZEOF_UCHAR);
+ u_memcpy(dest, tempbuffer, sourceLength);
uprv_free(tempbuffer);
}
if(countr > 0) {
- uprv_memmove(tempbuffer, tempbuffer+countr, sourceLength*U_SIZEOF_UCHAR);
+ u_memmove(tempbuffer, tempbuffer+countr, sourceLength);
if(u_strlen(tempbuffer) < sourceLength) {
for(i=sourceLength-1;i>=sourceLength-countr;i--) {
tempbuffer[i] = SPACE_CHAR;
}
}
}
- uprv_memcpy(dest, tempbuffer, sourceLength*U_SIZEOF_UCHAR);
+ u_memcpy(dest, tempbuffer, sourceLength);
uprv_free(tempbuffer);
j++;
}
- uprv_memcpy(dest, tempbuffer, destSize*U_SIZEOF_UCHAR);
+ u_memcpy(dest, tempbuffer, destSize);
}
}
} else {
/* to ensure the array index is within the range */
U_ASSERT(dest[i] >= 0x064Bu
- && dest[i]-0x064Bu < sizeof(IrrelevantPos)/sizeof(IrrelevantPos[0]));
- dest[i] = 0xFE70 + IrrelevantPos[(dest[i] - 0x064B)] + Shape;
+ && dest[i]-0x064Bu < UPRV_LENGTHOF(IrrelevantPos));
+ dest[i] = 0xFE70 + IrrelevantPos[(dest[i] - 0x064B)] + static_cast<UChar>(Shape);
}
}else if ((currLink & APRESENT) > 0) {
dest[i] = (UChar)(0xFB50 + (currLink >> 8) + Shape);
}
/* Start of Arabic letter shaping part */
- if(outputSize<=LENGTHOF(buffer)) {
- outputSize=LENGTHOF(buffer);
+ if(outputSize<=UPRV_LENGTHOF(buffer)) {
+ outputSize=UPRV_LENGTHOF(buffer);
tempbuffer=buffer;
} else {
tempbuffer = (UChar *)uprv_malloc(outputSize*U_SIZEOF_UCHAR);
return 0;
}
}
- uprv_memcpy(tempbuffer, source, sourceLength*U_SIZEOF_UCHAR);
+ u_memcpy(tempbuffer, source, sourceLength);
if (tempsource != NULL){
uprv_free(tempsource);
}
countSpaces(tempbuffer,destLength,options,&spacesCountl,&spacesCountr);
invertBuffer(tempbuffer,destLength,options,spacesCountl,spacesCountr);
}
- uprv_memcpy(dest, tempbuffer, uprv_min(destLength, destCapacity)*U_SIZEOF_UCHAR);
+ u_memcpy(dest, tempbuffer, uprv_min(destLength, destCapacity));
if(tempbuffer!=buffer) {
uprv_free(tempbuffer);
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
return sourceLength;
}
- uprv_memcpy(dest, source, sourceLength*U_SIZEOF_UCHAR);
+ u_memcpy(dest, source, sourceLength);
destLength=sourceLength;
}