-
Notifications
You must be signed in to change notification settings - Fork 39
/
AutoCorrect.m
78 lines (63 loc) · 1.77 KB
/
AutoCorrect.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// AvroKeyboard
//
// Created by Rifat Nabi on 6/24/12.
// Copyright (c) 2012 OmicronLab. All rights reserved.
//
#import "AutoCorrect.h"
#import "AvroParser.h"
static AutoCorrect* sharedInstance = nil;
@implementation AutoCorrect
@synthesize autoCorrectEntries = _autoCorrectEntries;
+ (AutoCorrect *)sharedInstance {
if (sharedInstance == nil) {
[[self alloc] init]; // assignment not done here, see allocWithZone
}
return sharedInstance;
}
+ (id)allocWithZone:(NSZone *)zone {
if (sharedInstance == nil) {
sharedInstance = [super allocWithZone:zone];
return sharedInstance; // assignment and return on first allocation
}
return sharedInstance; //on subsequent allocation attempts return nil
}
- (id)copyWithZone:(NSZone *)zone {
return self;
}
- (id)retain {
return self;
}
- (oneway void)release {
//do nothing
}
- (id)autorelease {
return self;
}
- (NSUInteger)retainCount {
return NSUIntegerMax; // This is sooo not zero
}
- (id)init {
self = [super init];
if (self) {
// Open the file
NSString *fileName = [[NSBundle mainBundle] pathForResource:@"autodict" ofType:@"plist"];
// Check if the file exist and load from it, otherwise start with a empty dictionary
if ([[NSFileManager defaultManager] fileExistsAtPath:fileName]) {
_autoCorrectEntries = [[NSMutableDictionary alloc] initWithContentsOfFile:fileName];
} else {
_autoCorrectEntries = [[NSMutableDictionary alloc] init];
}
}
return self;
}
- (void)dealloc {
[_autoCorrectEntries release];
[super dealloc];
}
// Instance Methods
- (NSString*)find:(NSString*)term {
term = [[AvroParser sharedInstance] fix:term];
return _autoCorrectEntries[term];
}
@end