static public boolean moreThanMaxCodes(TextFragment tf) { List<Code> codes = tf.getCodes(); return codes.size() > MAX_INLINE_CODES; }
public GenericContent setContent (TextFragment content) { codedText = content.getCodedText(); codes = content.getCodes(); return this; }
/** * Gets a list of the copy of the codes for this fragment. * @return the list of the copy of the codes for this fragment. If there is no code, an empty list is returned. */ public List<Code> getClonedCodes () { ArrayList<Code> clones = new ArrayList<Code>(); for ( Code code : getCodes() ) { clones.add(code.clone()); } return clones; }
@Override public int hashCode() { return Objects.hash(getText(), getCodes()); }
/** * Sets the fragment to format. * @param content The TextFragment object to format. * @return Itself */ public TMXContent setContent (TextFragment content) { codedText = content.getCodedText(); codes = content.getCodes(); return this; }
private static boolean isLeadingCode(Code code, TextFragment oriSrc) { int index = oriSrc.getCodes().indexOf(code); if (index == -1) return false; String ctext = oriSrc.getCodedText(); int pos = ctext.indexOf(String.valueOf(TextFragment.toChar(index)), 0); if (pos == -1) return false; // Remove all codes from the beginning of the string before the pos and see if any text remains String substr = ctext.substring(0, pos - 1); substr = TextFragment.MARKERS_REGEX.matcher(substr).replaceAll(""); return substr.trim().length() == 0; }
private Field createCodesField(TranslationUnitField field, TextFragment frag, Field.Store store, Field.Index index) { // We don't keep the outerData in the codes return new Field(field.name(), Code.codesToString(frag.getCodes(), true), store, index); } }
/** * Creates a TextFragment with the content of a given TextFragment. * @param fragment the content to use. */ public TextFragment (TextFragment fragment) { this.setCodedText(fragment.getCodedText(), fragment.getCodes(), false); this.lastCodeID = fragment.lastCodeID; }
public static boolean hasMergedCode(TextFragment tf) { if (tf == null || tf.isEmpty()) { return false; } for (Code c : tf.getCodes()) { if (c.isMerged()) { return true; } } return false; }
/** * Reduce the IDs for all codes in a TextFragment by a fixed amount. * @param tf * @param offset */ private static void reduceCodeIdsByOffset(TextFragment tf, int offset) { for (Code code : tf.getCodes()) { code.setId(code.getId() - offset); } }
/** * Sets the fragment to format. * @param content The TextFragment object to format. * @param resetStandoff true to reset the ITS standoff items (e.g. when the fragment is the whole content of a text container). * @return Itself */ public XLIFFContent setContent (TextFragment content, boolean resetStandoff) { codedText = content.getCodedText(); codes = content.getCodes(); // Check if we need to reset the standoff items if ( resetStandoff ) clearStandoff(); return this; }
private void mergeSegment(Segment segment) { TextFragment textFragment = segment.getContent(); String codedText = textFragment.getCodedText(); List<Code> codes = textFragment.getCodes(); for (int i = 0; i < codedText.length(); i++) { char c = codedText.charAt(i); if (!TextFragment.isMarker(c)) { addChar(c); continue; } int codeIndex = TextFragment.toIndex(codedText.charAt(++i)); addCode(codes.get(codeIndex)); } }
private static int incrementCodeIdsByOffset(TextFragment tf, int delta) { int count = 0; for ( Code code : tf.getCodes() ) { code.setId(code.getId() + delta); if (code.getTagType() != TagType.CLOSING) count++; } return count; } }
public void setText (TextFragment oriFrag) { modified = false; textCont = null; textFrag = oriFrag; edit.setEnabled(oriFrag != null); if ( oriFrag == null ) { edit.setText(""); } else { codedText = textFrag.getCodedText(); // Make a copy of the list, as getCodes() gives an un-modifiable list codes = new ArrayList<Code>(textFrag.getCodes()); updateText(null); } }
/** * Writes a text fragment. * @param tf the text fragment to write out. */ public void write (TextFragment tf) { try { writeLongString(tf.getCodedText()); writeLongString(Code.codesToString(tf.getCodes())); } catch ( IOException e ) { throw new OkapiException("Error while writing.", e); } }
private void checkInlineCodes (TextFragment tf) { if ( params.getUseCodeFinder() ) { params.getCodeFinder().process(tf); } // Escape inline code content List<Code> codes = tf.getCodes(); for ( Code code : codes ) { // Escape the data of the new inline code (and only them) if ( code.getType().equals(InlineCodeFinder.TAGTYPE) ) { code.setData(encoder.encode(code.getData(), EncoderContext.SKELETON)); } } }
public void simplifyOpeningClosing (TextFragment tf) { prepare(tf.getCodedText(), tf.getCodes()); simplifyOpeningClosing(); tf.setCodedText(getCodedText(), getCodes()); }
/** * Simplifies the place-holders in a given text fragment. * @param tf the text fragment to modify. */ public void simplifyIsolated (TextFragment tf) { prepare(tf.getCodedText(), tf.getCodes()); simplifyIsolated(); tf.setCodedText(getCodedText(), getCodes()); }
public void simplifyEmptyOpeningClosing (TextFragment tf) { prepare(tf.getCodedText(), tf.getCodes()); simplifyEmptyOpeningClosing(); tf.setCodedText(getCodedText(), getCodes()); }
private void convertTextContainer (TextContainer tc) { for ( TextPart textPart : tc ) { TextFragment tf = textPart.getContent(); for (Code code : tf.getCodes()) { if (!code.hasReference()) continue; String data = code.getOuterData(); String newData = convertRefIds(data); if ( code.hasOuterData() ) { code.setOuterData(newData); } else { code.setData(newData); } } } }