2017-01-20 00:20:31 +00:00
|
|
|
// © 2016 and later: Unicode, Inc. and others.
|
2016-06-15 18:58:17 +00:00
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
2000-06-30 00:29:46 +00:00
|
|
|
/*
|
2007-07-27 03:12:12 +00:00
|
|
|
******************************************************************************
|
|
|
|
*
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (C) 2000-2016, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
2007-07-27 03:12:12 +00:00
|
|
|
*
|
|
|
|
******************************************************************************
|
2011-05-26 20:05:39 +00:00
|
|
|
* file name: ushape.cpp
|
2017-02-03 18:57:23 +00:00
|
|
|
* encoding: UTF-8
|
2007-07-27 03:12:12 +00:00
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 2000jun29
|
|
|
|
* created by: Markus W. Scherer
|
|
|
|
*
|
|
|
|
* Arabic letter shaping implemented by Ayman Roshdy
|
|
|
|
*/
|
2000-06-30 00:29:46 +00:00
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
2000-08-12 01:01:03 +00:00
|
|
|
#include "unicode/uchar.h"
|
|
|
|
#include "unicode/ustring.h"
|
2000-06-30 00:29:46 +00:00
|
|
|
#include "unicode/ushape.h"
|
2004-10-18 02:43:33 +00:00
|
|
|
#include "cmemory.h"
|
|
|
|
#include "putilimp.h"
|
2001-10-08 23:26:58 +00:00
|
|
|
#include "ustr_imp.h"
|
2004-12-31 13:41:56 +00:00
|
|
|
#include "ubidi_props.h"
|
2011-11-14 19:32:51 +00:00
|
|
|
#include "uassert.h"
|
2000-06-30 00:29:46 +00:00
|
|
|
|
2011-07-27 05:53:56 +00:00
|
|
|
/*
|
|
|
|
* This implementation is designed for 16-bit Unicode strings.
|
|
|
|
* The main assumption is that the Arabic characters and their
|
|
|
|
* presentation forms each fit into a single UChar.
|
|
|
|
* With UTF-8, they occupy 2 or 3 bytes, and more than the ASCII
|
|
|
|
* characters.
|
|
|
|
*/
|
2000-08-12 01:01:03 +00:00
|
|
|
|
2001-03-13 00:34:30 +00:00
|
|
|
/*
|
|
|
|
* ### TODO in general for letter shaping:
|
|
|
|
* - the letter shaping code is UTF-16-unaware; needs update
|
|
|
|
* + especially invertBuffer()?!
|
|
|
|
* - needs to handle the "Arabic Tail" that is used in some legacy codepages
|
|
|
|
* 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
|
2013-05-31 16:57:56 +00:00
|
|
|
* + Unicode 3.2 added U+FE73 ARABIC TAIL FRAGMENT
|
2001-03-13 00:34:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* definitions for Arabic letter shaping ------------------------------------ */
|
|
|
|
|
|
|
|
#define IRRELEVANT 4
|
|
|
|
#define LAMTYPE 16
|
|
|
|
#define ALEFTYPE 32
|
|
|
|
#define LINKR 1
|
|
|
|
#define LINKL 2
|
2006-11-29 23:35:20 +00:00
|
|
|
#define APRESENT 8
|
|
|
|
#define SHADDA 64
|
|
|
|
#define CSHADDA 128
|
|
|
|
#define COMBINE (SHADDA+CSHADDA)
|
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
#define HAMZAFE_CHAR 0xfe80
|
|
|
|
#define HAMZA06_CHAR 0x0621
|
|
|
|
#define YEH_HAMZA_CHAR 0x0626
|
|
|
|
#define YEH_HAMZAFE_CHAR 0xFE89
|
|
|
|
#define LAMALEF_SPACE_SUB 0xFFFF
|
|
|
|
#define TASHKEEL_SPACE_SUB 0xFFFE
|
|
|
|
#define NEW_TAIL_CHAR 0xFE73
|
|
|
|
#define OLD_TAIL_CHAR 0x200B
|
|
|
|
#define LAM_CHAR 0x0644
|
|
|
|
#define SPACE_CHAR 0x0020
|
|
|
|
#define SHADDA_CHAR 0xFE7C
|
|
|
|
#define TATWEEL_CHAR 0x0640
|
|
|
|
#define SHADDA_TATWEEL_CHAR 0xFE7D
|
2012-09-27 09:09:18 +00:00
|
|
|
#define SHADDA06_CHAR 0x0651
|
2009-03-02 15:46:03 +00:00
|
|
|
|
|
|
|
#define SHAPE_MODE 0
|
|
|
|
#define DESHAPE_MODE 1
|
|
|
|
|
2012-09-28 13:41:40 +00:00
|
|
|
struct uShapeVariables {
|
2012-10-03 17:18:27 +00:00
|
|
|
UChar tailChar;
|
|
|
|
uint32_t uShapeLamalefBegin;
|
|
|
|
uint32_t uShapeLamalefEnd;
|
|
|
|
uint32_t uShapeTashkeelBegin;
|
|
|
|
uint32_t uShapeTashkeelEnd;
|
|
|
|
int spacesRelativeToTextBeginEnd;
|
|
|
|
};
|
2009-03-02 15:46:03 +00:00
|
|
|
|
|
|
|
static const uint8_t tailFamilyIsolatedFinal[] = {
|
|
|
|
/* FEB1 */ 1,
|
|
|
|
/* FEB2 */ 1,
|
|
|
|
/* FEB3 */ 0,
|
|
|
|
/* FEB4 */ 0,
|
|
|
|
/* FEB5 */ 1,
|
|
|
|
/* FEB6 */ 1,
|
|
|
|
/* FEB7 */ 0,
|
|
|
|
/* FEB8 */ 0,
|
|
|
|
/* FEB9 */ 1,
|
|
|
|
/* FEBA */ 1,
|
|
|
|
/* FEBB */ 0,
|
|
|
|
/* FEBC */ 0,
|
|
|
|
/* FEBD */ 1,
|
|
|
|
/* FEBE */ 1
|
|
|
|
};
|
|
|
|
|
|
|
|
static const uint8_t tashkeelMedial[] = {
|
|
|
|
/* FE70 */ 0,
|
|
|
|
/* FE71 */ 1,
|
|
|
|
/* FE72 */ 0,
|
|
|
|
/* FE73 */ 0,
|
|
|
|
/* FE74 */ 0,
|
|
|
|
/* FE75 */ 0,
|
|
|
|
/* FE76 */ 0,
|
|
|
|
/* FE77 */ 1,
|
|
|
|
/* FE78 */ 0,
|
|
|
|
/* FE79 */ 1,
|
|
|
|
/* FE7A */ 0,
|
|
|
|
/* FE7B */ 1,
|
|
|
|
/* FE7C */ 0,
|
|
|
|
/* FE7D */ 1,
|
|
|
|
/* FE7E */ 0,
|
|
|
|
/* FE7F */ 1
|
|
|
|
};
|
|
|
|
|
|
|
|
static const UChar yehHamzaToYeh[] =
|
|
|
|
{
|
|
|
|
/* isolated*/ 0xFEEF,
|
|
|
|
/* final */ 0xFEF0
|
|
|
|
};
|
2001-03-13 00:34:30 +00:00
|
|
|
|
2008-01-08 09:45:15 +00:00
|
|
|
static const uint8_t IrrelevantPos[] = {
|
2001-08-30 16:59:44 +00:00
|
|
|
0x0, 0x2, 0x4, 0x6,
|
2009-03-02 15:46:03 +00:00
|
|
|
0x8, 0xA, 0xC, 0xE
|
2001-03-13 00:34:30 +00:00
|
|
|
};
|
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
|
2001-08-30 16:59:44 +00:00
|
|
|
static const UChar convertLamAlef[] =
|
2001-03-13 00:34:30 +00:00
|
|
|
{
|
|
|
|
/*FEF5*/ 0x0622,
|
|
|
|
/*FEF6*/ 0x0622,
|
|
|
|
/*FEF7*/ 0x0623,
|
|
|
|
/*FEF8*/ 0x0623,
|
|
|
|
/*FEF9*/ 0x0625,
|
|
|
|
/*FEFA*/ 0x0625,
|
|
|
|
/*FEFB*/ 0x0627,
|
|
|
|
/*FEFC*/ 0x0627
|
|
|
|
};
|
|
|
|
|
2001-08-30 16:59:44 +00:00
|
|
|
static const UChar araLink[178]=
|
2001-03-13 00:34:30 +00:00
|
|
|
{
|
|
|
|
1 + 32 + 256 * 0x11,/*0x0622*/
|
|
|
|
1 + 32 + 256 * 0x13,/*0x0623*/
|
|
|
|
1 + 256 * 0x15,/*0x0624*/
|
|
|
|
1 + 32 + 256 * 0x17,/*0x0625*/
|
|
|
|
1 + 2 + 256 * 0x19,/*0x0626*/
|
|
|
|
1 + 32 + 256 * 0x1D,/*0x0627*/
|
|
|
|
1 + 2 + 256 * 0x1F,/*0x0628*/
|
|
|
|
1 + 256 * 0x23,/*0x0629*/
|
|
|
|
1 + 2 + 256 * 0x25,/*0x062A*/
|
|
|
|
1 + 2 + 256 * 0x29,/*0x062B*/
|
|
|
|
1 + 2 + 256 * 0x2D,/*0x062C*/
|
|
|
|
1 + 2 + 256 * 0x31,/*0x062D*/
|
|
|
|
1 + 2 + 256 * 0x35,/*0x062E*/
|
|
|
|
1 + 256 * 0x39,/*0x062F*/
|
|
|
|
1 + 256 * 0x3B,/*0x0630*/
|
|
|
|
1 + 256 * 0x3D,/*0x0631*/
|
|
|
|
1 + 256 * 0x3F,/*0x0632*/
|
|
|
|
1 + 2 + 256 * 0x41,/*0x0633*/
|
|
|
|
1 + 2 + 256 * 0x45,/*0x0634*/
|
|
|
|
1 + 2 + 256 * 0x49,/*0x0635*/
|
|
|
|
1 + 2 + 256 * 0x4D,/*0x0636*/
|
|
|
|
1 + 2 + 256 * 0x51,/*0x0637*/
|
|
|
|
1 + 2 + 256 * 0x55,/*0x0638*/
|
|
|
|
1 + 2 + 256 * 0x59,/*0x0639*/
|
|
|
|
1 + 2 + 256 * 0x5D,/*0x063A*/
|
|
|
|
0, 0, 0, 0, 0, /*0x063B-0x063F*/
|
|
|
|
1 + 2, /*0x0640*/
|
|
|
|
1 + 2 + 256 * 0x61,/*0x0641*/
|
|
|
|
1 + 2 + 256 * 0x65,/*0x0642*/
|
|
|
|
1 + 2 + 256 * 0x69,/*0x0643*/
|
|
|
|
1 + 2 + 16 + 256 * 0x6D,/*0x0644*/
|
|
|
|
1 + 2 + 256 * 0x71,/*0x0645*/
|
|
|
|
1 + 2 + 256 * 0x75,/*0x0646*/
|
|
|
|
1 + 2 + 256 * 0x79,/*0x0647*/
|
|
|
|
1 + 256 * 0x7D,/*0x0648*/
|
|
|
|
1 + 256 * 0x7F,/*0x0649*/
|
|
|
|
1 + 2 + 256 * 0x81,/*0x064A*/
|
2006-11-29 23:35:20 +00:00
|
|
|
4 + 256 * 1, /*0x064B*/
|
|
|
|
4 + 128 + 256 * 1, /*0x064C*/
|
|
|
|
4 + 128 + 256 * 1, /*0x064D*/
|
|
|
|
4 + 128 + 256 * 1, /*0x064E*/
|
|
|
|
4 + 128 + 256 * 1, /*0x064F*/
|
|
|
|
4 + 128 + 256 * 1, /*0x0650*/
|
|
|
|
4 + 64 + 256 * 3, /*0x0651*/
|
|
|
|
4 + 256 * 1, /*0x0652*/
|
|
|
|
4 + 256 * 7, /*0x0653*/
|
|
|
|
4 + 256 * 8, /*0x0654*/
|
2011-11-21 19:38:08 +00:00
|
|
|
4 + 256 * 8, /*0x0655*/
|
2006-11-29 23:35:20 +00:00
|
|
|
4 + 256 * 1, /*0x0656*/
|
|
|
|
0, 0, 0, 0, 0, /*0x0657-0x065B*/
|
2001-03-13 00:34:30 +00:00
|
|
|
1 + 256 * 0x85,/*0x065C*/
|
|
|
|
1 + 256 * 0x87,/*0x065D*/
|
|
|
|
1 + 256 * 0x89,/*0x065E*/
|
|
|
|
1 + 256 * 0x8B,/*0x065F*/
|
|
|
|
0, 0, 0, 0, 0, /*0x0660-0x0664*/
|
|
|
|
0, 0, 0, 0, 0, /*0x0665-0x0669*/
|
|
|
|
0, 0, 0, 0, 0, 0, /*0x066A-0x066F*/
|
2006-11-29 23:35:20 +00:00
|
|
|
4 + 256 * 6, /*0x0670*/
|
|
|
|
1 + 8 + 256 * 0x00,/*0x0671*/
|
|
|
|
1 + 32, /*0x0672*/
|
|
|
|
1 + 32, /*0x0673*/
|
2001-03-13 00:34:30 +00:00
|
|
|
0, /*0x0674*/
|
2006-11-29 23:35:20 +00:00
|
|
|
1 + 32, /*0x0675*/
|
2001-03-13 00:34:30 +00:00
|
|
|
1, 1, /*0x0676-0x0677*/
|
2014-02-26 00:02:24 +00:00
|
|
|
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*/
|
2006-11-29 23:35:20 +00:00
|
|
|
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*/
|
2014-02-26 00:02:24 +00:00
|
|
|
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*/
|
2006-11-29 23:35:20 +00:00
|
|
|
1, 1, 1, 1, 1, 1, 1+8+256 * 0x3A, 1, /*0x0692-0x0699*/
|
2001-03-13 00:34:30 +00:00
|
|
|
1+2, 1+2, 1+2, 1+2, 1+2, 1+2, /*0x069A-0x06A3*/
|
|
|
|
1+2, 1+2, 1+2, 1+2, /*0x069A-0x06A3*/
|
2006-11-29 23:35:20 +00:00
|
|
|
1+2, 1+2, 1+2, 1+2, 1+2, 1+2+8+256 * 0x3E, /*0x06A4-0x06AD*/
|
2001-03-13 00:34:30 +00:00
|
|
|
1+2, 1+2, 1+2, 1+2, /*0x06A4-0x06AD*/
|
2006-11-29 23:35:20 +00:00
|
|
|
1+2, 1+2+8+256 * 0x42, 1+2, 1+2, 1+2, 1+2, /*0x06AE-0x06B7*/
|
2001-03-13 00:34:30 +00:00
|
|
|
1+2, 1+2, 1+2, 1+2, /*0x06AE-0x06B7*/
|
2014-02-26 00:02:24 +00:00
|
|
|
1+2, 1+2, /*0x06B8-0x06B9*/
|
|
|
|
1 + 8 + 256 * 0x4E,/*0x06BA*/
|
|
|
|
1 + 2 + 8 + 256 * 0x50,/*0x06BB*/
|
|
|
|
1+2, 1+2, /*0x06BC-0x06BD*/
|
|
|
|
1 + 2 + 8 + 256 * 0x5A,/*0x06BE*/
|
|
|
|
1+2, /*0x06BF*/
|
|
|
|
1 + 8 + 256 * 0x54,/*0x06C0*/
|
|
|
|
1 + 2 + 8 + 256 * 0x56,/*0x06C1*/
|
|
|
|
1, 1, 1, /*0x06C2-0x06C4*/
|
|
|
|
1 + 8 + 256 * 0x90,/*0x06C5*/
|
|
|
|
1 + 8 + 256 * 0x89,/*0x06C6*/
|
|
|
|
1 + 8 + 256 * 0x87,/*0x06C7*/
|
|
|
|
1 + 8 + 256 * 0x8B,/*0x06C8*/
|
|
|
|
1 + 8 + 256 * 0x92,/*0x06C9*/
|
|
|
|
1, /*0x06CA*/
|
|
|
|
1 + 8 + 256 * 0x8E,/*0x06CB*/
|
|
|
|
1 + 2 + 8 + 256 * 0xAC,/*0x06CC*/
|
2001-03-13 00:34:30 +00:00
|
|
|
1, /*0x06CD*/
|
2014-02-26 00:02:24 +00:00
|
|
|
1+2, 1+2, /*0x06CE-0x06CF*/
|
|
|
|
1 + 2 + 8 + 256 * 0x94,/*0x06D0*/
|
|
|
|
1+2, /*0x06D1*/
|
|
|
|
1 + 8 + 256 * 0x5E,/*0x06D2*/
|
|
|
|
1 + 8 + 256 * 0x60 /*0x06D3*/
|
2001-03-13 00:34:30 +00:00
|
|
|
};
|
|
|
|
|
2008-01-08 09:45:15 +00:00
|
|
|
static const uint8_t presALink[] = {
|
2006-11-29 23:35:20 +00:00
|
|
|
/***********0*****1*****2*****3*****4*****5*****6*****7*****8*****9*****A*****B*****C*****D*****E*****F*/
|
|
|
|
/*FB5*/ 0, 1, 0, 0, 0, 0, 0, 1, 2,1 + 2, 0, 0, 0, 0, 0, 0,
|
|
|
|
/*FB6*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
/*FB7*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2,1 + 2, 0, 0,
|
|
|
|
/*FB8*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1,
|
|
|
|
/*FB9*/ 2,1 + 2, 0, 1, 2,1 + 2, 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,
|
|
|
|
/*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,
|
|
|
|
/*FBF*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2,1 + 2,
|
|
|
|
/*FC0*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
/*FC1*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
/*FC2*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
/*FC3*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
/*FC4*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
/*FC5*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4,
|
|
|
|
/*FC6*/ 4, 4, 4
|
|
|
|
};
|
|
|
|
|
2008-01-08 09:45:15 +00:00
|
|
|
static const uint8_t presBLink[]=
|
2006-11-29 23:35:20 +00:00
|
|
|
{
|
|
|
|
/***********0*****1*****2*****3*****4*****5*****6*****7*****8*****9*****A*****B*****C*****D*****E*****F*/
|
2011-11-21 19:38:08 +00:00
|
|
|
/*FE7*/1 + 2,1 + 2,1 + 2, 0,1 + 2, 0,1 + 2,1 + 2,1 + 2,1 + 2,1 + 2,1 + 2,1 + 2,1 + 2,1 + 2,1 + 2,
|
2006-11-29 23:35:20 +00:00
|
|
|
/*FE8*/ 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2,1 + 2, 0, 1, 0,
|
|
|
|
/*FE9*/ 1, 2,1 + 2, 0, 1, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,
|
2011-11-21 19:38:08 +00:00
|
|
|
/*FEA*/1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 0, 1, 0, 1, 0,
|
2006-11-29 23:35:20 +00:00
|
|
|
/*FEB*/ 1, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,
|
|
|
|
/*FEC*/1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,
|
|
|
|
/*FED*/1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,
|
|
|
|
/*FEE*/1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 2,1 + 2, 0, 1, 0,
|
|
|
|
/*FEF*/ 1, 0, 1, 2,1 + 2, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const UChar convertFBto06[] =
|
2001-03-13 00:34:30 +00:00
|
|
|
{
|
2006-11-29 23:35:20 +00:00
|
|
|
/***********0******1******2******3******4******5******6******7******8******9******A******B******C******D******E******F***/
|
2014-02-26 00:02:24 +00:00
|
|
|
/*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,
|
2006-11-29 23:35:20 +00:00
|
|
|
/*FB7*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x686, 0x686, 0x686, 0x686, 0, 0,
|
2014-02-26 00:02:24 +00:00
|
|
|
/*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,
|
2006-11-29 23:35:20 +00:00
|
|
|
/*FBC*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
2014-02-26 00:02:24 +00:00
|
|
|
/*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,
|
2006-11-29 23:35:20 +00:00
|
|
|
/*FBF*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x6CC, 0x6CC, 0x6CC, 0x6CC
|
2001-03-13 00:34:30 +00:00
|
|
|
};
|
|
|
|
|
2001-08-30 16:59:44 +00:00
|
|
|
static const UChar convertFEto06[] =
|
2001-03-13 00:34:30 +00:00
|
|
|
{
|
|
|
|
/***********0******1******2******3******4******5******6******7******8******9******A******B******C******D******E******F***/
|
|
|
|
/*FE7*/ 0x64B, 0x64B, 0x64C, 0x64C, 0x64D, 0x64D, 0x64E, 0x64E, 0x64F, 0x64F, 0x650, 0x650, 0x651, 0x651, 0x652, 0x652,
|
|
|
|
/*FE8*/ 0x621, 0x622, 0x622, 0x623, 0x623, 0x624, 0x624, 0x625, 0x625, 0x626, 0x626, 0x626, 0x626, 0x627, 0x627, 0x628,
|
|
|
|
/*FE9*/ 0x628, 0x628, 0x628, 0x629, 0x629, 0x62A, 0x62A, 0x62A, 0x62A, 0x62B, 0x62B, 0x62B, 0x62B, 0x62C, 0x62C, 0x62C,
|
|
|
|
/*FEA*/ 0x62C, 0x62D, 0x62D, 0x62D, 0x62D, 0x62E, 0x62E, 0x62E, 0x62E, 0x62F, 0x62F, 0x630, 0x630, 0x631, 0x631, 0x632,
|
|
|
|
/*FEB*/ 0x632, 0x633, 0x633, 0x633, 0x633, 0x634, 0x634, 0x634, 0x634, 0x635, 0x635, 0x635, 0x635, 0x636, 0x636, 0x636,
|
|
|
|
/*FEC*/ 0x636, 0x637, 0x637, 0x637, 0x637, 0x638, 0x638, 0x638, 0x638, 0x639, 0x639, 0x639, 0x639, 0x63A, 0x63A, 0x63A,
|
|
|
|
/*FED*/ 0x63A, 0x641, 0x641, 0x641, 0x641, 0x642, 0x642, 0x642, 0x642, 0x643, 0x643, 0x643, 0x643, 0x644, 0x644, 0x644,
|
|
|
|
/*FEE*/ 0x644, 0x645, 0x645, 0x645, 0x645, 0x646, 0x646, 0x646, 0x646, 0x647, 0x647, 0x647, 0x647, 0x648, 0x648, 0x649,
|
|
|
|
/*FEF*/ 0x649, 0x64A, 0x64A, 0x64A, 0x64A, 0x65C, 0x65C, 0x65D, 0x65D, 0x65E, 0x65E, 0x65F, 0x65F
|
|
|
|
};
|
|
|
|
|
2008-01-08 09:45:15 +00:00
|
|
|
static const uint8_t shapeTable[4][4][4]=
|
2001-03-13 00:34:30 +00:00
|
|
|
{
|
|
|
|
{ {0,0,0,0}, {0,0,0,0}, {0,1,0,3}, {0,1,0,1} },
|
|
|
|
{ {0,0,2,2}, {0,0,1,2}, {0,1,1,2}, {0,1,1,3} },
|
|
|
|
{ {0,0,0,0}, {0,0,0,0}, {0,1,0,3}, {0,1,0,3} },
|
|
|
|
{ {0,0,1,2}, {0,0,1,2}, {0,1,1,2}, {0,1,1,3} }
|
|
|
|
};
|
|
|
|
|
2000-08-12 01:01:03 +00:00
|
|
|
/*
|
|
|
|
* This function shapes European digits to Arabic-Indic digits
|
|
|
|
* in-place, writing over the input characters.
|
|
|
|
* Since we know that we are only looking for BMP code points,
|
|
|
|
* we can safely just work with code units (again, at least UTF-16).
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
_shapeToArabicDigitsWithContext(UChar *s, int32_t length,
|
|
|
|
UChar digitBase,
|
|
|
|
UBool isLogical, UBool lastStrongWasAL) {
|
|
|
|
int32_t i;
|
|
|
|
UChar c;
|
|
|
|
|
|
|
|
digitBase-=0x30;
|
|
|
|
|
|
|
|
/* the iteration direction depends on the type of input */
|
|
|
|
if(isLogical) {
|
|
|
|
for(i=0; i<length; ++i) {
|
|
|
|
c=s[i];
|
2018-02-15 19:01:29 +00:00
|
|
|
switch(ubidi_getClass(c)) {
|
2000-08-12 01:01:03 +00:00
|
|
|
case U_LEFT_TO_RIGHT: /* L */
|
|
|
|
case U_RIGHT_TO_LEFT: /* R */
|
|
|
|
lastStrongWasAL=FALSE;
|
|
|
|
break;
|
|
|
|
case U_RIGHT_TO_LEFT_ARABIC: /* AL */
|
|
|
|
lastStrongWasAL=TRUE;
|
|
|
|
break;
|
|
|
|
case U_EUROPEAN_NUMBER: /* EN */
|
|
|
|
if(lastStrongWasAL && (uint32_t)(c-0x30)<10) {
|
2000-08-21 21:40:35 +00:00
|
|
|
s[i]=(UChar)(digitBase+c); /* digitBase+(c-0x30) - digitBase was modified above */
|
2000-08-12 01:01:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(i=length; i>0; /* pre-decrement in the body */) {
|
|
|
|
c=s[--i];
|
2018-02-15 19:01:29 +00:00
|
|
|
switch(ubidi_getClass(c)) {
|
2000-08-12 01:01:03 +00:00
|
|
|
case U_LEFT_TO_RIGHT: /* L */
|
|
|
|
case U_RIGHT_TO_LEFT: /* R */
|
|
|
|
lastStrongWasAL=FALSE;
|
|
|
|
break;
|
|
|
|
case U_RIGHT_TO_LEFT_ARABIC: /* AL */
|
|
|
|
lastStrongWasAL=TRUE;
|
|
|
|
break;
|
|
|
|
case U_EUROPEAN_NUMBER: /* EN */
|
|
|
|
if(lastStrongWasAL && (uint32_t)(c-0x30)<10) {
|
2000-08-21 21:40:35 +00:00
|
|
|
s[i]=(UChar)(digitBase+c); /* digitBase+(c-0x30) - digitBase was modified above */
|
2000-08-12 01:01:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-13 00:34:30 +00:00
|
|
|
/*
|
|
|
|
*Name : invertBuffer
|
|
|
|
*Function : This function inverts the buffer, it's used
|
|
|
|
* in case the user specifies the buffer to be
|
|
|
|
* U_SHAPE_TEXT_DIRECTION_LOGICAL
|
|
|
|
*/
|
2011-11-21 19:38:08 +00:00
|
|
|
static void
|
2011-05-26 20:05:39 +00:00
|
|
|
invertBuffer(UChar *buffer, int32_t size, uint32_t /*options*/, int32_t lowlimit, int32_t highlimit) {
|
2001-03-13 00:34:30 +00:00
|
|
|
UChar temp;
|
|
|
|
int32_t i=0,j=0;
|
|
|
|
for(i=lowlimit,j=size-highlimit-1;i<j;i++,j--) {
|
|
|
|
temp = buffer[i];
|
|
|
|
buffer[i] = buffer[j];
|
|
|
|
buffer[j] = temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*Name : changeLamAlef
|
|
|
|
*Function : Converts the Alef characters into an equivalent
|
|
|
|
* LamAlef location in the 0x06xx Range, this is an
|
|
|
|
* intermediate stage in the operation of the program
|
|
|
|
* later it'll be converted into the 0xFExx LamAlefs
|
|
|
|
* in the shaping function.
|
|
|
|
*/
|
2011-05-26 20:05:39 +00:00
|
|
|
static inline UChar
|
2001-03-13 00:34:30 +00:00
|
|
|
changeLamAlef(UChar ch) {
|
|
|
|
switch(ch) {
|
|
|
|
case 0x0622 :
|
2006-03-21 09:48:57 +00:00
|
|
|
return 0x065C;
|
2001-03-13 00:34:30 +00:00
|
|
|
case 0x0623 :
|
2006-03-21 09:48:57 +00:00
|
|
|
return 0x065D;
|
2001-03-13 00:34:30 +00:00
|
|
|
case 0x0625 :
|
2006-03-21 09:48:57 +00:00
|
|
|
return 0x065E;
|
2001-03-13 00:34:30 +00:00
|
|
|
case 0x0627 :
|
2006-03-21 09:48:57 +00:00
|
|
|
return 0x065F;
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
2006-03-21 09:48:57 +00:00
|
|
|
return 0;
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*Name : getLink
|
|
|
|
*Function : Resolves the link between the characters as
|
|
|
|
* Arabic characters have four forms :
|
|
|
|
* Isolated, Initial, Middle and Final Form
|
|
|
|
*/
|
2001-03-22 01:26:48 +00:00
|
|
|
static UChar
|
2001-03-13 00:34:30 +00:00
|
|
|
getLink(UChar ch) {
|
|
|
|
if(ch >= 0x0622 && ch <= 0x06D3) {
|
|
|
|
return(araLink[ch-0x0622]);
|
|
|
|
} else if(ch == 0x200D) {
|
|
|
|
return(3);
|
|
|
|
} else if(ch >= 0x206D && ch <= 0x206F) {
|
|
|
|
return(4);
|
2009-03-02 15:46:03 +00:00
|
|
|
}else if(ch >= 0xFB50 && ch <= 0xFC62) {
|
2006-11-29 23:35:20 +00:00
|
|
|
return(presALink[ch-0xFB50]);
|
2001-03-13 00:34:30 +00:00
|
|
|
} else if(ch >= 0xFE70 && ch <= 0xFEFC) {
|
2006-11-29 23:35:20 +00:00
|
|
|
return(presBLink[ch-0xFE70]);
|
2009-03-02 15:46:03 +00:00
|
|
|
}else {
|
2001-03-13 00:34:30 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*Name : countSpaces
|
|
|
|
*Function : Counts the number of spaces
|
|
|
|
* at each end of the logical buffer
|
|
|
|
*/
|
2001-03-22 01:26:48 +00:00
|
|
|
static void
|
2011-05-26 20:05:39 +00:00
|
|
|
countSpaces(UChar *dest, int32_t size, uint32_t /*options*/, int32_t *spacesCountl, int32_t *spacesCountr) {
|
2001-03-13 00:34:30 +00:00
|
|
|
int32_t i = 0;
|
|
|
|
int32_t countl = 0,countr = 0;
|
2011-11-21 19:38:08 +00:00
|
|
|
while((dest[i] == SPACE_CHAR) && (countl < size)) {
|
2001-03-13 00:34:30 +00:00
|
|
|
countl++;
|
|
|
|
i++;
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
if (countl < size) { /* the entire buffer is not all space */
|
|
|
|
while(dest[size-1] == SPACE_CHAR) {
|
|
|
|
countr++;
|
|
|
|
size--;
|
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
|
|
|
*spacesCountl = countl;
|
|
|
|
*spacesCountr = countr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*Name : isTashkeelChar
|
2009-03-02 15:46:03 +00:00
|
|
|
*Function : Returns 1 for Tashkeel characters in 06 range else return 0
|
2001-03-13 00:34:30 +00:00
|
|
|
*/
|
2011-05-26 20:05:39 +00:00
|
|
|
static inline int32_t
|
2001-03-13 00:34:30 +00:00
|
|
|
isTashkeelChar(UChar ch) {
|
2006-03-21 09:48:57 +00:00
|
|
|
return (int32_t)( ch>=0x064B && ch<= 0x0652 );
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
/*
|
|
|
|
*Name : isTashkeelCharFE
|
|
|
|
*Function : Returns 1 for Tashkeel characters in FE range else return 0
|
|
|
|
*/
|
2011-05-26 20:05:39 +00:00
|
|
|
static inline int32_t
|
2009-03-02 15:46:03 +00:00
|
|
|
isTashkeelCharFE(UChar ch) {
|
|
|
|
return (int32_t)( ch>=0xFE70 && ch<= 0xFE7F );
|
|
|
|
}
|
|
|
|
|
2001-03-13 00:34:30 +00:00
|
|
|
/*
|
|
|
|
*Name : isAlefChar
|
|
|
|
*Function : Returns 1 for Alef characters else return 0
|
|
|
|
*/
|
2011-05-26 20:05:39 +00:00
|
|
|
static inline int32_t
|
2001-03-13 00:34:30 +00:00
|
|
|
isAlefChar(UChar ch) {
|
2006-03-21 09:48:57 +00:00
|
|
|
return (int32_t)( (ch==0x0622)||(ch==0x0623)||(ch==0x0625)||(ch==0x0627) );
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*Name : isLamAlefChar
|
|
|
|
*Function : Returns 1 for LamAlef characters else return 0
|
|
|
|
*/
|
2011-05-26 20:05:39 +00:00
|
|
|
static inline int32_t
|
2001-03-13 00:34:30 +00:00
|
|
|
isLamAlefChar(UChar ch) {
|
2009-03-02 15:46:03 +00:00
|
|
|
return (int32_t)((ch>=0xFEF5)&&(ch<=0xFEFC) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*BIDI
|
|
|
|
*Name : isTailChar
|
2011-11-21 19:38:08 +00:00
|
|
|
*Function : returns 1 if the character matches one of the tail characters (0xfe73 or 0x200b) otherwise returns 0
|
2009-03-02 15:46:03 +00:00
|
|
|
*/
|
|
|
|
|
2011-05-26 20:05:39 +00:00
|
|
|
static inline int32_t
|
2009-03-02 15:46:03 +00:00
|
|
|
isTailChar(UChar ch) {
|
|
|
|
if(ch == OLD_TAIL_CHAR || ch == NEW_TAIL_CHAR){
|
|
|
|
return 1;
|
|
|
|
}else{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*BIDI
|
|
|
|
*Name : isSeenTailFamilyChar
|
2011-11-21 19:38:08 +00:00
|
|
|
*Function : returns 1 if the character is a seen family isolated character
|
2009-03-02 15:46:03 +00:00
|
|
|
* in the FE range otherwise returns 0
|
|
|
|
*/
|
|
|
|
|
2011-05-26 20:05:39 +00:00
|
|
|
static inline int32_t
|
2009-03-02 15:46:03 +00:00
|
|
|
isSeenTailFamilyChar(UChar ch) {
|
|
|
|
if(ch >= 0xfeb1 && ch < 0xfebf){
|
|
|
|
return tailFamilyIsolatedFinal [ch - 0xFEB1];
|
|
|
|
}else{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Name : isSeenFamilyChar
|
|
|
|
* Function : returns 1 if the character is a seen family character in the Unicode
|
|
|
|
* 06 range otherwise returns 0
|
|
|
|
*/
|
|
|
|
|
2011-05-26 20:05:39 +00:00
|
|
|
static inline int32_t
|
2009-03-02 15:46:03 +00:00
|
|
|
isSeenFamilyChar(UChar ch){
|
|
|
|
if(ch >= 0x633 && ch <= 0x636){
|
|
|
|
return 1;
|
|
|
|
}else {
|
|
|
|
return 0;
|
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
/*Start of BIDI*/
|
|
|
|
/*
|
|
|
|
*Name : isAlefMaksouraChar
|
2011-11-21 19:38:08 +00:00
|
|
|
*Function : returns 1 if the character is a Alef Maksoura Final or isolated
|
|
|
|
* otherwise returns 0
|
2009-03-02 15:46:03 +00:00
|
|
|
*/
|
2011-05-26 20:05:39 +00:00
|
|
|
static inline int32_t
|
2009-03-02 15:46:03 +00:00
|
|
|
isAlefMaksouraChar(UChar ch) {
|
|
|
|
return (int32_t)( (ch == 0xFEEF) || ( ch == 0xFEF0) || (ch == 0x0649));
|
2011-11-21 19:38:08 +00:00
|
|
|
}
|
2009-03-02 15:46:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Name : isYehHamzaChar
|
|
|
|
* Function : returns 1 if the character is a yehHamza isolated or yehhamza
|
2011-11-21 19:38:08 +00:00
|
|
|
* final is found otherwise returns 0
|
2009-03-02 15:46:03 +00:00
|
|
|
*/
|
2011-05-26 20:05:39 +00:00
|
|
|
static inline int32_t
|
2009-03-02 15:46:03 +00:00
|
|
|
isYehHamzaChar(UChar ch) {
|
|
|
|
if((ch==0xFE89)||(ch==0xFE8A)){
|
|
|
|
return 1;
|
|
|
|
}else{
|
|
|
|
return 0;
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
}
|
2009-03-02 15:46:03 +00:00
|
|
|
|
2011-11-21 19:38:08 +00:00
|
|
|
/*
|
2009-03-02 15:46:03 +00:00
|
|
|
* Name: isTashkeelOnTatweelChar
|
2011-11-21 19:38:08 +00:00
|
|
|
* Function: Checks if the Tashkeel Character is on Tatweel or not,if the
|
|
|
|
* Tashkeel on tatweel (FE range), it returns 1 else if the
|
|
|
|
* Tashkeel with shadda on tatweel (FC range)return 2 otherwise
|
2009-03-02 15:46:03 +00:00
|
|
|
* returns 0
|
|
|
|
*/
|
2011-05-26 20:05:39 +00:00
|
|
|
static inline int32_t
|
2009-03-02 15:46:03 +00:00
|
|
|
isTashkeelOnTatweelChar(UChar ch){
|
|
|
|
if(ch >= 0xfe70 && ch <= 0xfe7f && ch != NEW_TAIL_CHAR && ch != 0xFE75 && ch != SHADDA_TATWEEL_CHAR)
|
|
|
|
{
|
|
|
|
return tashkeelMedial [ch - 0xFE70];
|
|
|
|
}else if( (ch >= 0xfcf2 && ch <= 0xfcf4) || (ch == SHADDA_TATWEEL_CHAR)) {
|
|
|
|
return 2;
|
|
|
|
}else{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Name: isIsolatedTashkeelChar
|
2011-11-21 19:38:08 +00:00
|
|
|
* Function: Checks if the Tashkeel Character is in the isolated form
|
|
|
|
* (i.e. Unicode FE range) returns 1 else if the Tashkeel
|
2009-03-02 15:46:03 +00:00
|
|
|
* with shadda is in the isolated form (i.e. Unicode FC range)
|
|
|
|
* returns 2 otherwise returns 0
|
|
|
|
*/
|
2011-05-26 20:05:39 +00:00
|
|
|
static inline int32_t
|
2009-03-02 15:46:03 +00:00
|
|
|
isIsolatedTashkeelChar(UChar ch){
|
|
|
|
if(ch >= 0xfe70 && ch <= 0xfe7f && ch != NEW_TAIL_CHAR && ch != 0xFE75){
|
|
|
|
return (1 - tashkeelMedial [ch - 0xFE70]);
|
|
|
|
}else if(ch >= 0xfc5e && ch <= 0xfc63){
|
|
|
|
return 1;
|
|
|
|
}else{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-03-13 00:34:30 +00:00
|
|
|
/*
|
|
|
|
*Name : calculateSize
|
2011-11-21 19:38:08 +00:00
|
|
|
*Function : This function calculates the destSize to be used in preflighting
|
2001-03-13 00:34:30 +00:00
|
|
|
* when the destSize is equal to 0
|
2011-11-21 19:38:08 +00:00
|
|
|
* It is used also to calculate the new destsize in case the
|
2009-03-02 15:46:03 +00:00
|
|
|
* destination buffer will be resized.
|
2001-03-13 00:34:30 +00:00
|
|
|
*/
|
2009-03-02 15:46:03 +00:00
|
|
|
|
2001-03-22 01:26:48 +00:00
|
|
|
static int32_t
|
2001-03-13 00:34:30 +00:00
|
|
|
calculateSize(const UChar *source, int32_t sourceLength,
|
2009-03-02 15:46:03 +00:00
|
|
|
int32_t destSize,uint32_t options) {
|
2001-03-13 00:34:30 +00:00
|
|
|
int32_t i = 0;
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
int lamAlefOption = 0;
|
|
|
|
int tashkeelOption = 0;
|
|
|
|
|
2001-03-13 00:34:30 +00:00
|
|
|
destSize = sourceLength;
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if (((options&U_SHAPE_LETTERS_MASK) == U_SHAPE_LETTERS_SHAPE ||
|
|
|
|
((options&U_SHAPE_LETTERS_MASK) == U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED )) &&
|
|
|
|
((options&U_SHAPE_LAMALEF_MASK) == U_SHAPE_LAMALEF_RESIZE )){
|
|
|
|
lamAlefOption = 1;
|
|
|
|
}
|
|
|
|
if((options&U_SHAPE_LETTERS_MASK) == U_SHAPE_LETTERS_SHAPE &&
|
|
|
|
((options&U_SHAPE_TASHKEEL_MASK) == U_SHAPE_TASHKEEL_RESIZE ) ){
|
|
|
|
tashkeelOption = 1;
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if(lamAlefOption || tashkeelOption){
|
2001-03-13 00:34:30 +00:00
|
|
|
if((options&U_SHAPE_TEXT_DIRECTION_MASK)==U_SHAPE_TEXT_DIRECTION_VISUAL_LTR) {
|
|
|
|
for(i=0;i<sourceLength;i++) {
|
2009-03-02 15:46:03 +00:00
|
|
|
if( ((isAlefChar(source[i]))&& (i<(sourceLength-1)) &&(source[i+1] == LAM_CHAR)) || (isTashkeelCharFE(source[i])) ) {
|
|
|
|
destSize--;
|
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
2009-03-02 15:46:03 +00:00
|
|
|
}else if((options&U_SHAPE_TEXT_DIRECTION_MASK)==U_SHAPE_TEXT_DIRECTION_LOGICAL) {
|
|
|
|
for(i=0;i<sourceLength;i++) {
|
|
|
|
if( ( (source[i] == LAM_CHAR) && (i<(sourceLength-1)) && (isAlefChar(source[i+1]))) || (isTashkeelCharFE(source[i])) ) {
|
|
|
|
destSize--;
|
|
|
|
}
|
2006-11-29 23:35:20 +00:00
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if ((options&U_SHAPE_LETTERS_MASK) == U_SHAPE_LETTERS_UNSHAPE){
|
|
|
|
if ( (options&U_SHAPE_LAMALEF_MASK) == U_SHAPE_LAMALEF_RESIZE){
|
|
|
|
for(i=0;i<sourceLength;i++) {
|
|
|
|
if(isLamAlefChar(source[i]))
|
2001-03-13 00:34:30 +00:00
|
|
|
destSize++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return destSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-03-02 15:46:03 +00:00
|
|
|
*Name : handleTashkeelWithTatweel
|
2011-11-21 19:38:08 +00:00
|
|
|
*Function : Replaces Tashkeel as following:
|
|
|
|
* Case 1 :if the Tashkeel on tatweel, replace it with Tatweel.
|
|
|
|
* Case 2 :if the Tashkeel aggregated with Shadda on Tatweel, replace
|
2009-03-02 15:46:03 +00:00
|
|
|
* it with Shadda on Tatweel.
|
|
|
|
* Case 3: if the Tashkeel is isolated replace it with Space.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int32_t
|
|
|
|
handleTashkeelWithTatweel(UChar *dest, int32_t sourceLength,
|
2011-05-26 20:05:39 +00:00
|
|
|
int32_t /*destSize*/, uint32_t /*options*/,
|
|
|
|
UErrorCode * /*pErrorCode*/) {
|
2009-03-02 15:46:03 +00:00
|
|
|
int i;
|
|
|
|
for(i = 0; i < sourceLength; i++){
|
|
|
|
if((isTashkeelOnTatweelChar(dest[i]) == 1)){
|
|
|
|
dest[i] = TATWEEL_CHAR;
|
|
|
|
}else if((isTashkeelOnTatweelChar(dest[i]) == 2)){
|
|
|
|
dest[i] = SHADDA_TATWEEL_CHAR;
|
|
|
|
}else if(isIsolatedTashkeelChar(dest[i]) && dest[i] != SHADDA_CHAR){
|
|
|
|
dest[i] = SPACE_CHAR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sourceLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*Name : handleGeneratedSpaces
|
2001-03-13 00:34:30 +00:00
|
|
|
*Function : The shapeUnicode function converts Lam + Alef into LamAlef + space,
|
2011-11-21 19:38:08 +00:00
|
|
|
* and Tashkeel to space.
|
|
|
|
* handleGeneratedSpaces function puts these generated spaces
|
2009-03-02 15:46:03 +00:00
|
|
|
* according to the options the user specifies. LamAlef and Tashkeel
|
2011-11-21 19:38:08 +00:00
|
|
|
* spaces can be replaced at begin, at end, at near or decrease the
|
2009-03-02 15:46:03 +00:00
|
|
|
* buffer size.
|
|
|
|
*
|
|
|
|
* There is also Auto option for LamAlef and tashkeel, which will put
|
2011-11-21 19:38:08 +00:00
|
|
|
* the spaces at end of the buffer (or end of text if the user used
|
2009-03-02 15:46:03 +00:00
|
|
|
* the option U_SHAPE_SPACES_RELATIVE_TO_TEXT_BEGIN_END).
|
|
|
|
*
|
2011-11-21 19:38:08 +00:00
|
|
|
* If the text type was visual_LTR and the option
|
|
|
|
* U_SHAPE_SPACES_RELATIVE_TO_TEXT_BEGIN_END was selected the END
|
2009-03-02 15:46:03 +00:00
|
|
|
* option will place the space at the beginning of the buffer and
|
2011-11-21 19:38:08 +00:00
|
|
|
* BEGIN will place the space at the end of the buffer.
|
2001-03-13 00:34:30 +00:00
|
|
|
*/
|
2009-03-02 15:46:03 +00:00
|
|
|
|
2001-03-22 01:26:48 +00:00
|
|
|
static int32_t
|
2009-03-02 15:46:03 +00:00
|
|
|
handleGeneratedSpaces(UChar *dest, int32_t sourceLength,
|
2001-03-13 00:34:30 +00:00
|
|
|
int32_t destSize,
|
|
|
|
uint32_t options,
|
2012-09-28 13:41:40 +00:00
|
|
|
UErrorCode *pErrorCode,struct uShapeVariables shapeVars ) {
|
2001-03-13 00:34:30 +00:00
|
|
|
|
|
|
|
int32_t i = 0, j = 0;
|
|
|
|
int32_t count = 0;
|
|
|
|
UChar *tempbuffer=NULL;
|
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
int lamAlefOption = 0;
|
|
|
|
int tashkeelOption = 0;
|
|
|
|
int shapingMode = SHAPE_MODE;
|
|
|
|
|
|
|
|
if (shapingMode == 0){
|
|
|
|
if ( (options&U_SHAPE_LAMALEF_MASK) == U_SHAPE_LAMALEF_RESIZE ){
|
|
|
|
lamAlefOption = 1;
|
|
|
|
}
|
|
|
|
if ( (options&U_SHAPE_TASHKEEL_MASK) == U_SHAPE_TASHKEEL_RESIZE ){
|
|
|
|
tashkeelOption = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-03 03:32:21 +00:00
|
|
|
tempbuffer = (UChar *)uprv_malloc((sourceLength+1)*U_SIZEOF_UCHAR);
|
|
|
|
/* Test for NULL */
|
|
|
|
if(tempbuffer == NULL) {
|
|
|
|
*pErrorCode = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-29 09:31:05 +00:00
|
|
|
|
2012-10-03 03:32:21 +00:00
|
|
|
if (lamAlefOption || tashkeelOption){
|
2001-03-13 00:34:30 +00:00
|
|
|
uprv_memset(tempbuffer, 0, (sourceLength+1)*U_SIZEOF_UCHAR);
|
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
i = j = 0; count = 0;
|
2001-03-13 00:34:30 +00:00
|
|
|
while(i < sourceLength) {
|
2009-03-02 15:46:03 +00:00
|
|
|
if ( (lamAlefOption && dest[i] == LAMALEF_SPACE_SUB) ||
|
2011-11-21 19:38:08 +00:00
|
|
|
(tashkeelOption && dest[i] == TASHKEEL_SPACE_SUB) ){
|
2001-03-13 00:34:30 +00:00
|
|
|
j--;
|
|
|
|
count++;
|
2009-03-02 15:46:03 +00:00
|
|
|
} else {
|
2001-03-13 00:34:30 +00:00
|
|
|
tempbuffer[j] = dest[i];
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
i++;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(count >= 0) {
|
|
|
|
tempbuffer[i] = 0x0000;
|
|
|
|
i--;
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
|
2016-09-20 01:10:36 +00:00
|
|
|
u_memcpy(dest, tempbuffer, sourceLength);
|
2001-03-13 00:34:30 +00:00
|
|
|
destSize = u_strlen(dest);
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lamAlefOption = 0;
|
2001-03-13 00:34:30 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if (shapingMode == 0){
|
|
|
|
if ( (options&U_SHAPE_LAMALEF_MASK) == U_SHAPE_LAMALEF_NEAR ){
|
|
|
|
lamAlefOption = 1;
|
|
|
|
}
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if (lamAlefOption){
|
2001-03-13 00:34:30 +00:00
|
|
|
/* Lam+Alef is already shaped into LamAlef + FFFF */
|
|
|
|
i = 0;
|
|
|
|
while(i < sourceLength) {
|
2009-03-02 15:46:03 +00:00
|
|
|
if(lamAlefOption&&dest[i] == LAMALEF_SPACE_SUB){
|
|
|
|
dest[i] = SPACE_CHAR;
|
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
destSize = sourceLength;
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
|
|
|
lamAlefOption = 0;
|
|
|
|
tashkeelOption = 0;
|
|
|
|
|
|
|
|
if (shapingMode == 0) {
|
2012-09-28 13:41:40 +00:00
|
|
|
if ( ((options&U_SHAPE_LAMALEF_MASK) == shapeVars.uShapeLamalefBegin) ||
|
2009-03-02 15:46:03 +00:00
|
|
|
(((options&U_SHAPE_LAMALEF_MASK) == U_SHAPE_LAMALEF_AUTO )
|
2012-09-28 13:41:40 +00:00
|
|
|
&& (shapeVars.spacesRelativeToTextBeginEnd==1)) ) {
|
2009-03-02 15:46:03 +00:00
|
|
|
lamAlefOption = 1;
|
|
|
|
}
|
2012-09-28 13:41:40 +00:00
|
|
|
if ( (options&U_SHAPE_TASHKEEL_MASK) == shapeVars.uShapeTashkeelBegin ) {
|
2009-03-02 15:46:03 +00:00
|
|
|
tashkeelOption = 1;
|
|
|
|
}
|
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if(lamAlefOption || tashkeelOption){
|
2001-03-13 00:34:30 +00:00
|
|
|
uprv_memset(tempbuffer, 0, (sourceLength+1)*U_SIZEOF_UCHAR);
|
2012-10-03 03:32:21 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
i = j = sourceLength; count = 0;
|
2012-10-03 03:32:21 +00:00
|
|
|
|
2001-03-13 00:34:30 +00:00
|
|
|
while(i >= 0) {
|
2009-03-02 15:46:03 +00:00
|
|
|
if ( (lamAlefOption && dest[i] == LAMALEF_SPACE_SUB) ||
|
|
|
|
(tashkeelOption && dest[i] == TASHKEEL_SPACE_SUB) ){
|
2001-03-13 00:34:30 +00:00
|
|
|
j++;
|
|
|
|
count++;
|
2009-03-02 15:46:03 +00:00
|
|
|
}else {
|
2001-03-13 00:34:30 +00:00
|
|
|
tempbuffer[j] = dest[i];
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
i--;
|
|
|
|
j--;
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
for(i=0 ;i < count; i++){
|
|
|
|
tempbuffer[i] = SPACE_CHAR;
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2016-09-20 01:10:36 +00:00
|
|
|
u_memcpy(dest, tempbuffer, sourceLength);
|
2001-03-13 00:34:30 +00:00
|
|
|
destSize = sourceLength;
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
|
2002-06-29 09:31:05 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
|
|
|
|
lamAlefOption = 0;
|
|
|
|
tashkeelOption = 0;
|
|
|
|
|
|
|
|
if (shapingMode == 0) {
|
2012-09-28 13:41:40 +00:00
|
|
|
if ( ((options&U_SHAPE_LAMALEF_MASK) == shapeVars.uShapeLamalefEnd) ||
|
2009-03-02 15:46:03 +00:00
|
|
|
(((options&U_SHAPE_LAMALEF_MASK) == U_SHAPE_LAMALEF_AUTO )
|
2012-09-28 13:41:40 +00:00
|
|
|
&& (shapeVars.spacesRelativeToTextBeginEnd==0)) ) {
|
2009-03-02 15:46:03 +00:00
|
|
|
lamAlefOption = 1;
|
|
|
|
}
|
2012-09-28 13:41:40 +00:00
|
|
|
if ( (options&U_SHAPE_TASHKEEL_MASK) == shapeVars.uShapeTashkeelEnd ){
|
2009-03-02 15:46:03 +00:00
|
|
|
tashkeelOption = 1;
|
|
|
|
}
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if(lamAlefOption || tashkeelOption){
|
2001-03-13 00:34:30 +00:00
|
|
|
uprv_memset(tempbuffer, 0, (sourceLength+1)*U_SIZEOF_UCHAR);
|
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
i = j = 0; count = 0;
|
2001-03-13 00:34:30 +00:00
|
|
|
while(i < sourceLength) {
|
2009-03-02 15:46:03 +00:00
|
|
|
if ( (lamAlefOption && dest[i] == LAMALEF_SPACE_SUB) ||
|
|
|
|
(tashkeelOption && dest[i] == TASHKEEL_SPACE_SUB) ){
|
2001-03-13 00:34:30 +00:00
|
|
|
j--;
|
|
|
|
count++;
|
2009-03-02 15:46:03 +00:00
|
|
|
}else {
|
2001-03-13 00:34:30 +00:00
|
|
|
tempbuffer[j] = dest[i];
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
i++;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(count >= 0) {
|
2009-03-02 15:46:03 +00:00
|
|
|
tempbuffer[i] = SPACE_CHAR;
|
2001-03-13 00:34:30 +00:00
|
|
|
i--;
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
|
2016-09-20 01:10:36 +00:00
|
|
|
u_memcpy(dest, tempbuffer, sourceLength);
|
2001-03-13 00:34:30 +00:00
|
|
|
destSize = sourceLength;
|
|
|
|
}
|
|
|
|
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if(tempbuffer){
|
2001-03-13 00:34:30 +00:00
|
|
|
uprv_free(tempbuffer);
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
|
|
|
|
return destSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-03-02 15:46:03 +00:00
|
|
|
*Name :expandCompositCharAtBegin
|
|
|
|
*Function :Expands the LamAlef character to Lam and Alef consuming the required
|
2011-11-21 19:38:08 +00:00
|
|
|
* space from beginning of the buffer. If the text type was visual_LTR
|
2009-03-02 15:46:03 +00:00
|
|
|
* and the option U_SHAPE_SPACES_RELATIVE_TO_TEXT_BEGIN_END was selected
|
|
|
|
* the spaces will be located at end of buffer.
|
|
|
|
* If there are no spaces to expand the LamAlef, an error
|
2011-11-21 19:38:08 +00:00
|
|
|
* will be set to U_NO_SPACE_AVAILABLE as defined in utypes.h
|
2001-03-13 00:34:30 +00:00
|
|
|
*/
|
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
static int32_t
|
|
|
|
expandCompositCharAtBegin(UChar *dest, int32_t sourceLength, int32_t destSize,UErrorCode *pErrorCode) {
|
2001-03-13 00:34:30 +00:00
|
|
|
int32_t i = 0,j = 0;
|
|
|
|
int32_t countl = 0;
|
|
|
|
UChar *tempbuffer=NULL;
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
tempbuffer = (UChar *)uprv_malloc((sourceLength+1)*U_SIZEOF_UCHAR);
|
2001-03-13 00:34:30 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
/* Test for NULL */
|
|
|
|
if(tempbuffer == NULL) {
|
|
|
|
*pErrorCode = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
2002-06-29 09:31:05 +00:00
|
|
|
|
2001-03-13 00:34:30 +00:00
|
|
|
uprv_memset(tempbuffer, 0, (sourceLength+1)*U_SIZEOF_UCHAR);
|
|
|
|
|
|
|
|
i = 0;
|
2009-03-02 15:46:03 +00:00
|
|
|
while(dest[i] == SPACE_CHAR) {
|
2001-03-13 00:34:30 +00:00
|
|
|
countl++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = j = sourceLength-1;
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2001-03-13 00:34:30 +00:00
|
|
|
while(i >= 0 && j >= 0) {
|
2009-03-02 15:46:03 +00:00
|
|
|
if( countl>0 && isLamAlefChar(dest[i])) {
|
|
|
|
tempbuffer[j] = LAM_CHAR;
|
2011-11-14 19:32:51 +00:00
|
|
|
/* to ensure the array index is within the range */
|
2012-02-06 19:57:08 +00:00
|
|
|
U_ASSERT(dest[i] >= 0xFEF5u
|
2016-02-23 10:40:09 +00:00
|
|
|
&& dest[i]-0xFEF5u < UPRV_LENGTHOF(convertLamAlef));
|
2009-03-02 15:46:03 +00:00
|
|
|
tempbuffer[j-1] = convertLamAlef[ dest[i] - 0xFEF5 ];
|
|
|
|
j--;
|
|
|
|
countl--;
|
|
|
|
}else {
|
|
|
|
if( countl == 0 && isLamAlefChar(dest[i]) ) {
|
2001-03-13 00:34:30 +00:00
|
|
|
*pErrorCode=U_NO_SPACE_AVAILABLE;
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
tempbuffer[j] = dest[i];
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
|
|
|
i--;
|
|
|
|
j--;
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
2016-09-20 01:10:36 +00:00
|
|
|
u_memcpy(dest, tempbuffer, sourceLength);
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-12 16:22:21 +00:00
|
|
|
uprv_free(tempbuffer);
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2001-03-13 00:34:30 +00:00
|
|
|
destSize = sourceLength;
|
2009-03-02 15:46:03 +00:00
|
|
|
return destSize;
|
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
/*
|
|
|
|
*Name : expandCompositCharAtEnd
|
2011-11-21 19:38:08 +00:00
|
|
|
*Function : Expands the LamAlef character to Lam and Alef consuming the
|
2009-03-02 15:46:03 +00:00
|
|
|
* required space from end of the buffer. If the text type was
|
|
|
|
* Visual LTR and the option U_SHAPE_SPACES_RELATIVE_TO_TEXT_BEGIN_END
|
2011-11-21 19:38:08 +00:00
|
|
|
* was used, the spaces will be consumed from begin of buffer. If
|
2009-03-02 15:46:03 +00:00
|
|
|
* there are no spaces to expand the LamAlef, an error
|
2011-11-21 19:38:08 +00:00
|
|
|
* will be set to U_NO_SPACE_AVAILABLE as defined in utypes.h
|
2009-03-02 15:46:03 +00:00
|
|
|
*/
|
2002-06-29 09:31:05 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
static int32_t
|
|
|
|
expandCompositCharAtEnd(UChar *dest, int32_t sourceLength, int32_t destSize,UErrorCode *pErrorCode) {
|
|
|
|
int32_t i = 0,j = 0;
|
2002-06-29 09:31:05 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
int32_t countr = 0;
|
|
|
|
int32_t inpsize = sourceLength;
|
2001-03-13 00:34:30 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
UChar *tempbuffer=NULL;
|
|
|
|
tempbuffer = (UChar *)uprv_malloc((sourceLength+1)*U_SIZEOF_UCHAR);
|
|
|
|
|
|
|
|
/* Test for NULL */
|
|
|
|
if(tempbuffer == NULL) {
|
|
|
|
*pErrorCode = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
uprv_memset(tempbuffer, 0, (sourceLength+1)*U_SIZEOF_UCHAR);
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
while(dest[inpsize-1] == SPACE_CHAR) {
|
|
|
|
countr++;
|
|
|
|
inpsize--;
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
i = sourceLength - countr - 1;
|
|
|
|
j = sourceLength - 1;
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
while(i >= 0 && j >= 0) {
|
|
|
|
if( countr>0 && isLamAlefChar(dest[i]) ) {
|
|
|
|
tempbuffer[j] = LAM_CHAR;
|
|
|
|
tempbuffer[j-1] = convertLamAlef[ dest[i] - 0xFEF5 ];
|
|
|
|
j--;
|
|
|
|
countr--;
|
|
|
|
}else {
|
|
|
|
if ((countr == 0) && isLamAlefChar(dest[i]) ) {
|
|
|
|
*pErrorCode=U_NO_SPACE_AVAILABLE;
|
|
|
|
}
|
|
|
|
tempbuffer[j] = dest[i];
|
|
|
|
}
|
|
|
|
i--;
|
|
|
|
j--;
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if(countr > 0) {
|
2016-09-20 01:10:36 +00:00
|
|
|
u_memmove(tempbuffer, tempbuffer+countr, sourceLength);
|
2009-03-02 15:46:03 +00:00
|
|
|
if(u_strlen(tempbuffer) < sourceLength) {
|
|
|
|
for(i=sourceLength-1;i>=sourceLength-countr;i--) {
|
|
|
|
tempbuffer[i] = SPACE_CHAR;
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-20 01:10:36 +00:00
|
|
|
u_memcpy(dest, tempbuffer, sourceLength);
|
2009-03-02 15:46:03 +00:00
|
|
|
|
2009-03-12 16:22:21 +00:00
|
|
|
uprv_free(tempbuffer);
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
destSize = sourceLength;
|
|
|
|
return destSize;
|
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
/*
|
|
|
|
*Name : expandCompositCharAtNear
|
|
|
|
*Function : Expands the LamAlef character into Lam + Alef, YehHamza character
|
2011-11-21 19:38:08 +00:00
|
|
|
* into Yeh + Hamza, SeenFamily character into SeenFamily character
|
|
|
|
* + Tail, while consuming the space next to the character.
|
2009-03-02 15:46:03 +00:00
|
|
|
* If there are no spaces next to the character, an error
|
2011-11-21 19:38:08 +00:00
|
|
|
* will be set to U_NO_SPACE_AVAILABLE as defined in utypes.h
|
2009-03-02 15:46:03 +00:00
|
|
|
*/
|
2001-03-13 00:34:30 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
static int32_t
|
|
|
|
expandCompositCharAtNear(UChar *dest, int32_t sourceLength, int32_t destSize,UErrorCode *pErrorCode,
|
2012-09-28 13:41:40 +00:00
|
|
|
int yehHamzaOption, int seenTailOption, int lamAlefOption, struct uShapeVariables shapeVars) {
|
2009-03-02 15:46:03 +00:00
|
|
|
int32_t i = 0;
|
|
|
|
|
|
|
|
|
|
|
|
UChar lamalefChar, yehhamzaChar;
|
|
|
|
|
|
|
|
for(i = 0 ;i<=sourceLength-1;i++) {
|
|
|
|
if (seenTailOption && isSeenTailFamilyChar(dest[i])) {
|
|
|
|
if ((i>0) && (dest[i-1] == SPACE_CHAR) ) {
|
2012-09-28 13:41:40 +00:00
|
|
|
dest[i-1] = shapeVars.tailChar;
|
2009-03-02 15:46:03 +00:00
|
|
|
}else {
|
|
|
|
*pErrorCode=U_NO_SPACE_AVAILABLE;
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
2009-03-02 15:46:03 +00:00
|
|
|
}else if(yehHamzaOption && (isYehHamzaChar(dest[i])) ) {
|
|
|
|
if ((i>0) && (dest[i-1] == SPACE_CHAR) ) {
|
|
|
|
yehhamzaChar = dest[i];
|
|
|
|
dest[i] = yehHamzaToYeh[yehhamzaChar - YEH_HAMZAFE_CHAR];
|
|
|
|
dest[i-1] = HAMZAFE_CHAR;
|
|
|
|
}else {
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
*pErrorCode=U_NO_SPACE_AVAILABLE;
|
|
|
|
}
|
|
|
|
}else if(lamAlefOption && isLamAlefChar(dest[i+1])) {
|
|
|
|
if(dest[i] == SPACE_CHAR){
|
|
|
|
lamalefChar = dest[i+1];
|
|
|
|
dest[i+1] = LAM_CHAR;
|
|
|
|
dest[i] = convertLamAlef[ lamalefChar - 0xFEF5 ];
|
|
|
|
}else {
|
|
|
|
*pErrorCode=U_NO_SPACE_AVAILABLE;
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
|
|
|
destSize = sourceLength;
|
|
|
|
return destSize;
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
/*
|
2009-03-02 15:46:03 +00:00
|
|
|
* Name : expandCompositChar
|
2011-11-21 19:38:08 +00:00
|
|
|
* Function : LamAlef, need special handling, since it expands from one
|
|
|
|
* character into two characters while shaping or deshaping.
|
2009-03-02 15:46:03 +00:00
|
|
|
* In order to expand it, near or far spaces according to the
|
|
|
|
* options user specifies. Also buffer size can be increased.
|
|
|
|
*
|
|
|
|
* For SeenFamily characters and YehHamza only the near option is
|
|
|
|
* supported, while for LamAlef we can take spaces from begin, end,
|
|
|
|
* near or even increase the buffer size.
|
2011-11-21 19:38:08 +00:00
|
|
|
* There is also the Auto option for LamAlef only, which will first
|
2009-03-02 15:46:03 +00:00
|
|
|
* search for a space at end, begin then near, respectively.
|
2011-11-21 19:38:08 +00:00
|
|
|
* If there are no spaces to expand these characters, an error will be set to
|
|
|
|
* U_NO_SPACE_AVAILABLE as defined in utypes.h
|
2009-03-02 15:46:03 +00:00
|
|
|
*/
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
static int32_t
|
|
|
|
expandCompositChar(UChar *dest, int32_t sourceLength,
|
|
|
|
int32_t destSize,uint32_t options,
|
2012-09-28 13:41:40 +00:00
|
|
|
UErrorCode *pErrorCode, int shapingMode,struct uShapeVariables shapeVars) {
|
2001-03-13 00:34:30 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
int32_t i = 0,j = 0;
|
|
|
|
|
|
|
|
UChar *tempbuffer=NULL;
|
|
|
|
int yehHamzaOption = 0;
|
|
|
|
int seenTailOption = 0;
|
|
|
|
int lamAlefOption = 0;
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if (shapingMode == 1){
|
|
|
|
if ( (options&U_SHAPE_LAMALEF_MASK) == U_SHAPE_LAMALEF_AUTO){
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2012-09-28 13:41:40 +00:00
|
|
|
if(shapeVars.spacesRelativeToTextBeginEnd == 0) {
|
2009-03-02 15:46:03 +00:00
|
|
|
destSize = expandCompositCharAtEnd(dest, sourceLength, destSize, pErrorCode);
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if(*pErrorCode == U_NO_SPACE_AVAILABLE) {
|
|
|
|
*pErrorCode = U_ZERO_ERROR;
|
|
|
|
destSize = expandCompositCharAtBegin(dest, sourceLength, destSize, pErrorCode);
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
destSize = expandCompositCharAtBegin(dest, sourceLength, destSize, pErrorCode);
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if(*pErrorCode == U_NO_SPACE_AVAILABLE) {
|
|
|
|
*pErrorCode = U_ZERO_ERROR;
|
|
|
|
destSize = expandCompositCharAtEnd(dest, sourceLength, destSize, pErrorCode);
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if(*pErrorCode == U_NO_SPACE_AVAILABLE) {
|
|
|
|
*pErrorCode = U_ZERO_ERROR;
|
2011-11-21 19:38:08 +00:00
|
|
|
destSize = expandCompositCharAtNear(dest, sourceLength, destSize, pErrorCode, yehHamzaOption,
|
2012-09-28 13:41:40 +00:00
|
|
|
seenTailOption, 1,shapeVars);
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if (shapingMode == 1){
|
2012-09-28 13:41:40 +00:00
|
|
|
if ( (options&U_SHAPE_LAMALEF_MASK) == shapeVars.uShapeLamalefEnd){
|
2009-03-02 15:46:03 +00:00
|
|
|
destSize = expandCompositCharAtEnd(dest, sourceLength, destSize, pErrorCode);
|
|
|
|
}
|
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if (shapingMode == 1){
|
2012-09-28 13:41:40 +00:00
|
|
|
if ( (options&U_SHAPE_LAMALEF_MASK) == shapeVars.uShapeLamalefBegin){
|
2009-03-02 15:46:03 +00:00
|
|
|
destSize = expandCompositCharAtBegin(dest, sourceLength, destSize, pErrorCode);
|
|
|
|
}
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if (shapingMode == 0){
|
|
|
|
if ((options&U_SHAPE_YEHHAMZA_MASK) == U_SHAPE_YEHHAMZA_TWOCELL_NEAR){
|
|
|
|
yehHamzaOption = 1;
|
|
|
|
}
|
|
|
|
if ((options&U_SHAPE_SEEN_MASK) == U_SHAPE_SEEN_TWOCELL_NEAR){
|
|
|
|
seenTailOption = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (shapingMode == 1) {
|
|
|
|
if ( (options&U_SHAPE_LAMALEF_MASK) == U_SHAPE_LAMALEF_NEAR) {
|
|
|
|
lamAlefOption = 1;
|
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if (yehHamzaOption || seenTailOption || lamAlefOption){
|
2011-11-21 19:38:08 +00:00
|
|
|
destSize = expandCompositCharAtNear(dest, sourceLength, destSize, pErrorCode, yehHamzaOption,
|
2012-09-28 13:41:40 +00:00
|
|
|
seenTailOption,lamAlefOption,shapeVars);
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
|
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if (shapingMode == 1){
|
|
|
|
if ( (options&U_SHAPE_LAMALEF_MASK) == U_SHAPE_LAMALEF_RESIZE){
|
|
|
|
destSize = calculateSize(dest,sourceLength,destSize,options);
|
|
|
|
tempbuffer = (UChar *)uprv_malloc((destSize+1)*U_SIZEOF_UCHAR);
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
/* Test for NULL */
|
|
|
|
if(tempbuffer == NULL) {
|
|
|
|
*pErrorCode = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
uprv_memset(tempbuffer, 0, (destSize+1)*U_SIZEOF_UCHAR);
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
i = j = 0;
|
|
|
|
while(i < destSize && j < destSize) {
|
|
|
|
if(isLamAlefChar(dest[i]) ) {
|
|
|
|
tempbuffer[j] = convertLamAlef[ dest[i] - 0xFEF5 ];
|
|
|
|
tempbuffer[j+1] = LAM_CHAR;
|
|
|
|
j++;
|
|
|
|
}else {
|
|
|
|
tempbuffer[j] = dest[i];
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
j++;
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2016-09-20 01:10:36 +00:00
|
|
|
u_memcpy(dest, tempbuffer, destSize);
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if(tempbuffer) {
|
|
|
|
uprv_free(tempbuffer);
|
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
return destSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*Name : shapeUnicode
|
|
|
|
*Function : Converts an Arabic Unicode buffer in 06xx Range into a shaped
|
|
|
|
* arabic Unicode buffer in FExx Range
|
|
|
|
*/
|
2001-03-22 01:26:48 +00:00
|
|
|
static int32_t
|
2001-03-13 00:34:30 +00:00
|
|
|
shapeUnicode(UChar *dest, int32_t sourceLength,
|
|
|
|
int32_t destSize,uint32_t options,
|
|
|
|
UErrorCode *pErrorCode,
|
2012-09-28 13:41:40 +00:00
|
|
|
int tashkeelFlag, struct uShapeVariables shapeVars) {
|
2001-03-13 00:34:30 +00:00
|
|
|
|
|
|
|
int32_t i, iend;
|
|
|
|
int32_t step;
|
2006-02-09 08:59:20 +00:00
|
|
|
int32_t lastPos,Nx, Nw;
|
2001-03-13 00:34:30 +00:00
|
|
|
unsigned int Shape;
|
|
|
|
int32_t lamalef_found = 0;
|
2009-03-02 15:46:03 +00:00
|
|
|
int32_t seenfamFound = 0, yehhamzaFound =0, tashkeelFound = 0;
|
2001-03-13 00:34:30 +00:00
|
|
|
UChar prevLink = 0, lastLink = 0, currLink, nextLink = 0;
|
|
|
|
UChar wLamalef;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Converts the input buffer from FExx Range into 06xx Range
|
|
|
|
* to make sure that all characters are in the 06xx range
|
|
|
|
* even the lamalef is converted to the special region in
|
|
|
|
* the 06xx range
|
|
|
|
*/
|
2006-11-29 23:35:20 +00:00
|
|
|
if ((options & U_SHAPE_PRESERVE_PRESENTATION_MASK) == U_SHAPE_PRESERVE_PRESENTATION_NOOP) {
|
|
|
|
for (i = 0; i < sourceLength; i++) {
|
|
|
|
UChar inputChar = dest[i];
|
|
|
|
if ( (inputChar >= 0xFB50) && (inputChar <= 0xFBFF)) {
|
|
|
|
UChar c = convertFBto06 [ (inputChar - 0xFB50) ];
|
|
|
|
if (c != 0)
|
|
|
|
dest[i] = c;
|
|
|
|
} else if ( (inputChar >= 0xFE70) && (inputChar <= 0xFEFC)) {
|
|
|
|
dest[i] = convertFEto06 [ (inputChar - 0xFE70) ] ;
|
|
|
|
} else {
|
|
|
|
dest[i] = inputChar ;
|
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
|
2001-03-13 00:34:30 +00:00
|
|
|
/* sets the index to the end of the buffer, together with the step point to -1 */
|
|
|
|
i = sourceLength - 1;
|
|
|
|
iend = -1;
|
|
|
|
step = -1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function resolves the link between the characters .
|
|
|
|
* Arabic characters have four forms :
|
|
|
|
* Isolated Form, Initial Form, Middle Form and Final Form
|
|
|
|
*/
|
|
|
|
currLink = getLink(dest[i]);
|
|
|
|
|
|
|
|
lastPos = i;
|
|
|
|
Nx = -2, Nw = 0;
|
|
|
|
|
|
|
|
while (i != iend) {
|
|
|
|
/* If high byte of currLink > 0 then more than one shape */
|
2006-11-29 23:35:20 +00:00
|
|
|
if ((currLink & 0xFF00) > 0 || (getLink(dest[i]) & IRRELEVANT) != 0) {
|
2001-03-13 00:34:30 +00:00
|
|
|
Nw = i + step;
|
|
|
|
while (Nx < 0) { /* we need to know about next char */
|
|
|
|
if(Nw == iend) {
|
|
|
|
nextLink = 0;
|
|
|
|
Nx = 3000;
|
|
|
|
} else {
|
|
|
|
nextLink = getLink(dest[Nw]);
|
|
|
|
if((nextLink & IRRELEVANT) == 0) {
|
|
|
|
Nx = Nw;
|
|
|
|
} else {
|
|
|
|
Nw = Nw + step;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ((currLink & ALEFTYPE) > 0) && ((lastLink & LAMTYPE) > 0) ) {
|
|
|
|
lamalef_found = 1;
|
|
|
|
wLamalef = changeLamAlef(dest[i]); /*get from 0x065C-0x065f */
|
|
|
|
if ( wLamalef != 0) {
|
2009-03-02 15:46:03 +00:00
|
|
|
dest[i] = LAMALEF_SPACE_SUB; /* The default case is to drop the Alef and replace */
|
|
|
|
dest[lastPos] =wLamalef; /* it by LAMALEF_SPACE_SUB which is the last character in the */
|
2001-03-13 00:34:30 +00:00
|
|
|
i=lastPos; /* unicode private use area, this is done to make */
|
|
|
|
} /* sure that removeLamAlefSpaces() handles only the */
|
|
|
|
lastLink = prevLink; /* spaces generated during lamalef generation. */
|
2009-03-02 15:46:03 +00:00
|
|
|
currLink = getLink(wLamalef); /* LAMALEF_SPACE_SUB is added here and is replaced by spaces */
|
2001-03-13 00:34:30 +00:00
|
|
|
} /* in removeLamAlefSpaces() */
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2012-10-03 17:18:27 +00:00
|
|
|
if ((i > 0) && (dest[i-1] == SPACE_CHAR)){
|
|
|
|
if ( isSeenFamilyChar(dest[i])) {
|
2009-03-02 15:46:03 +00:00
|
|
|
seenfamFound = 1;
|
|
|
|
} else if (dest[i] == YEH_HAMZA_CHAR) {
|
|
|
|
yehhamzaFound = 1;
|
|
|
|
}
|
2012-10-03 17:18:27 +00:00
|
|
|
}
|
|
|
|
else if(i==0){
|
|
|
|
if ( isSeenFamilyChar(dest[i])){
|
2009-03-02 15:46:03 +00:00
|
|
|
seenfamFound = 1;
|
|
|
|
} else if (dest[i] == YEH_HAMZA_CHAR) {
|
|
|
|
yehhamzaFound = 1;
|
|
|
|
}
|
2012-10-03 17:18:27 +00:00
|
|
|
}
|
2009-03-02 15:46:03 +00:00
|
|
|
|
2011-11-21 19:38:08 +00:00
|
|
|
/*
|
2001-03-13 00:34:30 +00:00
|
|
|
* get the proper shape according to link ability of neighbors
|
|
|
|
* and of character; depends on the order of the shapes
|
|
|
|
* (isolated, initial, middle, final) in the compatibility area
|
|
|
|
*/
|
2006-11-29 23:35:20 +00:00
|
|
|
Shape = shapeTable[nextLink & (LINKR + LINKL)]
|
|
|
|
[lastLink & (LINKR + LINKL)]
|
2011-11-21 19:38:08 +00:00
|
|
|
[currLink & (LINKR + LINKL)];
|
2006-11-29 23:35:20 +00:00
|
|
|
|
|
|
|
if ((currLink & (LINKR+LINKL)) == 1) {
|
|
|
|
Shape &= 1;
|
|
|
|
} else if(isTashkeelChar(dest[i])) {
|
|
|
|
if( (lastLink & LINKL) && (nextLink & LINKR) && (tashkeelFlag == 1) &&
|
|
|
|
dest[i] != 0x064C && dest[i] != 0x064D )
|
|
|
|
{
|
2011-11-21 19:38:08 +00:00
|
|
|
Shape = 1;
|
2006-11-29 23:35:20 +00:00
|
|
|
if( (nextLink&ALEFTYPE) == ALEFTYPE && (lastLink&LAMTYPE) == LAMTYPE ) {
|
2011-11-21 19:38:08 +00:00
|
|
|
Shape = 0;
|
2006-11-29 23:35:20 +00:00
|
|
|
}
|
2012-09-27 09:09:18 +00:00
|
|
|
} else if(tashkeelFlag == 2 && dest[i] == SHADDA06_CHAR){
|
2012-10-03 17:18:27 +00:00
|
|
|
Shape = 1;
|
2012-09-27 09:09:18 +00:00
|
|
|
} else {
|
2006-11-29 23:35:20 +00:00
|
|
|
Shape = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((dest[i] ^ 0x0600) < 0x100) {
|
2009-03-02 15:46:03 +00:00
|
|
|
if ( isTashkeelChar(dest[i]) ){
|
2012-10-03 17:18:27 +00:00
|
|
|
if (tashkeelFlag == 2 && dest[i] != SHADDA06_CHAR){
|
2009-03-02 15:46:03 +00:00
|
|
|
dest[i] = TASHKEEL_SPACE_SUB;
|
|
|
|
tashkeelFound = 1;
|
2011-11-14 19:32:51 +00:00
|
|
|
} else {
|
|
|
|
/* to ensure the array index is within the range */
|
2012-02-06 19:57:08 +00:00
|
|
|
U_ASSERT(dest[i] >= 0x064Bu
|
2016-02-23 10:40:09 +00:00
|
|
|
&& dest[i]-0x064Bu < UPRV_LENGTHOF(IrrelevantPos));
|
2011-11-14 19:32:51 +00:00
|
|
|
dest[i] = 0xFE70 + IrrelevantPos[(dest[i] - 0x064B)] + Shape;
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
|
|
|
}else if ((currLink & APRESENT) > 0) {
|
2006-11-29 23:35:20 +00:00
|
|
|
dest[i] = (UChar)(0xFB50 + (currLink >> 8) + Shape);
|
2009-03-02 15:46:03 +00:00
|
|
|
}else if ((currLink >> 8) > 0 && (currLink & IRRELEVANT) == 0) {
|
2006-11-29 23:35:20 +00:00
|
|
|
dest[i] = (UChar)(0xFE70 + (currLink >> 8) + Shape);
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
2006-11-29 23:35:20 +00:00
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* move one notch forward */
|
|
|
|
if ((currLink & IRRELEVANT) == 0) {
|
2006-11-29 23:35:20 +00:00
|
|
|
prevLink = lastLink;
|
|
|
|
lastLink = currLink;
|
|
|
|
lastPos = i;
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i = i + step;
|
|
|
|
if (i == Nx) {
|
|
|
|
currLink = nextLink;
|
|
|
|
Nx = -2;
|
2006-11-29 23:35:20 +00:00
|
|
|
} else if(i != iend) {
|
2001-03-13 00:34:30 +00:00
|
|
|
currLink = getLink(dest[i]);
|
|
|
|
}
|
|
|
|
}
|
2009-03-02 15:46:03 +00:00
|
|
|
destSize = sourceLength;
|
|
|
|
if ( (lamalef_found != 0 ) || (tashkeelFound != 0) ){
|
2012-09-28 13:41:40 +00:00
|
|
|
destSize = handleGeneratedSpaces(dest,sourceLength,destSize,options,pErrorCode, shapeVars);
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if ( (seenfamFound != 0) || (yehhamzaFound != 0) ) {
|
2012-09-28 13:41:40 +00:00
|
|
|
destSize = expandCompositChar(dest, sourceLength,destSize,options,pErrorCode, SHAPE_MODE,shapeVars);
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
return destSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*Name : deShapeUnicode
|
|
|
|
*Function : Converts an Arabic Unicode buffer in FExx Range into unshaped
|
|
|
|
* arabic Unicode buffer in 06xx Range
|
|
|
|
*/
|
2001-03-22 01:26:48 +00:00
|
|
|
static int32_t
|
2001-03-13 00:34:30 +00:00
|
|
|
deShapeUnicode(UChar *dest, int32_t sourceLength,
|
|
|
|
int32_t destSize,uint32_t options,
|
2012-09-28 13:41:40 +00:00
|
|
|
UErrorCode *pErrorCode, struct uShapeVariables shapeVars) {
|
2001-03-13 00:34:30 +00:00
|
|
|
int32_t i = 0;
|
|
|
|
int32_t lamalef_found = 0;
|
2009-03-02 15:46:03 +00:00
|
|
|
int32_t yehHamzaComposeEnabled = 0;
|
|
|
|
int32_t seenComposeEnabled = 0;
|
|
|
|
|
|
|
|
yehHamzaComposeEnabled = ((options&U_SHAPE_YEHHAMZA_MASK) == U_SHAPE_YEHHAMZA_TWOCELL_NEAR) ? 1 : 0;
|
|
|
|
seenComposeEnabled = ((options&U_SHAPE_SEEN_MASK) == U_SHAPE_SEEN_TWOCELL_NEAR)? 1 : 0;
|
2001-03-13 00:34:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
*This for loop changes the buffer from the Unicode FE range to
|
|
|
|
*the Unicode 06 range
|
|
|
|
*/
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2001-03-13 00:34:30 +00:00
|
|
|
for(i = 0; i < sourceLength; i++) {
|
|
|
|
UChar inputChar = dest[i];
|
2006-11-29 23:35:20 +00:00
|
|
|
if ( (inputChar >= 0xFB50) && (inputChar <= 0xFBFF)) { /* FBxx Arabic range */
|
|
|
|
UChar c = convertFBto06 [ (inputChar - 0xFB50) ];
|
|
|
|
if (c != 0)
|
|
|
|
dest[i] = c;
|
2011-11-21 19:38:08 +00:00
|
|
|
} else if( (yehHamzaComposeEnabled == 1) && ((inputChar == HAMZA06_CHAR) || (inputChar == HAMZAFE_CHAR))
|
2009-03-02 15:46:03 +00:00
|
|
|
&& (i < (sourceLength - 1)) && isAlefMaksouraChar(dest[i+1] )) {
|
|
|
|
dest[i] = SPACE_CHAR;
|
|
|
|
dest[i+1] = YEH_HAMZA_CHAR;
|
2011-11-21 19:38:08 +00:00
|
|
|
} else if ( (seenComposeEnabled == 1) && (isTailChar(inputChar)) && (i< (sourceLength - 1))
|
2009-03-02 15:46:03 +00:00
|
|
|
&& (isSeenTailFamilyChar(dest[i+1])) ) {
|
|
|
|
dest[i] = SPACE_CHAR;
|
2006-11-29 23:35:20 +00:00
|
|
|
} else if (( inputChar >= 0xFE70) && (inputChar <= 0xFEF4 )) { /* FExx Arabic range */
|
2009-03-02 15:46:03 +00:00
|
|
|
dest[i] = convertFEto06 [ (inputChar - 0xFE70) ];
|
2001-03-13 00:34:30 +00:00
|
|
|
} else {
|
|
|
|
dest[i] = inputChar ;
|
|
|
|
}
|
2009-03-02 15:46:03 +00:00
|
|
|
|
2001-03-13 00:34:30 +00:00
|
|
|
if( isLamAlefChar(dest[i]) )
|
|
|
|
lamalef_found = 1;
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
destSize = sourceLength;
|
|
|
|
if (lamalef_found != 0){
|
2012-09-28 13:41:40 +00:00
|
|
|
destSize = expandCompositChar(dest,sourceLength,destSize,options,pErrorCode,DESHAPE_MODE, shapeVars);
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
|
|
|
return destSize;
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
|
|
|
|
2011-11-21 19:38:08 +00:00
|
|
|
/*
|
2009-03-02 15:46:03 +00:00
|
|
|
****************************************
|
|
|
|
* u_shapeArabic
|
|
|
|
****************************************
|
2011-11-21 19:38:08 +00:00
|
|
|
*/
|
2009-03-02 15:46:03 +00:00
|
|
|
|
2000-06-30 00:29:46 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
u_shapeArabic(const UChar *source, int32_t sourceLength,
|
2002-08-01 20:25:10 +00:00
|
|
|
UChar *dest, int32_t destCapacity,
|
2000-06-30 00:29:46 +00:00
|
|
|
uint32_t options,
|
|
|
|
UErrorCode *pErrorCode) {
|
2001-03-13 00:34:30 +00:00
|
|
|
|
2002-08-01 20:25:10 +00:00
|
|
|
int32_t destLength;
|
2012-10-03 17:18:27 +00:00
|
|
|
struct uShapeVariables shapeVars = { OLD_TAIL_CHAR,U_SHAPE_LAMALEF_BEGIN,U_SHAPE_LAMALEF_END,U_SHAPE_TASHKEEL_BEGIN,U_SHAPE_TASHKEEL_END,0};
|
2001-03-13 00:34:30 +00:00
|
|
|
|
2000-08-12 01:01:03 +00:00
|
|
|
/* usual error checking */
|
2000-06-30 00:29:46 +00:00
|
|
|
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-08-14 23:05:10 +00:00
|
|
|
/* make sure that no reserved options values are used; allow dest==NULL only for preflighting */
|
2006-11-29 23:35:20 +00:00
|
|
|
if( source==NULL || sourceLength<-1 || (dest==NULL && destCapacity!=0) || destCapacity<0 ||
|
2009-03-02 15:46:03 +00:00
|
|
|
(((options&U_SHAPE_TASHKEEL_MASK) > 0) &&
|
|
|
|
((options&U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED) == U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED) ) ||
|
|
|
|
(((options&U_SHAPE_TASHKEEL_MASK) > 0) &&
|
|
|
|
((options&U_SHAPE_LETTERS_MASK) == U_SHAPE_LETTERS_UNSHAPE)) ||
|
2006-11-29 23:35:20 +00:00
|
|
|
(options&U_SHAPE_DIGIT_TYPE_RESERVED)==U_SHAPE_DIGIT_TYPE_RESERVED ||
|
|
|
|
(options&U_SHAPE_DIGITS_MASK)==U_SHAPE_DIGITS_RESERVED ||
|
2009-03-02 15:46:03 +00:00
|
|
|
((options&U_SHAPE_LAMALEF_MASK) != U_SHAPE_LAMALEF_RESIZE &&
|
2006-11-29 23:35:20 +00:00
|
|
|
(options&U_SHAPE_AGGREGATE_TASHKEEL_MASK) != 0) ||
|
|
|
|
((options&U_SHAPE_AGGREGATE_TASHKEEL_MASK) == U_SHAPE_AGGREGATE_TASHKEEL &&
|
|
|
|
(options&U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED) != U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED)
|
2011-11-21 19:38:08 +00:00
|
|
|
)
|
2009-03-02 15:46:03 +00:00
|
|
|
{
|
2000-08-12 01:01:03 +00:00
|
|
|
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
2012-10-03 17:18:27 +00:00
|
|
|
/* Validate lamalef options */
|
|
|
|
if(((options&U_SHAPE_LAMALEF_MASK) > 0)&&
|
2009-03-02 15:46:03 +00:00
|
|
|
!(((options & U_SHAPE_LAMALEF_MASK)==U_SHAPE_LAMALEF_BEGIN) ||
|
|
|
|
((options & U_SHAPE_LAMALEF_MASK)==U_SHAPE_LAMALEF_END ) ||
|
|
|
|
((options & U_SHAPE_LAMALEF_MASK)==U_SHAPE_LAMALEF_RESIZE )||
|
|
|
|
((options & U_SHAPE_LAMALEF_MASK)==U_SHAPE_LAMALEF_AUTO) ||
|
|
|
|
((options & U_SHAPE_LAMALEF_MASK)==U_SHAPE_LAMALEF_NEAR)))
|
2012-10-03 17:18:27 +00:00
|
|
|
{
|
|
|
|
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
|
2009-03-02 15:46:03 +00:00
|
|
|
return 0;
|
2012-10-03 17:18:27 +00:00
|
|
|
}
|
|
|
|
/* Validate Tashkeel options */
|
|
|
|
if(((options&U_SHAPE_TASHKEEL_MASK) > 0)&&
|
2009-03-02 15:46:03 +00:00
|
|
|
!(((options & U_SHAPE_TASHKEEL_MASK)==U_SHAPE_TASHKEEL_BEGIN) ||
|
|
|
|
((options & U_SHAPE_TASHKEEL_MASK)==U_SHAPE_TASHKEEL_END )
|
|
|
|
||((options & U_SHAPE_TASHKEEL_MASK)==U_SHAPE_TASHKEEL_RESIZE )||
|
2012-10-03 17:18:27 +00:00
|
|
|
((options & U_SHAPE_TASHKEEL_MASK)==U_SHAPE_TASHKEEL_REPLACE_BY_TATWEEL)))
|
|
|
|
{
|
|
|
|
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
|
2009-03-02 15:46:03 +00:00
|
|
|
return 0;
|
2012-10-03 17:18:27 +00:00
|
|
|
}
|
2000-08-12 01:01:03 +00:00
|
|
|
/* determine the source length */
|
|
|
|
if(sourceLength==-1) {
|
|
|
|
sourceLength=u_strlen(source);
|
|
|
|
}
|
2005-08-01 22:10:20 +00:00
|
|
|
if(sourceLength<=0) {
|
2002-08-01 20:25:10 +00:00
|
|
|
return u_terminateUChars(dest, destCapacity, 0, pErrorCode);
|
2000-08-12 01:01:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check that source and destination do not overlap */
|
2000-08-14 23:05:10 +00:00
|
|
|
if( dest!=NULL &&
|
2000-10-12 19:23:35 +00:00
|
|
|
((source<=dest && dest<source+sourceLength) ||
|
2006-11-29 23:35:20 +00:00
|
|
|
(dest<=source && source<dest+destCapacity))) {
|
2000-08-12 01:01:03 +00:00
|
|
|
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
2011-11-21 19:38:08 +00:00
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
/* Does Options contain the new Seen Tail Unicode code point option */
|
2011-04-29 17:39:36 +00:00
|
|
|
if ( (options&U_SHAPE_TAIL_TYPE_MASK) == U_SHAPE_TAIL_NEW_UNICODE){
|
2012-09-28 13:41:40 +00:00
|
|
|
shapeVars.tailChar = NEW_TAIL_CHAR;
|
2009-03-02 15:46:03 +00:00
|
|
|
}else {
|
2012-09-28 13:41:40 +00:00
|
|
|
shapeVars.tailChar = OLD_TAIL_CHAR;
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
2000-08-12 01:01:03 +00:00
|
|
|
|
|
|
|
if((options&U_SHAPE_LETTERS_MASK)!=U_SHAPE_LETTERS_NOOP) {
|
2001-10-05 23:25:37 +00:00
|
|
|
UChar buffer[300];
|
2006-11-29 23:35:20 +00:00
|
|
|
UChar *tempbuffer, *tempsource = NULL;
|
2001-10-05 23:25:37 +00:00
|
|
|
int32_t outputSize, spacesCountl=0, spacesCountr=0;
|
|
|
|
|
2006-11-29 23:35:20 +00:00
|
|
|
if((options&U_SHAPE_AGGREGATE_TASHKEEL_MASK)>0) {
|
|
|
|
int32_t logical_order = (options&U_SHAPE_TEXT_DIRECTION_MASK) == U_SHAPE_TEXT_DIRECTION_LOGICAL;
|
2011-11-21 19:38:08 +00:00
|
|
|
int32_t aggregate_tashkeel =
|
|
|
|
(options&(U_SHAPE_AGGREGATE_TASHKEEL_MASK+U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED)) ==
|
2006-11-29 23:35:20 +00:00
|
|
|
(U_SHAPE_AGGREGATE_TASHKEEL+U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED);
|
|
|
|
int step=logical_order?1:-1;
|
|
|
|
int j=logical_order?-1:2*sourceLength;
|
|
|
|
int i=logical_order?-1:sourceLength;
|
|
|
|
int end=logical_order?sourceLength:-1;
|
|
|
|
int aggregation_possible = 1;
|
|
|
|
UChar prev = 0;
|
|
|
|
UChar prevLink, currLink = 0;
|
|
|
|
int newSourceLength = 0;
|
|
|
|
tempsource = (UChar *)uprv_malloc(2*sourceLength*U_SIZEOF_UCHAR);
|
|
|
|
if(tempsource == NULL) {
|
|
|
|
*pErrorCode = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((i+=step) != end) {
|
|
|
|
prevLink = currLink;
|
|
|
|
currLink = getLink(source[i]);
|
|
|
|
if (aggregate_tashkeel && ((prevLink|currLink)&COMBINE) == COMBINE && aggregation_possible) {
|
2011-11-21 19:38:08 +00:00
|
|
|
aggregation_possible = 0;
|
2006-11-29 23:35:20 +00:00
|
|
|
tempsource[j] = (prev<source[i]?prev:source[i])-0x064C+0xFC5E;
|
|
|
|
currLink = getLink(tempsource[j]);
|
|
|
|
} else {
|
|
|
|
aggregation_possible = 1;
|
|
|
|
tempsource[j+=step] = source[i];
|
|
|
|
prev = source[i];
|
|
|
|
newSourceLength++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
source = tempsource+(logical_order?0:j);
|
|
|
|
sourceLength = newSourceLength;
|
|
|
|
}
|
|
|
|
|
2001-10-05 23:25:37 +00:00
|
|
|
/* calculate destination size */
|
|
|
|
/* TODO: do we ever need to do this pure preflighting? */
|
2011-11-21 19:38:08 +00:00
|
|
|
if(((options&U_SHAPE_LAMALEF_MASK)==U_SHAPE_LAMALEF_RESIZE) ||
|
2009-03-02 15:46:03 +00:00
|
|
|
((options&U_SHAPE_TASHKEEL_MASK)==U_SHAPE_TASHKEEL_RESIZE)) {
|
2002-08-01 20:25:10 +00:00
|
|
|
outputSize=calculateSize(source,sourceLength,destCapacity,options);
|
2001-10-05 23:25:37 +00:00
|
|
|
} else {
|
|
|
|
outputSize=sourceLength;
|
|
|
|
}
|
2009-03-02 15:46:03 +00:00
|
|
|
|
2002-08-01 20:25:10 +00:00
|
|
|
if(outputSize>destCapacity) {
|
2001-10-05 23:25:37 +00:00
|
|
|
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
|
2006-11-29 23:35:20 +00:00
|
|
|
if (tempsource != NULL) uprv_free(tempsource);
|
2001-10-05 23:25:37 +00:00
|
|
|
return outputSize;
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
|
|
|
|
2002-08-01 20:25:10 +00:00
|
|
|
/*
|
|
|
|
* need a temporary buffer of size max(outputSize, sourceLength)
|
|
|
|
* because at first we copy source->temp
|
|
|
|
*/
|
|
|
|
if(sourceLength>outputSize) {
|
|
|
|
outputSize=sourceLength;
|
|
|
|
}
|
|
|
|
|
2001-03-13 00:34:30 +00:00
|
|
|
/* Start of Arabic letter shaping part */
|
2014-08-28 22:13:45 +00:00
|
|
|
if(outputSize<=UPRV_LENGTHOF(buffer)) {
|
|
|
|
outputSize=UPRV_LENGTHOF(buffer);
|
2001-10-05 23:25:37 +00:00
|
|
|
tempbuffer=buffer;
|
|
|
|
} else {
|
|
|
|
tempbuffer = (UChar *)uprv_malloc(outputSize*U_SIZEOF_UCHAR);
|
2002-06-29 09:31:05 +00:00
|
|
|
|
2002-07-03 11:59:21 +00:00
|
|
|
/*Test for NULL*/
|
|
|
|
if(tempbuffer == NULL) {
|
|
|
|
*pErrorCode = U_MEMORY_ALLOCATION_ERROR;
|
2006-11-29 23:35:20 +00:00
|
|
|
if (tempsource != NULL) uprv_free(tempsource);
|
2002-07-03 11:59:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-10-05 23:25:37 +00:00
|
|
|
}
|
2016-09-20 01:10:36 +00:00
|
|
|
u_memcpy(tempbuffer, source, sourceLength);
|
2009-03-02 15:46:03 +00:00
|
|
|
if (tempsource != NULL){
|
|
|
|
uprv_free(tempsource);
|
|
|
|
}
|
|
|
|
|
2001-10-05 23:25:37 +00:00
|
|
|
if(sourceLength<outputSize) {
|
|
|
|
uprv_memset(tempbuffer+sourceLength, 0, (outputSize-sourceLength)*U_SIZEOF_UCHAR);
|
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
|
|
|
|
if((options&U_SHAPE_TEXT_DIRECTION_MASK) == U_SHAPE_TEXT_DIRECTION_LOGICAL) {
|
|
|
|
countSpaces(tempbuffer,sourceLength,options,&spacesCountl,&spacesCountr);
|
2006-11-29 23:35:20 +00:00
|
|
|
invertBuffer(tempbuffer,sourceLength,options,spacesCountl,spacesCountr);
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
|
|
|
|
2009-03-02 15:46:03 +00:00
|
|
|
if((options&U_SHAPE_TEXT_DIRECTION_MASK) == U_SHAPE_TEXT_DIRECTION_VISUAL_LTR) {
|
|
|
|
if((options&U_SHAPE_SPACES_RELATIVE_TO_TEXT_MASK) == U_SHAPE_SPACES_RELATIVE_TO_TEXT_BEGIN_END) {
|
2012-09-28 13:41:40 +00:00
|
|
|
shapeVars.spacesRelativeToTextBeginEnd = 1;
|
|
|
|
shapeVars.uShapeLamalefBegin = U_SHAPE_LAMALEF_END;
|
|
|
|
shapeVars.uShapeLamalefEnd = U_SHAPE_LAMALEF_BEGIN;
|
|
|
|
shapeVars.uShapeTashkeelBegin = U_SHAPE_TASHKEEL_END;
|
|
|
|
shapeVars.uShapeTashkeelEnd = U_SHAPE_TASHKEEL_BEGIN;
|
2009-03-02 15:46:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-13 00:34:30 +00:00
|
|
|
switch(options&U_SHAPE_LETTERS_MASK) {
|
|
|
|
case U_SHAPE_LETTERS_SHAPE :
|
2011-11-21 19:38:08 +00:00
|
|
|
if( (options&U_SHAPE_TASHKEEL_MASK)> 0
|
2009-03-02 15:46:03 +00:00
|
|
|
&& ((options&U_SHAPE_TASHKEEL_MASK) !=U_SHAPE_TASHKEEL_REPLACE_BY_TATWEEL)) {
|
|
|
|
/* Call the shaping function with tashkeel flag == 2 for removal of tashkeel */
|
2012-09-28 13:41:40 +00:00
|
|
|
destLength = shapeUnicode(tempbuffer,sourceLength,destCapacity,options,pErrorCode,2,shapeVars);
|
2009-03-02 15:46:03 +00:00
|
|
|
}else {
|
|
|
|
/* default Call the shaping function with tashkeel flag == 1 */
|
2012-09-28 13:41:40 +00:00
|
|
|
destLength = shapeUnicode(tempbuffer,sourceLength,destCapacity,options,pErrorCode,1,shapeVars);
|
2009-03-02 15:46:03 +00:00
|
|
|
|
|
|
|
/*After shaping text check if user wants to remove tashkeel and replace it with tatweel*/
|
|
|
|
if( (options&U_SHAPE_TASHKEEL_MASK) == U_SHAPE_TASHKEEL_REPLACE_BY_TATWEEL){
|
|
|
|
destLength = handleTashkeelWithTatweel(tempbuffer,destLength,destCapacity,options,pErrorCode);
|
|
|
|
}
|
|
|
|
}
|
2001-03-13 00:34:30 +00:00
|
|
|
break;
|
2001-10-13 00:06:29 +00:00
|
|
|
case U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED :
|
2001-03-13 00:34:30 +00:00
|
|
|
/* Call the shaping function with tashkeel flag == 0 */
|
2012-09-28 13:41:40 +00:00
|
|
|
destLength = shapeUnicode(tempbuffer,sourceLength,destCapacity,options,pErrorCode,0,shapeVars);
|
2001-03-13 00:34:30 +00:00
|
|
|
break;
|
2009-03-02 15:46:03 +00:00
|
|
|
|
2001-03-13 00:34:30 +00:00
|
|
|
case U_SHAPE_LETTERS_UNSHAPE :
|
|
|
|
/* Call the deshaping function */
|
2012-09-28 13:41:40 +00:00
|
|
|
destLength = deShapeUnicode(tempbuffer,sourceLength,destCapacity,options,pErrorCode,shapeVars);
|
2001-03-13 00:34:30 +00:00
|
|
|
break;
|
|
|
|
default :
|
|
|
|
/* will never occur because of validity checks above */
|
2002-08-01 20:25:10 +00:00
|
|
|
destLength = 0;
|
2001-03-13 00:34:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-08-01 20:25:10 +00:00
|
|
|
/*
|
|
|
|
* TODO: (markus 2002aug01)
|
|
|
|
* For as long as we always preflight the outputSize above
|
|
|
|
* we should U_ASSERT(outputSize==destLength)
|
|
|
|
* except for the adjustment above before the tempbuffer allocation
|
|
|
|
*/
|
|
|
|
|
2001-03-13 00:34:30 +00:00
|
|
|
if((options&U_SHAPE_TEXT_DIRECTION_MASK) == U_SHAPE_TEXT_DIRECTION_LOGICAL) {
|
2002-08-01 20:25:10 +00:00
|
|
|
countSpaces(tempbuffer,destLength,options,&spacesCountl,&spacesCountr);
|
2006-11-29 23:35:20 +00:00
|
|
|
invertBuffer(tempbuffer,destLength,options,spacesCountl,spacesCountr);
|
2001-03-13 00:34:30 +00:00
|
|
|
}
|
2016-09-20 01:10:36 +00:00
|
|
|
u_memcpy(dest, tempbuffer, uprv_min(destLength, destCapacity));
|
2001-03-13 00:34:30 +00:00
|
|
|
|
2001-10-05 23:25:37 +00:00
|
|
|
if(tempbuffer!=buffer) {
|
2001-03-13 00:34:30 +00:00
|
|
|
uprv_free(tempbuffer);
|
|
|
|
}
|
2001-10-05 23:25:37 +00:00
|
|
|
|
2002-08-01 20:25:10 +00:00
|
|
|
if(destLength>destCapacity) {
|
2001-10-05 23:25:37 +00:00
|
|
|
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
|
2002-08-01 20:25:10 +00:00
|
|
|
return destLength;
|
2001-10-05 23:25:37 +00:00
|
|
|
}
|
|
|
|
|
2001-03-13 00:34:30 +00:00
|
|
|
/* End of Arabic letter shaping part */
|
2000-08-12 01:01:03 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* No letter shaping:
|
|
|
|
* just make sure the destination is large enough and copy the string.
|
|
|
|
*/
|
2002-08-01 20:25:10 +00:00
|
|
|
if(destCapacity<sourceLength) {
|
2000-08-14 23:05:10 +00:00
|
|
|
/* this catches preflighting, too */
|
2000-08-12 01:01:03 +00:00
|
|
|
*pErrorCode=U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
return sourceLength;
|
|
|
|
}
|
2016-09-20 01:10:36 +00:00
|
|
|
u_memcpy(dest, source, sourceLength);
|
2002-08-01 20:25:10 +00:00
|
|
|
destLength=sourceLength;
|
2000-08-12 01:01:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform number shaping.
|
|
|
|
* With UTF-16 or UTF-32, the length of the string is constant.
|
|
|
|
* The easiest way to do this is to operate on the destination and
|
|
|
|
* "shape" the digits in-place.
|
|
|
|
*/
|
|
|
|
if((options&U_SHAPE_DIGITS_MASK)!=U_SHAPE_DIGITS_NOOP) {
|
|
|
|
UChar digitBase;
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
/* select the requested digit group */
|
|
|
|
switch(options&U_SHAPE_DIGIT_TYPE_MASK) {
|
|
|
|
case U_SHAPE_DIGIT_TYPE_AN:
|
|
|
|
digitBase=0x660; /* Unicode: "Arabic-Indic digits" */
|
|
|
|
break;
|
|
|
|
case U_SHAPE_DIGIT_TYPE_AN_EXTENDED:
|
|
|
|
digitBase=0x6f0; /* Unicode: "Eastern Arabic-Indic digits (Persian and Urdu)" */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* will never occur because of validity checks above */
|
2000-08-21 21:40:35 +00:00
|
|
|
digitBase=0;
|
2000-08-12 01:01:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* perform the requested operation */
|
|
|
|
switch(options&U_SHAPE_DIGITS_MASK) {
|
|
|
|
case U_SHAPE_DIGITS_EN2AN:
|
|
|
|
/* add (digitBase-'0') to each European (ASCII) digit code point */
|
|
|
|
digitBase-=0x30;
|
2002-08-01 20:25:10 +00:00
|
|
|
for(i=0; i<destLength; ++i) {
|
2000-08-12 01:01:03 +00:00
|
|
|
if(((uint32_t)dest[i]-0x30)<10) {
|
|
|
|
dest[i]+=digitBase;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case U_SHAPE_DIGITS_AN2EN:
|
|
|
|
/* subtract (digitBase-'0') from each Arabic digit code point */
|
2002-08-01 20:25:10 +00:00
|
|
|
for(i=0; i<destLength; ++i) {
|
2000-08-12 01:01:03 +00:00
|
|
|
if(((uint32_t)dest[i]-(uint32_t)digitBase)<10) {
|
|
|
|
dest[i]-=digitBase-0x30;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case U_SHAPE_DIGITS_ALEN2AN_INIT_LR:
|
2002-08-01 20:25:10 +00:00
|
|
|
_shapeToArabicDigitsWithContext(dest, destLength,
|
2000-08-12 01:01:03 +00:00
|
|
|
digitBase,
|
|
|
|
(UBool)((options&U_SHAPE_TEXT_DIRECTION_MASK)==U_SHAPE_TEXT_DIRECTION_LOGICAL),
|
|
|
|
FALSE);
|
|
|
|
break;
|
|
|
|
case U_SHAPE_DIGITS_ALEN2AN_INIT_AL:
|
2002-08-01 20:25:10 +00:00
|
|
|
_shapeToArabicDigitsWithContext(dest, destLength,
|
2000-08-12 01:01:03 +00:00
|
|
|
digitBase,
|
|
|
|
(UBool)((options&U_SHAPE_TEXT_DIRECTION_MASK)==U_SHAPE_TEXT_DIRECTION_LOGICAL),
|
|
|
|
TRUE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* will never occur because of validity checks above */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-01 20:25:10 +00:00
|
|
|
return u_terminateUChars(dest, destCapacity, destLength, pErrorCode);
|
2000-06-30 00:29:46 +00:00
|
|
|
}
|