From b3dee5036052523e1af4bac535d5b97452ff2995 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 4 Jun 2009 15:25:20 +0000 Subject: =?UTF-8?q?=E2=80=A2=20updated=20queryTextRangeForQuery:=20method?= =?UTF-8?q?=20to=20make=20usage=20of=20the=20new=20SQLParser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CustomQuery.m | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 8e7d3325..49b2f64a 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -739,16 +739,17 @@ { SPSQLParser *customQueryParser; NSArray *queries; - int i; // If the supplied position is negative or beyond the end of the string, return nil. if (position < 0 || position > [[textView string] length]) return NSMakeRange(NSNotFound,0); - // Split the current text into queries + // Split the current text into ranges of queries customQueryParser = [[SPSQLParser alloc] initWithString:[[textView string] substringWithRange:NSMakeRange(position, [[textView string] length]-position)]]; - queries = [[NSArray alloc] initWithArray:[customQueryParser splitStringByCharacter:';']]; + queries = [[NSArray alloc] initWithArray:[customQueryParser splitSqlStringIntoRangesByCharacter:';']]; [customQueryParser release]; + + // Check for a valid index anIndex--; if(anIndex < 0 || anIndex >= [queries count]) { @@ -756,21 +757,16 @@ return NSMakeRange(NSNotFound, 0); } - NSString *theQuery = [queries objectAtIndex:anIndex]; - - // Calculate the text length before that query at index anIndex - long prevQueriesLength = 0; - for (i = 0; i < anIndex; i++ ) { - prevQueriesLength += [[queries objectAtIndex:i] length] + 1; - } - + NSRange theQueryRange = [[queries objectAtIndex:anIndex] rangeValue]; + NSString *theQueryString = [[textView string] substringWithRange:theQueryRange]; + [queries release]; // Remove all leading white spaces - NSError *err; - int offset = [theQuery rangeOfRegex:@"^(\\s*)" options:RKLNoOptions inRange:NSMakeRange(0, [theQuery length]) capture:1 error:&err].length; - - return NSMakeRange(position+offset+prevQueriesLength, [theQuery length] - offset); + int offset = [theQueryString rangeOfRegex:@"^(\\s*)"].length; + theQueryRange.location += offset; + theQueryRange.length -= offset; + return theQueryRange; } /* -- cgit v1.2.3