From 3d94ef3ed65c30139ded428b477fac673a29c1ee Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 16 Jul 2009 17:21:43 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20minor=20issues=20for=20"Comment=20L?= =?UTF-8?q?ine/Selection"=20in=20Custom=20Query=20-=20esp.=20for=20(un)com?= =?UTF-8?q?menting=20a=20selection=20if=20it=20ends=20with=20a=20\n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CustomQuery.m | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index e59f82e2..461dfba8 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -959,18 +959,23 @@ [n setString:[[textView string] substringWithRange:workingRange]]; + if([n isMatchedByRegex:@"\\n\\Z"]) { + workingRange.length--; + [n replaceOccurrencesOfRegex:@"\\n\\Z" withString:@""]; + } + // Escape given */ by *\/ [n replaceOccurrencesOfRegex:@"\\*/(?=.)" withString:@"*\\\\/"]; [n replaceOccurrencesOfRegex:@"\\*/(?=\\n)" withString:@"*\\\\/"]; // Wrap current query into /* */ [n replaceOccurrencesOfRegex:@"^" withString:@"/* "]; - [n replaceOccurrencesOfRegex:@"$" withString:@" */"]; + [n appendString:@" */"]; // Check if current query/selection is already commented out, if so uncomment it if([n isMatchedByRegex:@"^/\\* \\s*/\\*\\s*(.|\\n)*?\\s*\\*/ \\*/\\s*$"]) { [n replaceOccurrencesOfRegex:@"^/\\* \\s*/\\*\\s*" withString:@""]; - [n replaceOccurrencesOfRegex:@"\\s*\\*/ \\*/\\s*$" withString:@""]; + [n replaceOccurrencesOfRegex:@"\\s*\\*/ \\*/\\s*\\Z" withString:@""]; // unescape *\/ [n replaceOccurrencesOfRegex:@"\\*\\\\/" withString:@"*/"]; isUncomment = YES; @@ -997,7 +1002,7 @@ NSRange oldRange = [textView selectedRange]; - if(oldRange.length) { + if(oldRange.length) { // (un)comment selection [self commentOutCurrentQueryTakingSelection:YES]; } else { // single line @@ -1017,15 +1022,15 @@ inRange:NSMakeRange(0,[n length]) capture:1 error: nil]]]; - } else if ([n isMatchedByRegex:@"^-- \\s*/\\*.*?\\*/\\s*$"]) { + } else if ([n isMatchedByRegex:@"^-- \\s*/\\*.*? ?\\*/\\s*$"]) { [n replaceOccurrencesOfRegex:@"^-- \\s*/\\* ?" withString:[n substringWithRange:[n rangeOfRegex:@"^-- (\\s*)" options:RKLNoOptions inRange:NSMakeRange(0,[n length]) capture:1 error: nil]]]; - [n replaceOccurrencesOfRegex:@"\\*/\\s*$" - withString:[n substringWithRange:[n rangeOfRegex:@"\\*/(\\s*)$" + [n replaceOccurrencesOfRegex:@" ?\\*/\\s*$" + withString:[n substringWithRange:[n rangeOfRegex:@" ?\\*/(\\s*)$" options:RKLNoOptions inRange:NSMakeRange(0,[n length]) capture:1 -- cgit v1.2.3