/*
Copyright 2011-2017 Frederic Langlet
Licensed 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

                http://www.apache.org/licenses/LICENSE-2.0

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 kanzi.util;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;


// Utility class to decompose a String into Lyndon words using the Chen-Fox-Lyndon algorithm
public class LyndonWords 
{
   private final List<Integer> breakpoints;

   
   public LyndonWords()
   {
      this.breakpoints = new ArrayList<Integer>();
   }
   
   
   // Not thread safe
   private List<Integer> chenFoxLyndonBreakpoints(byte[] buf, int length)
   {
      int k = 0;
      this.breakpoints.clear();

      while (k < length)
      {
         int i = k;
         int j = k + 1;
        
         while ((j < length) && (buf[i] <= buf[j]))
         {
            i = (buf[i] == buf[j]) ? i+1 : k;
            j++;
         }
            
         while (k <= i)
         {
            k += (j-i);
            this.breakpoints.add(k);            
         }
      }
      
      return this.breakpoints;
   }
   
   
   // Not thread safe
   public String[] split(String s)
   {
      return this.split(s, null);  // relies on default encoding
   }
	   
   
   // Not thread safe
   public String[] split(String s, Charset cs)
   {
      byte[] buf = (cs == null) ? s.getBytes() : s.getBytes(cs);
      this.chenFoxLyndonBreakpoints(buf, s.length());
      String[] res = new String[this.breakpoints.size()];
      int n = 0;
      int prev = 0;
     
      for (int bp : this.breakpoints)
      {
         res[n++] = s.substring(prev, bp);
         prev = bp;
      }  
     
      return res;
   }   

   
   public int[] getPositions(String s)
   {      
      return this.getPositions(s, null);   // relies on default encoding
   }
    
   
   public int[] getPositions(String s, Charset cs)
   {      
      byte[] buf = (cs == null) ? s.getBytes() : s.getBytes(cs);
      this.chenFoxLyndonBreakpoints(buf, s.length());
      int[] res = new int[this.breakpoints.size()];     
      int n = 0;
      
      for (Integer bp : this.breakpoints)
         res[n++] = bp;
      
      return res;
   }   
   
}

@@ -2452,32 +2452,200 @@
 .getBytes(cs);%0D%0A
+      return this.getPositions(buf, buf.length);   // relies on default encoding%0D%0A   %7D%0D%0A   %0D%0A   %0D%0A   public int%5B%5D getPositions(byte%5B%5D buf, int length)%0D%0A   %7B          %0D%0A
       this.chenF
@@ -2665,34 +2665,30 @@
 points(buf, 
-s.
 length
-()
 );%0D%0A      in

Add one more public method.