private int findIndexOfFrom ( String query ) { if ( query . startsWith ( "from" ) ) return 0 ; int fromIdx = query . indexOf ( " from " ) ; if ( - 1 == fromIdx ) return - 1 ; final int first = query . substring ( 0 , fromIdx ) . indexOf ( "(" ) ; if ( first > 0 ) { int leftCnt = 1 ; int i = first + 1 ; while ( leftCnt != 0 && i < query . length ( ) ) { if ( query . charAt ( i ) == ' ' ) leftCnt ++ ; else if ( query . charAt ( i ) == ' ' ) leftCnt -- ; i ++ ; } if ( leftCnt > 0 ) return - 1 ; else { fromIdx = query . indexOf ( " from " , i ) ; return ( fromIdx == - 1 ) ? - 1 : fromIdx + 1 ; } } else { return fromIdx + 1 ; } }
Find index of from