Clover coverage report - [ini4j]
Coverage timestamp: Sze nov. 30 2005 08:31:05 CET
file stats: LOC: 92   Methods: 2
NCLOC: 66   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Convert.java 100% 100% 100% 100%
coverage
 1    /*
 2    * Copyright 2005 [ini4j] Development Team
 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 org.ini4j;
 18   
 19    class Convert
 20    {
 21  132 protected static String escape(String line)
 22    {
 23  132 int len = line.length();
 24  132 StringBuilder buffer = new StringBuilder(len*2);
 25   
 26  132 for(int i = 0 ; i < len; i++)
 27    {
 28  1013 char c = line.charAt(i);
 29  1013 int idx = "\\\t\n\f".indexOf(c);
 30   
 31  1013 if ( idx >= 0 )
 32    {
 33  3 buffer.append('\\');
 34  3 buffer.append( "\\tnf".charAt(idx));
 35    }
 36    else
 37    {
 38  1010 if ((c < 0x0020) || (c > 0x007e))
 39    {
 40  1 buffer.append("\\u");
 41  1 buffer.append(Integer.toHexString(c));
 42    }
 43    else
 44    {
 45  1009 buffer.append(c);
 46    }
 47    }
 48    }
 49  132 return buffer.toString();
 50    }
 51   
 52  1302 protected static String unescape(String line)
 53    {
 54  1302 int n = line.length();
 55  1302 StringBuilder buffer = new StringBuilder(n);
 56   
 57  1302 for(int i = 0; i < n; )
 58    {
 59  11086 char c = line.charAt(i++);
 60   
 61  11086 if ( c == '\\' )
 62    {
 63  8 c = line.charAt(i++);
 64   
 65  8 if ( c == 'u' )
 66    {
 67  4 try
 68    {
 69  4 c = (char) Integer.parseInt(line.substring(i,i+=4), 16);
 70    }
 71    catch (RuntimeException x)
 72    {
 73  1 throw new IllegalArgumentException("Malformed \\uxxxx encoding.");
 74    }
 75    }
 76    else
 77    {
 78  4 int idx = "\\tnf".indexOf(c);
 79   
 80  4 if ( idx >= 0 )
 81    {
 82  3 c = "\\\t\n\f".charAt(idx);
 83    }
 84    }
 85    }
 86   
 87  11085 buffer.append(c);
 88    }
 89   
 90  1301 return buffer.toString();
 91    }
 92    }