Coverage Report - org.kuali.student.contract.writer.StringQuoter
 
Classes in this File Line Coverage Branch Coverage Complexity
StringQuoter
0%
0/27
0%
0/13
10
 
 1  
 /*
 2  
  * Copyright 2009 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community 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.osedu.org/licenses/ECL-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.kuali.student.contract.writer;
 17  
 
 18  
 /**
 19  
  *
 20  
  * @author nwright
 21  
  */
 22  0
 public class StringQuoter
 23  
 {
 24  
 
 25  
  public static String quote (String value)
 26  
  {
 27  0
   if (value == null)
 28  
   {
 29  0
    return null;
 30  
   }
 31  0
   StringBuffer buf = new StringBuffer (value.length () + 3);
 32  0
   buf.append ('"');
 33  0
   boolean lastCharWasEscape = false;
 34  0
   for (int i = 0; i < value.length (); i ++)
 35  
   {
 36  0
    char c = value.charAt (i);
 37  0
    switch (c)
 38  
    {
 39  
     case '"':
 40  0
      if ( ! lastCharWasEscape)
 41  
      {
 42  0
       buf.append ('\\');
 43  
      }
 44  0
      lastCharWasEscape = false;
 45  0
      break;
 46  
     case '\\':
 47  0
      if ( ! lastCharWasEscape)
 48  
      {
 49  0
       buf.append ('\\');
 50  
      }
 51  0
      lastCharWasEscape = true;
 52  0
      break;
 53  
     case '\n':
 54  
     case '\r':
 55  0
      buf.append ('"');
 56  0
      buf.append ("\n");
 57  0
      buf.append ("\t + ");
 58  0
      buf.append ('"');
 59  0
      lastCharWasEscape = false;
 60  0
      continue;
 61  
     default:
 62  0
      lastCharWasEscape = false;
 63  
    }
 64  0
    buf.append (c);
 65  
   }
 66  0
   buf.append ('"');
 67  0
   return buf.toString ();
 68  
  }
 69  
 
 70  
 }