Skip to content

Commit

Permalink
Refactor Parser & Optimize build flags
Browse files Browse the repository at this point in the history
  • Loading branch information
torifat committed Sep 23, 2016
1 parent ed657e1 commit 02631c1
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 65 deletions.
6 changes: 6 additions & 0 deletions AutoCorrectItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ -(BOOL)validateWith:(id *)ioValue error:(NSError * __autoreleasing *)outError {
return YES;
}

-(void)dealloc {
[replace release];
[with release];
[super dealloc];
}

@end
43 changes: 39 additions & 4 deletions AvroKeyboard.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0500;
LastUpgradeCheck = 0800;
TargetAttributes = {
8D1107260486CEB800E47090 = {
DevelopmentTeam = 22LN73JVY9;
DevelopmentTeam = 8FVM4CE4C6;
};
};
};
Expand Down Expand Up @@ -464,14 +464,15 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
DEVELOPMENT_TEAM = 22LN73JVY9;
DEVELOPMENT_TEAM = 8FVM4CE4C6;
GCC_DYNAMIC_NO_PIC = NO;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "\"$(LOCAL_LIBRARY_DIR)/Input Methods/\"";
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_BUNDLE_IDENTIFIER = com.omicronlab.inputmethod.AvroKeyboard;
PRODUCT_NAME = "Avro Keyboard";
PROVISIONING_PROFILE = "";
WRAPPER_EXTENSION = app;
Expand All @@ -487,13 +488,14 @@
CODE_SIGN_IDENTITY = "Developer ID Application";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = 22LN73JVY9;
DEVELOPMENT_TEAM = 8FVM4CE4C6;
GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
GCC_MODEL_TUNING = G5;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Applications";
MACOSX_DEPLOYMENT_TARGET = 10.7;
PRODUCT_BUNDLE_IDENTIFIER = com.omicronlab.inputmethod.AvroKeyboard;
PRODUCT_NAME = "Avro Keyboard";
PROVISIONING_PROFILE = "";
WRAPPER_EXTENSION = app;
Expand All @@ -503,7 +505,24 @@
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = NO;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = NO;
ONLY_ACTIVE_ARCH = YES;
};
Expand All @@ -512,7 +531,23 @@
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = NO;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = NO;
};
name = Release;
Expand Down
4 changes: 2 additions & 2 deletions AvroKeyboardController.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
int _prevSelected;
NSMutableString* _composedBuffer; // _composedBuffer contains text that the input method has converted
NSMutableArray* _currentCandidates;
int _selectedCandidateIndex;
NSInteger _selectedCandidateIndex;
NSString* _prefix; // Converted Prefix
NSString* _term; // Original Non-Converted Term
NSString* _suffix; // Converted Suffix
Expand All @@ -30,4 +30,4 @@
//They are all simple wrappers around basic NSString methods.
- (void)commitText:(NSString*)string;

@end
@end
2 changes: 1 addition & 1 deletion AvroParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
NSString* _number;
NSString* _casesensitive;
NSArray* _patterns;
int _maxPatternLength;
NSInteger _maxPatternLength;
}

+ (AvroParser *)sharedInstance;
Expand Down
57 changes: 19 additions & 38 deletions AvroParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,19 @@ - (NSString*)parse:(NSString *)string {
NSString * fixed = [self fix:string];
NSMutableString* output = [[NSMutableString alloc] initWithCapacity:0];

int len = [fixed length], cur;
NSInteger len = [fixed length], cur;
for(cur = 0; cur < len; ++cur) {
int start = cur, end;
NSInteger start = cur, end;
BOOL matched = FALSE;

int chunkLen;
NSInteger chunkLen;
for(chunkLen = _maxPatternLength; chunkLen > 0; --chunkLen) {
end = start + chunkLen;
if(end <= len) {
NSString* chunk = [fixed substringWithRange:NSMakeRange(start, chunkLen)];

// Binary Search
int left = 0, right = [_patterns count] - 1, mid;
NSInteger left = 0, right = [_patterns count] - 1, mid;
while(right >= left) {
mid = (right + left) / 2;
NSDictionary* pattern = [_patterns objectAtIndex:mid];
Expand All @@ -115,7 +115,7 @@ - (NSString*)parse:(NSString *)string {
for(NSDictionary* rule in rules) {

BOOL replace = TRUE;
int chk = 0;
NSInteger chk = 0;
NSArray* matches = [rule objectForKey:@"matches"];
for(NSDictionary* match in matches) {
NSString* value = [match objectForKey:@"value"];
Expand Down Expand Up @@ -191,7 +191,7 @@ - (NSString*)parse:(NSString *)string {
}
// Exact
else if([scope isEqualToString:@"exact"]) {
int s, e;
NSInteger s, e;
if([type isEqualToString:@"suffix"]) {
s = end;
e = end + [value length];
Expand All @@ -201,7 +201,7 @@ - (NSString*)parse:(NSString *)string {
s = start - [value length];
e = start;
}
if(![self isExact:value heystack:fixed start:s end:e not:isNegative]) {
if(![self isExact:value heystack:fixed start:(int)s end:(int)e not:isNegative]) {
replace = FALSE;
break;
}
Expand Down Expand Up @@ -248,57 +248,38 @@ - (NSString*)parse:(NSString *)string {
return output;
}

- (BOOL)isVowel:(unichar)c {
- (BOOL)inString:(NSString*) str c:(unichar) c {
// Making it lowercase for checking
c = [self smallCap:c];
int i, len = [_vowel length];
NSInteger i, len = [str length];
for (i = 0; i < len; ++i) {
if ([_vowel characterAtIndex:i] == c) {
if ([str characterAtIndex:i] == c) {
return TRUE;
}
}
return FALSE;

}

- (BOOL)isVowel:(unichar)c {
return [self inString:_vowel c:c];
}

- (BOOL)isConsonant:(unichar)c {
// Making it lowercase for checking
c = [self smallCap:c];
int i, len = [_consonant length];
for (i = 0; i < len; ++i) {
if ([_consonant characterAtIndex:i] == c) {
return TRUE;
}
}
return FALSE;
return [self inString:_consonant c:c];
//return [consonant rangeOfString:c options:NSCaseInsensitiveSearch].location != NSNotFound;
}

- (BOOL)isNumber:(unichar)c {
// Making it lowercase for checking
c = [self smallCap:c];
int i, len = [_number length];
for (i = 0; i < len; ++i) {
if ([_number characterAtIndex:i] == c) {
return TRUE;
}
}
return FALSE;
return [self inString:_number c:c];
}

- (BOOL)isPunctuation:(unichar)c {
return !([self isVowel:c] || [self isConsonant:c]);
}

- (BOOL)isCaseSensitive:(unichar)c {
// Making it lowercase for checking
c = [self smallCap:c];
int i, len = [_casesensitive length];
for (i = 0; i < len; ++i) {
if ([_casesensitive characterAtIndex:i] == c) {
return TRUE;
}
}
return FALSE;
return [self inString:_casesensitive c:c];
}

- (BOOL)isExact:(NSString*) needle heystack:(NSString*)heystack start:(int)start end:(int)end not:(BOOL)not {
Expand All @@ -317,7 +298,7 @@ - (unichar)smallCap:(unichar) letter {

- (NSString*)fix:(NSString *)string {
NSMutableString* fixed = [[NSMutableString alloc] initWithCapacity:0];
int i, len = [string length];
NSInteger i, len = [string length];
for (i = 0; i < len; ++i) {
unichar c = [string characterAtIndex:i];
if (![self isCaseSensitive:c]) {
Expand Down
2 changes: 1 addition & 1 deletion Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>Avro Keyboard</string>
<key>CFBundleIdentifier</key>
<string>com.omicronlab.inputmethod.AvroKeyboard</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
4 changes: 2 additions & 2 deletions NSString+Levenshtein.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ -(int) computeLevenshteinDistanceWithString:(NSString *) string
int i,j,k; // indexes
int cost, distance;

int n = [self length];
int m = [string length];
int n = (int)[self length];
int m = (int)[string length];

if( n!=0 && m!=0 ){

Expand Down
2 changes: 1 addition & 1 deletion PreferencesController.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
IBOutlet NSTextView* _aboutContent;
IBOutlet NSArrayController* _autoCorrectController;

int _currentViewTag;
NSInteger _currentViewTag;
NSMutableArray* _autoCorrectItemsArray;
}

Expand Down
4 changes: 2 additions & 2 deletions PreferencesController.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ - (NSRect)newFrameForNewContentView:(NSView*)view {
return frame;
}

- (NSView*)viewForTag:(int)tag {
- (NSView*)viewForTag:(NSInteger)tag {
NSView* view = nil;
switch (tag) {
case 0:
Expand All @@ -84,7 +84,7 @@ - (BOOL)validateToolbarItem:(NSToolbarItem *)item {
}

- (IBAction)switchView:(id)sender {
int tag = [sender tag];
NSInteger tag = [sender tag];
NSView* view = [self viewForTag:tag];
NSView* previousView = [self viewForTag:_currentViewTag];
_currentViewTag = tag;
Expand Down
2 changes: 1 addition & 1 deletion RegexParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
NSString* _consonant;
NSString* _casesensitive;
NSArray* _patterns;
int _maxPatternLength;
NSInteger _maxPatternLength;
}

+ (RegexParser *)sharedInstance;
Expand Down
Loading

0 comments on commit 02631c1

Please sign in to comment.