/** * Gets text of a given text fragment object possibly containing inline codes. * * @param textFragment * the given text fragment object. * @return the text of the given text fragment object possibly containing inline codes. */ public static String getCodedText (TextFragment textFragment) { if (textFragment == null) return ""; return textFragment.getCodedText(); }
public GenericContent setContent (TextFragment content) { codedText = content.getCodedText(); codes = content.getCodes(); return this; }
/** * 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 void assembleSegmentContent(Segment segment, StringBuilder textContentBuilder) { TextFragment content = segment.getContent(); String codedText = content.getCodedText(); for (int i = 0; i < codedText.length(); i++) { char c = codedText.charAt(i); textContentBuilder.append(c); } } }
private Field createRawCodedTextField(TranslationUnitField fieldType, TextFragment frag, Field.Store store, Field.Index index) { return new Field(fieldType.name(), frag.getCodedText(), store, index); }
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 String toMIFString (TextFragment tf) { String ctext = tf.getCodedText(); StringBuilder tmp = new StringBuilder(); for ( int i=0; i<ctext.length(); i++ ) { char ch = ctext.charAt(i); if ( TextFragment.isMarker(ch) ) { tmp.append(tf.getCode(ctext.charAt(++i))); } else { tmp.append(encoder.encode(ch, EncoderContext.SKELETON)); } } return tmp.toString(); }
private void processFragment (TextFragment frag) { String text = frag.getCodedText(); String result = changeWidth(text, params); // Record if we modified something wasModified = !text.equals(result); // Set back the modified text frag.setCodedText(result); }
/** * Gets the coded text of the first part of the source of a given text unit resource. * * @param textUnit * the text unit resource which source text should be returned. * @return the source part of the given text unit resource. */ public static String getSourceText (ITextUnit textUnit) { // if ( textUnit == null ) return ""; // return getCodedText(textUnit.getSourceContent()); return textUnit.getSource().getFirstContent().getCodedText(); }
/** * 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; }
/** * 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; }
/** * Deletes the last non-whitespace and non-code character of a given text fragment. * * @param textFragment * the text fragment to examine. */ public static void deleteLastChar (TextFragment textFragment) { if (textFragment == null) return; String st = textFragment.getCodedText(); int pos = TextFragment.indexOfLastNonWhitespace(st, -1, 0, true, true, true, true); if (pos == -1) return; textFragment.remove(pos, pos + 1); }
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)); } }
/** * Clones this TextFragment. * @return a new TextFragment that is a copy of this one. */ @Override public TextFragment clone () { TextFragment tf = new TextFragment(this.getCodedText(), this.getClonedCodes()); tf.lastCodeID = this.getLastCodeId(); return tf; }
@Override protected ITextUnit postProcessTextUnit(ITextUnit textUnit) { TextFragment text = textUnit.getSource().getFirstContent(); text.setCodedText(text.getCodedText()); if ( codeFinder != null ) { encoderManager.updateEncoder(textUnit.getMimeType()); codeFinder.process(text); } text.setCodedText(text.getCodedText()); return textUnit; }
private TextFragment toAbstract (TextFragment frag) { // If the entry is from extraction/merge mode try to convert the inline codes if ( originalTuId != null ) { // At this point the fragment should not be segmented nor have any inline codes GenericContent.fromLetterCodedToFragment(frag.getCodedText(), frag, false, true); } else { // Else: Normal PO entry // Sets the inline codes if ( params.getUseCodeFinder() ) { params.getCodeFinder().process(frag); } } return frag; }
/** * 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); } }
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()); }