thisJ = eNJ;
thisJ = leftNoTrJ = eNJ;
nsresult ArabicShaping(const PRUnichar* aString, PRUint32 aLen,                       PRUnichar* aBuf, PRUint32 *aBufLen,                        PRBool aInputLogical, PRBool aOutputLogical){  nsAutoString tempString(aString, aLen);  PRUnichar *tempBuf = NS_CONST_CAST(PRUnichar*, tempString.get());  if (aInputLogical) {    ReverseString(tempBuf, aLen);  }  const PRUnichar* src = tempBuf;  const PRUnichar* p;  PRUnichar* dest = aBuf;  PRUnichar formB;  PRInt8 leftJ, thisJ, rightJ;  PRInt8 leftNoTrJ, rightNoTrJ;  thisJ = eNJ;  rightJ = GetJoiningClass(*(src));  while(src<tempBuf+aLen-1) {    leftJ = thisJ;    if ((eTr != leftJ) || ((leftJ == eTr) &&         ( ( (src-1) >= tempBuf) && !IS_ARABIC_CHAR(*(src-1)))))      leftNoTrJ = thisJ;    if(src-2 >= (tempBuf)){      for(p=src-2; (p >= (tempBuf))&& (eTr == leftNoTrJ) && (IS_ARABIC_CHAR(*(p+1))) ; p--)          leftNoTrJ = GetJoiningClass(*(p)) ;    }    thisJ = rightJ;    rightJ = rightNoTrJ = GetJoiningClass(*(src+1)) ;    if(src+2 <= (tempBuf+aLen-1)){      for(p=src+2; (p <= (tempBuf+aLen-1))&&(eTr == rightNoTrJ) && (IS_ARABIC_CHAR(*(src+1))); p++)        rightNoTrJ = GetJoiningClass(*(p)) ;    }    formB = PresentationFormB(*src, DecideForm(leftNoTrJ, thisJ, rightNoTrJ));    *dest++ = formB;    src++;  }  if((eTr != thisJ) ||      ((thisJ == eTr) && (((src-1)>=tempBuf) && (!IS_ARABIC_CHAR(*(src-1))))))    leftNoTrJ = thisJ;  if(src-2 >= (tempBuf)){    for(p=src-2; (src-2 >= (tempBuf)) && (eTr == leftNoTrJ) && (IS_ARABIC_CHAR(*(p+1))); p--)      leftNoTrJ = GetJoiningClass(*(p)) ;  }  formB = PresentationFormB(*src, DecideForm(leftNoTrJ, rightJ, eNJ));  *dest++ = formB;  src++;  PRUnichar *lSrc = aBuf;  PRUnichar *lDest = aBuf;  while(lSrc < (dest-1)) {    PRUnichar next = *(lSrc+1);    if(((0xFEDF == next) || (0xFEE0 == next)) &&        (0xFE80 == (0xFFF1 & *lSrc))) {      PRBool done = PR_FALSE;      PRUint16 key = ((*lSrc) << 8) | ( 0x00FF & next);      PRUint16 i;      for(i=0;i<8;i++) {        if(key == gArabicLigatureMap[i]) {          done = PR_TRUE;          // lam and alef in the source are mapped to a lam-alef ligature in the          // destination, so lSrc is incremented by 2 here          *lDest++ = 0xFEF5 + i;          lSrc+=2;          break;        }      }      if(! done)        *lDest++ = *lSrc++;     }     else       *lDest++ = *lSrc++;   }  if(lSrc < dest)    *lDest++ = *lSrc++;   *aBufLen = lDest - aBuf;  if (aOutputLogical) {    ReverseString(aBuf, *aBufLen);  }  return NS_OK;}