Move HandleNumbers() from nsBidiPresUtils to nsBidiUtils. Bug 137857. r=ftang, sr=attinasi

This commit is contained in:
smontagu@netscape.com 2007-06-28 13:02:44 -07:00
parent c97787962e
commit 4c75e3d163
2 changed files with 64 additions and 0 deletions

View File

@ -228,6 +228,16 @@ static PRUint16 gArabicLigatureMap[] =
0x8EE0 // 0xFE8E 0xFEE0 -> 0xFEFC
};
#define ARABIC_TO_HINDI_DIGIT_INCREMENT (START_HINDI_DIGITS - START_ARABIC_DIGITS)
#define NUM_TO_ARABIC(c) \
((((c)>=START_HINDI_DIGITS) && ((c)<=END_HINDI_DIGITS)) ? \
((c) - (PRUint16)ARABIC_TO_HINDI_DIGIT_INCREMENT) : \
(c))
#define NUM_TO_HINDI(c) \
((((c)>=START_ARABIC_DIGITS) && ((c)<=END_ARABIC_DIGITS)) ? \
((c) + (PRUint16)ARABIC_TO_HINDI_DIGIT_INCREMENT): \
(c))
nsresult ArabicShaping(const PRUnichar* aString, PRUint32 aLen,
PRUnichar* aBuf, PRUint32 *aBufLen)
{
@ -459,4 +469,40 @@ nsresult Conv_06_FE_WithReverse(const nsString& aSrc,
}// for : loop the buffer
return NS_OK;
}
nsresult HandleNumbers(PRUnichar* aBuffer, PRUint32 aSize, PRUint32 aNumFlag)
{
PRUint32 i;
// IBMBIDI_NUMERAL_REGULAR *
// IBMBIDI_NUMERAL_HINDICONTEXT
// IBMBIDI_NUMERAL_ARABIC
// IBMBIDI_NUMERAL_HINDI
switch (aNumFlag) {
case IBMBIDI_NUMERAL_HINDI:
for (i=0;i<aSize;i++)
aBuffer[i] = NUM_TO_HINDI(aBuffer[i]);
break;
case IBMBIDI_NUMERAL_ARABIC:
for (i=0;i<aSize;i++)
aBuffer[i] = NUM_TO_ARABIC(aBuffer[i]);
break;
default : // IBMBIDI_NUMERAL_REGULAR, IBMBIDI_NUMERAL_HINDICONTEXT for HandleNum() which is called for clipboard handling
for (i=1;i<aSize;i++) {
if (IS_ARABIC_CHAR(aBuffer[i-1]))
aBuffer[i] = NUM_TO_HINDI(aBuffer[i]);
else
aBuffer[i] = NUM_TO_ARABIC(aBuffer[i]);
}
break;
}
return NS_OK;
}
nsresult HandleNumbers(const nsString& aSrc, nsString& aDst)
{
aDst = aSrc;
return HandleNumbers((PRUnichar *)aDst.get(),aDst.Length(), IBMBIDI_NUMERAL_REGULAR);
}
#endif //IBMBIDI

View File

@ -67,6 +67,24 @@
*/
nsresult Conv_06_FE_WithReverse(const nsString& aSrc, nsString& aDst, PRUint32 aDir);
/**
* Scan a Unichar string, converting numbers to Arabic or Hindi forms in place
* @param aBuffer is the string
* @param aSize is the size of aBuffer
* @param aNumFlag specifies the conversion to perform:
* IBMBIDI_NUMERAL_HINDI: convert to Hindi forms (Unicode 0660-0669)
* IBMBIDI_NUMERAL_ARABIC: convert to Arabic forms (Unicode 0030-0039)
* IBMBIDI_NUMERAL_HINDICONTEXT: convert numbers in Arabic text to Hindi, otherwise to Arabic
*/
nsresult HandleNumbers(PRUnichar* aBuffer, PRUint32 aSize, PRUint32 aNumFlag);
/**
* Scan an nsString, converting numerals to Arabic or Hindi forms
* @param aSrc is the input string
* @param aDst is the output string
*/
nsresult HandleNumbers(const nsString& aSrc, nsString& aDst);
// --------------------------------------------------
// IBMBIDI
// --------------------------------------------------