/** * Removes the part at s given position. * <p> * If the selected part is the last segment in the content, the part * is only cleared, not removed. * * @param partIndex the position of the part to remove. */ public void remove(int partIndex) { if ( parts.get(partIndex).isSegment() && hasOnlyOneSegment() ){ // If it's the last segment, just clear it, don't remove it. parts.get(partIndex).text.clear(); } else { parts.remove(partIndex); } }
/** * Removes all inline tags from the given {@link TextFragment} * @param tf the given text fragment */ public static void removeCodes(TextFragment tf) { StringBuilder tmp = new StringBuilder(); StringBuilder text = new StringBuilder(tf.getText()); for (int i=0; i<text.length(); i++) { switch (text.charAt(i)) { case TextFragment.MARKER_OPENING: case TextFragment.MARKER_CLOSING: case TextFragment.MARKER_ISOLATED: i++; // skip index marker as well break; default: tmp.append(text.charAt(i)); break; } } tf.clear(); tf.setCodedText(tmp.toString()); }
/** * Effectively marks the segment for removal by emptying the content for the * given target. the text unit will be pruned by a different method * ({@link #pruneTextUnit(ITextUnit, LocaleId)}). * * @param tu the text unit containing the content * @param seg the segment to be marked for removal * @param targetLocale the locale for which the segment should be removed */ protected void markSegmentForRemoval(ITextUnit tu, Segment seg, LocaleId targetLocale) { tu.getTargetSegment(targetLocale, seg.getId(), false).getContent().clear(); }
@Override public TextContainer createTarget (LocaleId targetLocale, boolean overwriteExisting, int creationOptions) { TextContainer trgCont = targets.get(targetLocale); if (( trgCont == null ) || overwriteExisting ) { trgCont = getSource().clone((creationOptions & COPY_PROPERTIES) == COPY_PROPERTIES); if ( (creationOptions & COPY_SEGMENTATION) != COPY_SEGMENTATION ) { trgCont.joinAll(); } if ( (creationOptions & COPY_CONTENT) != COPY_CONTENT ) { for ( Segment seg : trgCont.getSegments() ) { seg.text.clear(); } } targets.put(targetLocale, trgCont); } return trgCont; }