NSData+Mnemonic.m
author Jens Alfke <jens@mooseyard.com>
Wed Sep 02 08:41:25 2009 -0700 (2009-09-02)
changeset 35 5cab3034d3a1
permissions -rw-r--r--
10.6 compatibility: Fix some new compiler warnings, and work around apparent regressions in NSTask and -stringByStandardizingPath.
     1 //
     2 //  NSData+Mnemonic.m
     3 //  Cloudy
     4 //
     5 //  Created by Jens Alfke on 6/24/09.
     6 //  Copyright 2009 Jens Alfke. All rights reserved.
     7 //
     8 
     9 #import "NSData+Mnemonic.h"
    10 #import "mnemonic.h"
    11 
    12 
    13 @implementation NSData (Mnemonic)
    14 
    15 - (NSString*) my_mnemonic {
    16     NSMutableData *chars = [NSMutableData dataWithLength: 10*mn_words_required(self.length)];
    17     if (!chars)
    18         return nil;
    19     int result = mn_encode((void*)self.bytes, self.length,
    20                            chars.mutableBytes, chars.length,
    21                            MN_FDEFAULT);
    22     if (result != 0) {
    23         Warn(@"Mnemonic encoder failed: err=%i",result);
    24         return nil;
    25     }
    26     return [[[NSString alloc] initWithUTF8String: chars.mutableBytes] autorelease];
    27 }
    28 
    29 @end