This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString *)convertISBN10To13:(NSString *)isbn10 | |
{ | |
NSString *prefix = [NSString stringWithFormat:@"978%@", [isbn10 substringToIndex:9]]; | |
NSInteger sum = 0; | |
for (int i=0; i<12; i++){ | |
char c = [prefix characterAtIndex:i]; | |
int n = c - '0'; | |
int w = (i % 2) ? 3 : 1; | |
sum += w * n; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func bytes<T: IntegerType>(i: T) -> [UInt8] { | |
let p = UnsafeMutablePointer<T>.alloc(1) | |
p.memory = i | |
let b = unsafeBitCast(p, UnsafePointer<UInt8>.self) | |
let bytes = reduce(0..<sizeof(T), []) { $0 + [b[$1]] } | |
p.destroy() | |
return bytes | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum ShiftKeyType { | |
case None | |
case Once | |
case Always | |
} | |
enum PunctuationSwitcherType { | |
case More | |
case Numeric | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BridgeHeader.h | |
#import <unicode/uchar.h> | |
// UnicodeBlock.swift | |
import Foundation | |
class UnicodeBlock { | |
class var blocks: UnicodeBlock[] { |
NewerOlder