[sword-svn] r3408 - trunk/bindings/objc/src
mdbergmann at crosswire.org
mdbergmann at crosswire.org
Mon Feb 15 07:39:57 MST 2016
Author: mdbergmann
Date: 2016-02-15 07:39:57 -0700 (Mon, 15 Feb 2016)
New Revision: 3408
Modified:
trunk/bindings/objc/src/SwordModule.mm
trunk/bindings/objc/src/SwordUtil.h
trunk/bindings/objc/src/SwordUtil.m
Log:
split the previous code into smaller reusable components.
Modified: trunk/bindings/objc/src/SwordModule.mm
===================================================================
--- trunk/bindings/objc/src/SwordModule.mm 2016-02-15 14:12:36 UTC (rev 3407)
+++ trunk/bindings/objc/src/SwordModule.mm 2016-02-15 14:39:57 UTC (rev 3408)
@@ -18,6 +18,7 @@
#import "SwordVerseKey.h"
#import "SwordBible.h"
#import "SwordCommentary.h"
+#import "SwordUtil.h"
@interface SwordModule ()
@@ -574,43 +575,7 @@
NSArray *lemmas = [self entryAttributeValuesLemma];
// post process all codes and mormalize the number
// Hebrew keys should have 5 number digits
- NSMutableArray *buf = [NSMutableArray array];
- for(NSString *lemma in lemmas) {
- // Hebrew
- NSString *prefix = nil;
- if([lemma hasPrefix:@"H"]) {
- prefix = @"H";
- }
- if([lemma hasPrefix:@"G"]) {
- prefix = @"G";
- }
-
- if(prefix == nil) {
- // add as is
- [buf addObject:lemma];
-
- } else {
- // lemma may contain more codes concatenated by space
- NSArray *keys = [lemma componentsSeparatedByString:@" "];
- for(__strong NSString *key in keys) {
- // trim
- key = [key stringByReplacingOccurrencesOfString:@" " withString:@""];
- NSArray *keyComps = [key componentsSeparatedByString:prefix];
- if(keyComps.count == 2) {
- NSString *keyValue = keyComps[1];
- if(keyValue.length < 5) {
- NSInteger pad = 5 - keyValue.length;
- for(int i = 0;i < pad;i++) {
- keyValue = [NSString stringWithFormat:@"0%@", keyValue];
- }
- }
- // add to result array
- [buf addObject:[NSString stringWithFormat:@"%@%@", prefix, keyValue]];
- }
- }
- }
- }
- return [NSArray arrayWithArray:buf];
+ return [SwordUtil padStrongsNumbers:lemmas];
}
- (NSString *)entryAttributeValuePreverseForKey:(SwordKey *)aKey {
Modified: trunk/bindings/objc/src/SwordUtil.h
===================================================================
--- trunk/bindings/objc/src/SwordUtil.h 2016-02-15 14:12:36 UTC (rev 3407)
+++ trunk/bindings/objc/src/SwordUtil.h 2016-02-15 14:39:57 UTC (rev 3408)
@@ -17,4 +17,17 @@
*/
+ (NSDictionary *)dictionaryFromUrl:(NSURL *)aURL;
+/**
+ Pads an array of unpadded Strong's numbers to 5 digits.
+ I.e. H0430 => H00430, G11 => G00011
+ */
++ (NSArray *)padStrongsNumbers:(NSArray *)unpaddedNumbers;
+
+/**
+ Pads a single unpadded Strong's numbers to 5 digits.
+ I.e. H0430 => H00430, G11 => G00011
+ Since an unpadded number can be combined with multiple numbers concatenated by space we'll return an array here.
+ */
++ (NSArray *)padStrongsNumber:(NSString *)unpaddedNumber;
+
@end
Modified: trunk/bindings/objc/src/SwordUtil.m
===================================================================
--- trunk/bindings/objc/src/SwordUtil.m 2016-02-15 14:12:36 UTC (rev 3407)
+++ trunk/bindings/objc/src/SwordUtil.m 2016-02-15 14:39:57 UTC (rev 3408)
@@ -61,4 +61,49 @@
return ret;
}
++ (NSArray *)padStrongsNumbers:(NSArray *)unpaddedNumbers {
+ NSMutableArray *buf = [NSMutableArray array];
+ for(NSString *lemma in unpaddedNumbers) {
+ [buf addObjectsFromArray:[self padStrongsNumber:lemma]];
+ }
+ return [NSArray arrayWithArray:buf];
+}
+
++ (NSArray *)padStrongsNumber:(NSString *)unpaddedNumber {
+ NSMutableArray *buf = [NSMutableArray array];
+ // Hebrew
+ NSString *prefix = nil;
+ if([unpaddedNumber hasPrefix:@"H"]) {
+ prefix = @"H";
+ }
+ if([unpaddedNumber hasPrefix:@"G"]) {
+ prefix = @"G";
+ }
+
+ if(prefix != nil) {
+ // lemma may contain more codes concatenated by space
+ NSArray *keys = [unpaddedNumber componentsSeparatedByString:@" "];
+ for(__strong NSString *key in keys) {
+ // trim
+ key = [key stringByReplacingOccurrencesOfString:@" " withString:@""];
+ NSArray *keyComps = [key componentsSeparatedByString:prefix];
+ if(keyComps.count == 2) {
+ NSString *keyValue = keyComps[1];
+ if(keyValue.length < 5) {
+ NSInteger pad = 5 - keyValue.length;
+ for(int i = 0;i < pad;i++) {
+ keyValue = [NSString stringWithFormat:@"0%@", keyValue];
+ }
+ }
+ // add to result array
+ [buf addObject:[NSString stringWithFormat:@"%@%@", prefix, keyValue]];
+ }
+ }
+ } else {
+ [buf addObject:unpaddedNumber];
+ }
+
+ return [NSArray arrayWithArray:buf];
+}
+
@end
\ No newline at end of file
More information about the sword-cvs
mailing list