Coverage Report - org.seasar.cubby.admin.servlet.StringUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
StringUtils
0%
0/17
0%
0/10
8
 
 1  
 /*
 2  
  * Copyright 2004-2009 the Seasar Foundation and the Others.
 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,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.cubby.admin.servlet;
 17  
 
 18  0
 class StringUtils {
 19  
 
 20  
         /**
 21  
          * 文字列を置き換えます。
 22  
          * 
 23  
          * @param text
 24  
          *            テキスト
 25  
          * @param fromText
 26  
          *            置き換え対象のテキスト
 27  
          * @param toText
 28  
          *            置き換えるテキスト
 29  
          * @return 結果
 30  
          */
 31  
         public static final String replace(final String text,
 32  
                         final String fromText, final String toText) {
 33  
 
 34  0
                 if (text == null || fromText == null || toText == null) {
 35  0
                         return null;
 36  
                 }
 37  0
                 final StringBuilder builder = new StringBuilder(100);
 38  0
                 int pos = 0;
 39  0
                 int pos2 = 0;
 40  
                 while (true) {
 41  0
                         pos = text.indexOf(fromText, pos2);
 42  0
                         if (pos == 0) {
 43  0
                                 builder.append(toText);
 44  0
                                 pos2 = fromText.length();
 45  0
                         } else if (pos > 0) {
 46  0
                                 builder.append(text.substring(pos2, pos));
 47  0
                                 builder.append(toText);
 48  0
                                 pos2 = pos + fromText.length();
 49  
                         } else {
 50  0
                                 builder.append(text.substring(pos2));
 51  0
                                 break;
 52  
                         }
 53  
                 }
 54  0
                 return builder.toString();
 55  
         }
 56  
 
 57  
 }