Not so long filenames
Not so long filenames
- Subject: Not so long filenames
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Tue, 14 Oct 2008 17:28:04 +0200
HFS+ and Finder can use filenames which use in Utf-16 up to 255 shorts.
But in the program below there seems to exist some other limit (at
least on 10.4.11 Tiger).
Where is this documented?
Or what am I doing wong?
#import <Cocoa/Cocoa.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSData *data = [ @"Some Data" dataUsingEncoding:
NSUTF8StringEncoding ];
NSFileWrapper *aWrapper = [ [ NSFileWrapper alloc ]
initRegularFileWithContents: data ];
NSString *f2 = [ NSString stringWithUTF8String: // 64 * DESERET
CAPITAL LETTER LONG I
"𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀
𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀
𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀
𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀𐐀"// 64
];
[ aWrapper setPreferredFilename: f2 ];
NSLog(@"%s Filewrapper has preferred filename with %u shorts in
Utf16; "
"Utf8 of fileSystemRepresentation has %u bytes",
__FUNCTION__, [ f2 length], strlen([f2 fileSystemRepresentation]));
NSTextAttachment *attachment = [ [ NSTextAttachment alloc ]
initWithFileWrapper: aWrapper ];
NSAttributedString *textStorage = [ NSMutableAttributedString
attributedStringWithAttachment: attachment ];
NSRange all = NSMakeRange( 0, [ textStorage length ] );
NSFileWrapper *fw = [ textStorage RTFDFileWrapperFromRange: all
documentAttributes: nil ];
if ( fw == nil ) // error
{
NSLog(@"%s Error: RTFDFileWrapperFromRange",__FUNCTION__);
return 1;
};
NSString *path = @"/tmp/a.rtfd";
BOOL ok = [ fw writeToFile: path atomically: NO updateFilenames: NO ];
if ( !ok ) // error
{
// we come here if strlen([f2 fileSystemRepresentation]) > 255
NSLog(@"%s Error: writeToFile",__FUNCTION__);
return 2;
};
NSLog(@"%s wrote rtfd wrapper %@",__FUNCTION__, path);
[pool release];
return 0;
}
Result:
... Filewrapper has preferred filename with 128 shorts in Utf16; Utf8
of fileSystemRepresentation has 256 bytes
... Error: writeToFile
Filename has exited with status 2.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden