ArabicShaping as = new ArabicShaping(ArabicShaping.LETTERS_SHAPE | ArabicShaping.LENGTH_GROW_SHRINK); try { s = as.shape(s); } catch (ArabicShapingException e) { LOG.error(e.getMessage(), e);
/** * 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); }
@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; } }
@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) { } } }
/** * 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); }