/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.fabric8.kubernetes.api;

/**
 */
public class KubernetesNames {
    /**
     * Lets convert the string to btw a valid kubernetes resource name
     */
    static String convertToKubernetesName(String text, boolean allowDots) {
      String lower = text.toLowerCase();
      StringBuilder builder = new StringBuilder();
      boolean started = false;
      char lastCh = ' ';
      for (int i = 0, last = lower.length() - 1; i <= last; i++) {
        char ch = lower.charAt(i);
        if (!(ch >= 'a' && ch <= 'z') && !(ch >= '0' && ch <= '9')) {
          if (ch == '/') {
            ch = '.';
          } else if (ch != '.' && ch != '-') {
            ch = '-';
          }
          if (!allowDots && ch == '.') {
              ch = '-';
          }
          if (!started || lastCh == '-' || lastCh == '.' || i == last) {
            continue;
          }
        }
        builder.append(ch);
        started = true;
        lastCh = ch;
      }
      return builder.toString();
    }

}

@@ -966,16 +966,23 @@
  */%0A    
+public 
 static S
@@ -1047,24 +1047,26 @@
 ts) %7B%0A      
+ 
+ 
 String lower
@@ -1084,24 +1084,26 @@
 owerCase();%0A
+  
       String
@@ -1147,16 +1147,18 @@
 ;%0A      
+ 
+ 
 boolean 
@@ -1174,16 +1174,18 @@
  false;%0A
+  
       ch
@@ -1207,16 +1207,18 @@
 ;%0A      
+  
 for (int
@@ -1274,24 +1274,28 @@
 ) %7B%0A        
+    
 char ch = lo
@@ -1313,24 +1313,28 @@
 i);%0A        
+  
+  
 if (!(ch %3E= 
@@ -1389,24 +1389,30 @@
 %7B%0A          
+     
+ 
 if (ch == '/
@@ -1424,24 +1424,32 @@
             
+        
 ch = '.';%0A  
@@ -1446,16 +1446,22 @@
  = '.';%0A
+      
         
@@ -1503,32 +1503,40 @@
 ) %7B%0A            
+        
 ch = '-';%0A      
@@ -1521,32 +1521,38 @@
       ch = '-';%0A
+      
           %7D%0A    
@@ -1553,24 +1553,30 @@
 %7D%0A          
+      
 if (!allowDo
@@ -1600,32 +1600,38 @@
 %7B%0A              
+      
 ch = '-';%0A      
@@ -1626,34 +1626,46 @@
  '-';%0A          
+   
-%7D%0A
+   %7D%0A      
           if (!s
@@ -1733,16 +1733,24 @@
         
+      
+  
 continue
@@ -1747,24 +1747,30 @@
   continue;%0A
+      
           %7D%0A
@@ -1777,26 +1777,33 @@
         
-%7D%0A
+    %7D%0A   
         
 builder.
@@ -1794,16 +1794,17 @@
         
+ 
 builder.
@@ -1823,16 +1823,20 @@
         
+    
 started 
@@ -1851,16 +1851,20 @@
         
+  
+  
 lastCh =
@@ -1870,26 +1870,30 @@
 = ch;%0A      
-%7D%0A
+  %7D%0A  
       return
@@ -1919,11 +1919,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

make helper method public - DOH :)