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

net.sourceforge.squirrel_sql.fw.completion.util.CompletionUtils Maven / Gradle / Ivy

Go to download

The framework library contains utility classes that are generic and useful for building applications that introspect a database via JDBC. These are not intended to be SQuirreLSQL-specific and could be used by other projects JDBC front-end applications. This project is guaranteed to have no code dependencies on other SQuirreLSQL projects and could therefore be used when building a different JDBC front-end application.

There is a newer version: 3.5.0
Show newest version
package net.sourceforge.squirrel_sql.fw.completion.util;

class CompletionUtils
{
   private static final char[] SEPARATORS = {' ', '\t', '\n' ,  ',', '(', '\'','"', '=', '>', '<'};

   static String getStringToParse(String textTillCaret)
   {

      int lastIndexOfLineFeed = textTillCaret.lastIndexOf('\n');
      String lineTillCaret;

      if(-1 == lastIndexOfLineFeed)
      {
         lineTillCaret = textTillCaret;
      }
      else
      {
         lineTillCaret = textTillCaret.substring(lastIndexOfLineFeed);
      }

      String beginning = "";
      if (0 != lineTillCaret.trim().length() && !Character.isWhitespace(lineTillCaret.charAt(lineTillCaret.length() - 1)))
      {
         String trimmedLineTillCaret = lineTillCaret.trim();

         int lastSeparatorIndex = getLastSeparatorIndex(trimmedLineTillCaret);
         if (-1 == lastSeparatorIndex)
         {
            beginning = trimmedLineTillCaret;
         }
         else
         {
            beginning = trimmedLineTillCaret.substring(lastSeparatorIndex + 1, trimmedLineTillCaret.length());
         }
      }

      return beginning;
   }

   static int getLastSeparatorIndex(String str)
   {
      int lastSeparatorIndex = -1;
      for (char separator : SEPARATORS)
      {
         int buf = str.lastIndexOf(separator);
         if (buf > lastSeparatorIndex)
         {
            lastSeparatorIndex = buf;
         }
      }
      return lastSeparatorIndex;
   }

   static int getStringToParsePosition(String textTillCaret)
	{

		int lastIndexOfLineFeed = textTillCaret.lastIndexOf('\n');
		String lineTillCaret;

		if (-1 == lastIndexOfLineFeed)
		{
			lineTillCaret = textTillCaret;
		}
		else
		{
			lineTillCaret = textTillCaret.substring(lastIndexOfLineFeed);
		}

		int pos = lastIndexOfLineFeed + 1;
		if (0 != lineTillCaret.length() && !Character.isWhitespace(lineTillCaret.charAt(lineTillCaret.length() - 1)))
		{
			int lastSeparatorIndex = getLastSeparatorIndex(lineTillCaret);
			if (-1 != lastSeparatorIndex)
			{
				pos += lastSeparatorIndex;
			}
		}

		return pos;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy