ArabicShaping as = new ArabicShaping(ArabicShaping.LETTERS_SHAPE | ArabicShaping.LENGTH_GROW_SHRINK); try { s = as.shape(s); } catch (ArabicShapingException e) { LOG.error(e.getMessage(), e);
int lamalef_count = normalize(dest, start, length); boolean yehhamza_found = false, tashkeel_found = false; int i = start + length - 1; int currLink = getLink(dest[i]); int nextLink = 0; int prevLink = 0; if ((currLink & '\uFF00') != 0 || isTashkeelChar(dest[i])) { nw = i - 1; nx = -2; nx = Integer.MAX_VALUE; } else { nextLink = getLink(dest[nw]); if ((nextLink & IRRELEVANT) == 0) { nx = nw; char wLamalef = changeLamAlef(dest[i]); // get from 0x065C-0x065f if (wLamalef != '\u0000') { currLink = getLink(wLamalef); // requires '\u0000', unfortunately if ( isSeenFamilyChar(dest[i]) == 1){ seenfam_found = true; } else if (dest[i] == YEH_HAMZA_CHAR) { if ( isSeenFamilyChar(dest[i]) == 1){ seenfam_found = true;
/** * Convert a string, returning the new string. * * @param text the string to convert * @return the converted string * @throws ArabicShapingException if the string cannot be converted according to the options. * @stable ICU 2.0 */ public String shape(String text) throws ArabicShapingException { char[] src = text.toCharArray(); char[] dest = src; if (((options & LAMALEF_MASK) == LAMALEF_RESIZE) && ((options & LETTERS_MASK) == LETTERS_UNSHAPE)) { dest = new char[src.length * 2]; // max } int len = shape(src, 0, src.length, dest, 0, dest.length); return new String(dest, 0, len); }
((options & LAMALEF_MASK) == LAMALEF_RESIZE)) { return calculateSize(source, sourceStart, sourceLength); } else { return sourceLength; // by definition invertBuffer(temp, 0, sourceLength); outputSize = shapeUnicode(temp, 0, sourceLength, destSize, 1); break; outputSize = shapeUnicode(temp, 0, sourceLength, destSize, 2); }else { outputSize = shapeUnicode(temp, 0, sourceLength, destSize, 0); outputSize = handleTashkeelWithTatweel(temp,sourceLength); outputSize = deShapeUnicode(temp, 0, sourceLength, destSize); break; shapeToArabicDigitsWithContext(temp, 0, outputSize, digitBase, false); break; shapeToArabicDigitsWithContext(temp, 0, outputSize, digitBase, true); break; invertBuffer(temp, 0, outputSize);
int wL = countSpaceSub(dest, length, LAMALEF_SPACE_SUB); int wT = countSpaceSub(dest, length, TASHKEEL_SPACE_SUB); shiftArray(dest, start, e, LAMALEF_SPACE_SUB); while (wL > start) { dest[--wL] = SPACE_CHAR; shiftArray(dest, start, e, TASHKEEL_SPACE_SUB); while (wT > start) { dest[--wT] = SPACE_CHAR; shiftArray(dest, start, e, LAMALEF_SPACE_SUB); wL = flipArray(dest,start,e, wL); length = wL - start; shiftArray(dest, start, e, TASHKEEL_SPACE_SUB); wT = flipArray(dest,start,e, wT); length = wT - start; shiftArray(dest, start, e, LAMALEF_SPACE_SUB); wL = flipArray(dest,start,e, wL); while (wL < e) { dest[wL++] = SPACE_CHAR; shiftArray(dest, start, e, TASHKEEL_SPACE_SUB); wT = flipArray(dest,start,e, wT); while (wT < e) { dest[wT++] = SPACE_CHAR;
private int deShapeUnicode(char[] dest, int start, int length, int destSize) throws ArabicShapingException { int lamalef_count = deshapeNormalize(dest, start, length); // If there was a lamalef in the buffer call expandLamAlef if (lamalef_count != 0) { // need to adjust dest to fit expanded buffer... !!! destSize = expandCompositChar(dest, start, length, lamalef_count,DESHAPE_MODE); } else { destSize = length; } return destSize; }
private boolean expandCompositCharAtEnd(char[] dest,int start, int length, int lacount){ boolean spaceNotFound = false; if (lacount > countSpacesLeft(dest, start, length)) { spaceNotFound = true; return spaceNotFound; } for (int r = start + lacount, w = start, e = start + length; r < e; ++r) { char ch = dest[r]; if (isNormalizedLamAlefChar(ch)) { dest[w++] = convertNormalizedLamAlef[ch - '\u065C']; dest[w++] = LAM_CHAR; } else { dest[w++] = ch; } } return spaceNotFound; }
private boolean expandCompositCharAtBegin(char[] dest,int start, int length, int lacount) { boolean spaceNotFound = false; if (lacount > countSpacesRight(dest, start, length)) { spaceNotFound = true; return spaceNotFound; } for (int r = start + length - lacount, w = start + length; --r >= start;) { char ch = dest[r]; if (isNormalizedLamAlefChar(ch)) { dest[--w] = LAM_CHAR; dest[--w] = convertNormalizedLamAlef[ch - '\u065C']; } else { dest[--w] = ch; } } return spaceNotFound; }
@Override public String shapeText(String text) { try { return shaper.shape(text); } catch (ArabicShapingException e) { XRLog.general(Level.WARNING, "Exception while shaping text", e); return text; } }
@Override public String deshapeText(String text) { try { return deshaper.shape(text); } catch (ArabicShapingException e) { XRLog.general(Level.WARNING, "Exception while deshaping text", e); return text; } }
/** * Performs digit and letter shaping * * @param options Shaping options covering both letters and digits */ private void shapeArabic(int options) { if (options != 0) { ArabicShaping shaper = new ArabicShaping(options); try { text = shaper.shape(text); } catch(ArabicShapingException e) { } } }
@Override public String shapeText(String text) { try { return shaper.shape(text); } catch (ArabicShapingException e) { XRLog.general(Level.WARNING, "Exception while shaping text", e); return text; } }
@Override public String deshapeText(String text) { try { return deshaper.shape(text); } catch (ArabicShapingException e) { XRLog.general(Level.WARNING, "Exception while deshaping text", e); return text; } }
/** * Convert a range of text in place. This may only be used if the Length option * does not grow or shrink the text. * * @param source An array containing the input text * @param start The start of the range of text to convert * @param length The length of the range of text to convert * @throws ArabicShapingException if the text cannot be converted according to the options. * @stable ICU 2.0 */ public void shape(char[] source, int start, int length) throws ArabicShapingException { if ((options & LAMALEF_MASK) == LAMALEF_RESIZE) { throw new ArabicShapingException("Cannot shape in place with length option resize."); } shape(source, start, length, source, start, length); }