All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.okapi.steps.codesremoval.CodesRemover Maven / Gradle / Ivy

/*===========================================================================
  Copyright (C) 2009-2011 by the Okapi Framework contributors
-----------------------------------------------------------------------------
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
===========================================================================*/

package net.sf.okapi.steps.codesremoval;

import java.util.ArrayList;
import java.util.List;

import net.sf.okapi.common.LocaleId;
import net.sf.okapi.common.resource.Code;
import net.sf.okapi.common.resource.ITextUnit;
import net.sf.okapi.common.resource.TextContainer;
import net.sf.okapi.common.resource.TextFragment;
import net.sf.okapi.common.resource.TextPart;

public class CodesRemover {

	private Parameters params;
	private LocaleId targetLocale;

	public CodesRemover (Parameters params,
		LocaleId targetLocale)
	{
		this.params = params;
		this.targetLocale = targetLocale;
	}

	public void processTextUnit (ITextUnit tu) {
		// Skip non-translatable if requested
		if ( !tu.isTranslatable() ) {
			if ( !params.getIncludeNonTranslatable() ) return;
		}

		// Process source if needed
		if ( params.getStripSource() ) {
			processContainer(tu.getSource());
		}
		
		// Process target if needed
		if ( params.getStripTarget() ) {
			if ( tu.hasTarget(targetLocale) ) {
				processContainer(tu.getTarget(targetLocale));
			}
		}
	}

	public void processContainer (TextContainer tc) {
		for ( TextPart part : tc ) {
			processFragment(part.text);
		}
	}
	
	public void processFragment (TextFragment tf) {
		String text = tf.getCodedText();
		List codes = tf.getCodes();
		StringBuilder tmp = new StringBuilder();
		ArrayList remaining = new ArrayList<>();

		// Go through the content
		Code code;
		for ( int i=0; i") 
				|| data.contains("
") || data.contains("
") || data.contains("\n") || data.contains("\r") || data.contains("\u0085") //A next-line character || data.contains("\u2028") //A line-separator character || data.contains("\u2029") //A paragraph-separator character )) return true; return false; } }