/** * Returns the fully hyphenated string. * The given hyphen characters are inserted at all possible hyphenation points. * @param text The string to be hyphenated * @param shy The character to be used as soft hyphen. * @param zwsp The character to be used as zero-width space. * @return The hyphenated string * @throws StandardHyphenationException if the word contains non-standard hyphenation * points, in which case the method {@link #hyphenate(String, int, Character, * Character)} should be used instead. */ public String hyphenate(String text, Character shy, Character zwsp) throws StandardHyphenationException { if (shy == null && zwsp == null) return text; byte[] hyphens = hyphenate(text); StringBuffer hyphenatedText = new StringBuffer(); int i; for (i = 0; i < hyphens.length; i++) { hyphenatedText.append(text.charAt(i)); if (shy != null && hyphens[i] == SHY) hyphenatedText.append(shy); else if (zwsp != null && hyphens[i] == ZWSP) hyphenatedText.append(zwsp); } hyphenatedText.append(text.charAt(i)); return hyphenatedText.toString(); }
private String transform(String text) { try { Tuple2<String,byte[]> t = extractHyphens(text, SHY, ZWSP); byte[] hyphens = hyphenator.hyphenate(t._1); if (t._2 != null) for (int i = 0; i < hyphens.length; i++) hyphens[i] += t._2[i]; return insertHyphens(t._1, hyphens, SHY, ZWSP); } catch (Exception e) { throw new RuntimeException("Error during libhyphen hyphenation", e); } }
protected String hyphenate(String text, int lineLength, Character hyphen, Character noHyphen) { Break b = hyphenate(text, lineLength); String hyphenatedText = ""; hyphenatedText += b.getText().substring(0, b.getBreakPosition()); if (b.hasHyphen()) { if (hyphen != null) hyphenatedText += hyphen; } else if (noHyphen != null) hyphenatedText += noHyphen; hyphenatedText += b.getText().substring(b.getBreakPosition()); return hyphenatedText; }
else positions = new byte[_text.length() - 1]; byte[] autoHyphens = hyphenator.hyphenate(_text); for (int i = 0; i < autoHyphens.length; i++) positions[i] += autoHyphens[i];
protected Break breakWord(String word, int limit, boolean force) { Hyphenator.Break br = hyphenator.hyphenate(word, limit); if (force && br.getBreakPosition() == 0) return new Break(word, limit, false); else return new Break(br.getText(), br.getBreakPosition(), br.hasHyphen()); } };