All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.snapscript.common.io.PropertyReader Maven / Gradle / Ivy

package org.snapscript.common.io;

public abstract class PropertyReader extends StatementReader {
   
   protected PropertyReader(String file) {
      super(file);
   }

   @Override
   protected T create(char[] data, int off, int length, int line) {
      int seek = 0;

      while(seek < length) {
         char next = data[off + seek++];
         
         if(separator(next)) {
            String name = format(data, off, seek - 1);
            
            if(seek >= length) {
               throw new StatementException("No value in '" + file + "' at line " + line);
            }
            return create(name, data, off + seek, length - seek, line);
         }
      }
      throw new StatementException("Error in '" + file + "' at line " + line);
   }
   
   protected String format(char[] data, int off, int length) {
      int finish = off + length;
      int start = off;

      while(start < finish) {
         char next = data[start];
         
         if(!space(next)) {
            break;
         }
         start++;
      }
      while(finish > start) {
         char next = data[finish-1];
         
         if(!space(next)) {
            break;
         }
         finish--;
      }
      return new String(data, start, finish -start);
   }
   
   protected boolean separator(char value) {
      return value == '=';
   }
   
   protected abstract T create(String name, char[] data, int off, int length, int line);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy