1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.text.method;
18 
19 /**
20  * This transformation method causes any newline characters (\n) to be
21  * displayed as spaces instead of causing line breaks, and causes
22  * carriage return characters (\r) to have no appearance.
23  */
24 public class SingleLineTransformationMethod
25 extends ReplacementTransformationMethod {
26     private static char[] ORIGINAL = new char[] { '\n', '\r' };
27     private static char[] REPLACEMENT = new char[] { ' ', '\uFEFF' };
28 
29     /**
30      * The characters to be replaced are \n and \r.
31      */
getOriginal()32     protected char[] getOriginal() {
33         return ORIGINAL;
34     }
35 
36     /**
37      * The character \n is replaced with is space;
38      * the character \r is replaced with is FEFF (zero width space).
39      */
getReplacement()40     protected char[] getReplacement() {
41         return REPLACEMENT;
42     }
43 
getInstance()44     public static SingleLineTransformationMethod getInstance() {
45         if (sInstance != null)
46             return sInstance;
47 
48         sInstance = new SingleLineTransformationMethod();
49         return sInstance;
50     }
51 
52     private static SingleLineTransformationMethod sInstance;
53 }
54