Coverage Report - org.ini4j.spi.WinEscapeTool
 
Classes in this File Line Coverage Branch Coverage Complexity
WinEscapeTool
100%
21/21
100%
4/4
3
 
 1  
 /*
 2  
  * Copyright 2005,2009 Ivan SZKIBA
 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  
 package org.ini4j.spi;
 17  
 
 18  1
 public class WinEscapeTool extends EscapeTool
 19  
 {
 20  
     private static final int ANSI_HEX_DIGITS = 2;
 21  
     private static final int ANSI_OCTAL_DIGITS = 3;
 22  
     private static final int OCTAL_RADIX = 8;
 23  1
     private static final WinEscapeTool INSTANCE = new WinEscapeTool();
 24  
 
 25  
     public static WinEscapeTool getInstance()
 26  
     {
 27  18
         return INSTANCE;
 28  
     }
 29  
 
 30  
     @Override void escapeBinary(StringBuilder buff, char c)
 31  
     {
 32  18
         buff.append("\\x");
 33  18
         buff.append(HEX[(c >>> HEX_DIGIT_3_OFFSET) & HEX_DIGIT_MASK]);
 34  18
         buff.append(HEX[c & HEX_DIGIT_MASK]);
 35  18
     }
 36  
 
 37  
     @Override int unescapeBinary(StringBuilder buff, char escapeType, String line, int index)
 38  
     {
 39  34
         int ret = index;
 40  
 
 41  34
         if (escapeType == 'x')
 42  
         {
 43  
             try
 44  
             {
 45  19
                 buff.append((char) Integer.parseInt(line.substring(index, index + ANSI_HEX_DIGITS), HEX_RADIX));
 46  18
                 ret = index + ANSI_HEX_DIGITS;
 47  
             }
 48  1
             catch (Exception x)
 49  
             {
 50  1
                 throw new IllegalArgumentException("Malformed \\xHH encoding.", x);
 51  18
             }
 52  
         }
 53  15
         else if (escapeType == 'o')
 54  
         {
 55  
             try
 56  
             {
 57  3
                 buff.append((char) Integer.parseInt(line.substring(index, index + ANSI_OCTAL_DIGITS), OCTAL_RADIX));
 58  2
                 ret = index + ANSI_OCTAL_DIGITS;
 59  
             }
 60  1
             catch (Exception x)
 61  
             {
 62  1
                 throw new IllegalArgumentException("Malformed \\oOO encoding.", x);
 63  2
             }
 64  
         }
 65  
 
 66  32
         return ret;
 67  
     }
 68  
 }