Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed memory leaks

Signed-off-by: Rifat Nabi <to.rifat@gmail.com>
  • Loading branch information...
commit 71d6708c8b39d438f9824e3cc20612538b634427 1 parent f7800d2
@torifat torifat authored
View
6 AvroKeyboardController.h
@@ -10,6 +10,7 @@
@interface AvroKeyboardController : IMKInputController {
+@private
id _currentClient; // the current active client.
int _prevSelected;
NSMutableString* _composedBuffer; // _composedBuffer contains text that the input method has converted
@@ -17,9 +18,12 @@
NSString* _prefix; // Converted Prefix
NSString* _term; // Original Non-Converted Term
NSString* _suffix; // Converted Suffix
- NSString* _regex;
}
+@property (nonatomic, retain) NSString* prefix;
+@property (nonatomic, retain) NSString* term;
+@property (nonatomic, retain) NSString* suffix;
+
//These are simple methods for managing our composition and original buffers
//They are all simple wrappers around basic NSString methods.
- (void)commitText:(NSString*)string;
View
42 AvroKeyboardController.m
@@ -14,7 +14,10 @@
@implementation AvroKeyboardController
+@synthesize prefix = _prefix, term = _term, suffix = _suffix;
+
- (id)initWithServer:(IMKServer*)server delegate:(id)delegate client:(id)inputClient {
+
self = [super initWithServer:server delegate:delegate client:inputClient];
if (self) {
@@ -22,41 +25,35 @@ - (id)initWithServer:(IMKServer*)server delegate:(id)delegate client:(id)inputCl
_composedBuffer = [[NSMutableString alloc] initWithString:@""];
_currentCandidates = [[NSMutableArray alloc] initWithCapacity:0];
_prevSelected = -1;
-
- NSString* charList = @"(?::`|\\.`|[-\\]\\\\~!@#&*()_=+\\[{}'\";<>/?|.,])*";
- _regex = [[NSString alloc] initWithFormat:@"(^%@?(?=(?:,{2,}))|^%@)(.*?(?:,,)*)(%@$)", charList, charList, charList];
- _term = [[NSString alloc] initWithString:@""];
- _prefix = [[NSString alloc] initWithString:@""];
- _suffix = [[NSString alloc] initWithString:@""];
-
}
return self;
}
- (void)dealloc {
- [_regex release];
- [_term release];
[_prefix release];
+ [_term release];
[_suffix release];
- [_composedBuffer release];
[_currentCandidates release];
+ [_composedBuffer release];
[super dealloc];
}
- (void)findCurrentCandidates {
[_currentCandidates removeAllObjects];
if (_composedBuffer && [_composedBuffer length] > 0) {
- NSArray* items = [[_composedBuffer retain] captureComponentsMatchedByRegex:_regex];
+ NSString* regex = @"(^(?::`|\\.`|[-\\]\\\\~!@#&*()_=+\\[{}'\";<>/?|.,])*?(?=(?:,{2,}))|^(?::`|\\.`|[-\\]\\\\~!@#&*()_=+\\[{}'\";<>/?|.,])*)(.*?(?:,,)*)((?::`|\\.`|[-\\]\\\\~!@#&*()_=+\\[{}'\";<>/?|.,])*$)";
+ NSArray* items = [_composedBuffer captureComponentsMatchedByRegex:regex];
if (items && [items count] > 0) {
- _prefix = [[[AvroParser sharedInstance] parse:[items objectAtIndex:1]] retain];
- _suffix = [[[AvroParser sharedInstance] parse:[items objectAtIndex:3]] retain];
- _term = [[items objectAtIndex:2] retain];
- _currentCandidates = [[[Suggestion sharedInstance] getList:_term] retain];
+ [self setPrefix:[[AvroParser sharedInstance] parse:[items objectAtIndex:1]]];
+ [self setTerm:[items objectAtIndex:2]];
+ [self setSuffix:[[AvroParser sharedInstance] parse:[items objectAtIndex:3]]];
+
+ _currentCandidates = [[[Suggestion sharedInstance] getList:[self term]] retain];
if (_currentCandidates && [_currentCandidates count] > 0) {
_prevSelected = -1;
- NSString* prevString = [[CacheManager sharedInstance] stringForKey:_term];
+ NSString* prevString = [[CacheManager sharedInstance] stringForKey:[self term]];
int i;
for (i = 0; i < [_currentCandidates count]; ++i) {
NSString* item = [_currentCandidates objectAtIndex:i];
@@ -64,11 +61,11 @@ - (void)findCurrentCandidates {
_prevSelected = i;
}
[_currentCandidates replaceObjectAtIndex:i withObject:
- [NSString stringWithFormat:@"%@%@%@", _prefix, item, _suffix]];
+ [NSString stringWithFormat:@"%@%@%@", [self prefix], item, [self suffix]]];
}
}
else {
- [_currentCandidates addObject:_prefix];
+ [_currentCandidates addObject:[self prefix]];
}
}
}
@@ -110,15 +107,16 @@ - (void)clearCompositionBuffer {
}
- (void)candidateSelected:(NSAttributedString*)candidateString {
- if (_term && [_term length] > 0) {
+ if ([self term] && [[self term] length] > 0) {
BOOL comp = [[candidateString string] isEqualToString:[_currentCandidates objectAtIndex:0]];
if ((comp && _prevSelected!=-1) == NO) {
if (comp == YES) {
- [[CacheManager sharedInstance] removeStringForKey:_term];
+ [[CacheManager sharedInstance] removeStringForKey:[self term]];
}
else {
- NSRange range = NSMakeRange([_prefix length], [candidateString length] - ([_prefix length] + [_suffix length]));
- [[CacheManager sharedInstance] setString:[[candidateString string] substringWithRange:range] forKey:_term];
+ NSRange range = NSMakeRange([[self prefix] length],
+ [candidateString length] - ([[self prefix] length] + [[self suffix] length]));
+ [[CacheManager sharedInstance] setString:[[candidateString string] substringWithRange:range] forKey:[self term]];
}
}
}
View
3  AvroParser.m
@@ -66,7 +66,7 @@ + (AvroParser *)sharedInstance {
- (NSString*)parse:(NSString *)string {
if (!string || [string length] == 0) {
- return string;
+ return @"";
}
NSString * fixed = [self fix:string];
@@ -207,7 +207,6 @@ - (NSString*)parse:(NSString *)string {
// NSLog(@"cur: %s, start: %s, end: %s, prev: %s\n", cur, start, end, prev);
}
- [fixed release];
[output autorelease];
return output;
View
2  Database.m
@@ -78,7 +78,7 @@ - (id)init {
[sqliteDb close];
- [loopPool drain];
+ [loopPool release];
}
return self;
View
1  Suggestion.m
@@ -31,6 +31,7 @@ - (id)init {
}
- (void)dealloc {
+ [_suggestions release];
[super dealloc];
}
Please sign in to comment.
Something went wrong with that request. Please try again.