net.sf.okapi.common.encoder.DefaultEncoder Maven / Gradle / Ivy
/*===========================================================================
Copyright (C) 2010 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.common.encoder;
import java.nio.charset.CharsetEncoder;
import net.sf.okapi.common.IParameters;
/**
* Implements {@link IEncoder} for non-specific formats. It only converts the line-breaks to the proper type.
*/
public class DefaultEncoder implements IEncoder {
private String lineBreak;
@Override
public void reset() { }
@Override
public void setOptions (IParameters params,
String encoding,
String lineBreak)
{
this.lineBreak = lineBreak;
}
@Override
public String encode (String text,
EncoderContext context)
{
return text.replace("\n", lineBreak);
}
@Override
public String encode (char value,
EncoderContext context)
{
return String.valueOf(value).replace("\n", lineBreak);
}
@Override
public String encode (int value,
EncoderContext context)
{
if ( Character.isSupplementaryCodePoint(value) ) {
return new String(Character.toChars(value)).replace("\n", lineBreak);
}
return String.valueOf((char)value).replace("\n", lineBreak);
}
@Override
public String toNative (String propertyName,
String value)
{
return value;
}
@Override
public String getLineBreak () {
return this.lineBreak;
}
public void setLineBreak(String lineBreak) {
this.lineBreak = lineBreak;
}
@Override
public CharsetEncoder getCharsetEncoder () {
return null;
}
@Override
public IParameters getParameters() {
return null;
}
@Override
public String getEncoding() {
return "";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy