[sword-svn] r3409 - trunk/bindings/objc/src
mdbergmann at crosswire.org
mdbergmann at crosswire.org
Mon Feb 15 08:42:37 MST 2016
Author: mdbergmann
Date: 2016-02-15 08:42:37 -0700 (Mon, 15 Feb 2016)
New Revision: 3409
Modified:
trunk/bindings/objc/src/SwordUtil.h
trunk/bindings/objc/src/SwordUtil.m
Log:
again more reuseable code.
Modified: trunk/bindings/objc/src/SwordUtil.h
===================================================================
--- trunk/bindings/objc/src/SwordUtil.h 2016-02-15 14:39:57 UTC (rev 3408)
+++ trunk/bindings/objc/src/SwordUtil.h 2016-02-15 15:42:37 UTC (rev 3409)
@@ -30,4 +30,10 @@
*/
+ (NSArray *)padStrongsNumber:(NSString *)unpaddedNumber;
+/**
+ * Pads a string on the left until maxDigits is reached
+ */
++ (NSString *)leftPadWithZero:(NSString *)unpadded maxDigits:(NSInteger)maxDigits;
+
+
@end
Modified: trunk/bindings/objc/src/SwordUtil.m
===================================================================
--- trunk/bindings/objc/src/SwordUtil.m 2016-02-15 14:39:57 UTC (rev 3408)
+++ trunk/bindings/objc/src/SwordUtil.m 2016-02-15 15:42:37 UTC (rev 3409)
@@ -88,13 +88,7 @@
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];
- }
- }
+ NSString *keyValue = [self leftPadWithZero:keyComps[1] maxDigits:5];
// add to result array
[buf addObject:[NSString stringWithFormat:@"%@%@", prefix, keyValue]];
}
@@ -106,4 +100,15 @@
return [NSArray arrayWithArray:buf];
}
++ (NSString *)leftPadWithZero:(NSString *)unpadded maxDigits:(NSInteger)maxDigits {
+ NSString *padded = unpadded;
+ if(padded.length < maxDigits) {
+ NSInteger pad = maxDigits - padded.length;
+ for(int i = 0;i < pad;i++) {
+ padded = [NSString stringWithFormat:@"0%@", padded];
+ }
+ }
+ return padded;
+}
+
@end
\ No newline at end of file
More information about the sword-cvs
mailing list