valerybokov edited a comment on pull request #107:
URL: https://github.com/apache/pdfbox/pull/107#issuecomment-997239316


   @THausherr , I found one case for COSParser.findString when this method 
returns wrong result. Maybe it is impossible because of string pattern in my 
test cant happen in real pdf. What can you say?
   
       static class SRC{
           int []arr = new int[30];
           int position;
   
           SRC(String body){
               for (int i = 0; i < body.length(); ++i)
                   arr[i] = body.charAt(i);
           }
   
           int read(){
               return arr.length > position ? arr[position++] : -1;
           }
   
           long getPosition(){
               return position;
           }
   }
   
       private static long findString(char[] string, SRC source)
       {
           long position = -1L;
           int stringLength = string.length;
           int counter = 0;
           int readChar = source.read();
           while (readChar != -1)
           {
               if (readChar == string[counter])
               {
                   if (counter == 0)
                   {
                       position = source.getPosition() - 1;
                   }
                   counter++;
                   if (counter == stringLength)
                   {
                       return position;
                   }
               }
               else if (counter > 0)
               {
                   counter = 0;
                   position = -1L;
                   continue;
               }
               readChar = source.read();
           }
           return position;
       }
   
       public static void main(String[]args) {
           System.out.println(findString("aaaaaba".toCharArray(), new 
SRC("aaaaaaaba")));
           System.out.println("aaaaaaaba".contains("aaaaaba"));
   }


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to