• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: converting/reading input argument as utf8
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: converting/reading input argument as utf8


  • Subject: Re: converting/reading input argument as utf8
  • From: Camillo Lugaresi <email@hidden>
  • Date: Thu, 2 Feb 2006 23:12:30 +0100

Additionally, remember that you must release objects created using alloc+init. You're leaking strings all over the place.

On 02/feb/06, at 21:56, Deborah Goldsmith wrote:

The encoding for %s is the legacy Mac encoding (CFStringGetSystemEncoding()), not UTF-8. If you're running in English, that's MacRoman.

You cannot use %s to convert UTF-8 to UTF-16. Use [NSString stringWithUTF8String] instead.

Deborah Goldsmith
Internationalization, Unicode liaison
Apple Computer, Inc.
email@hidden

On Feb 2, 2006, at 2:24 AM, koen gogne wrote:

Hi all,

i'm quite new to cocoa programming,
and i have a question on the use of utf8 input arguments

Below you'll find some code that creates a thumbnail
per page for a given input file to a given output location

this workes fine as long as the input given does simple ascii characters

once i try using utf8 characters my input gets transferred incorrectly,
and the input file is not found and hence not read correctly,
so no thumbs could be made.


an example:
this works perfectly:
/Users/demo/myprogram /Volumes/vol1/input/file.pdf /Volumes/vol1/ output/out


this gets scrambled incorrectly:
/Users/demo/myprogram /Volumes/vol1/ïnpût/filé.pdf /Volumes/vol1/ output/out


my code:


int main (int argc, const char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog([[NSString alloc] initWithFormat:@"Processing file '%s' to '%s'.",argv[1], argv[2]]);
NSString *inpath;
NSString *outpath;

inpath = [[[NSString alloc] initWithFormat:@"%s",argv[1]] stringByExpandingTildeInPath];
NSURL * url = [NSURL fileURLWithPath:inpath];
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef) url, NULL);


if (source)
{
NSDictionary* thumbOpts = [NSDictionary dictionaryWithObjectsAndKeys:
(id)kCFBooleanTrue, (id) kCGImageSourceCreateThumbnailWithTransform,
(id)kCFBooleanTrue, (id) kCGImageSourceCreateThumbnailFromImageIfAbsent,
nil];


size_t count = CGImageSourceGetCount(source);
integer_t i = 0;

if ((count == 0))
{
CGImageRef image = CGImageSourceCreateThumbnailAtIndex(source, 0, (CFDictionaryRef)thumbOpts);


outpath = [[[NSString alloc] initWithFormat:@"%s.jpg",argv[2]] stringByExpandingTildeInPath];
NSURL * outurl = [NSURL fileURLWithPath: outpath];
CGImageDestinationRef ref = CGImageDestinationCreateWithURL ((CFURLRef)outurl, (CFStringRef)@"public.jpeg", 1, NULL);

// add image to the ImageIO destination (specify the image we want to save)
CGImageDestinationAddImage(ref, image, NULL);


if (!CGImageDestinationFinalize(ref))
{
NSLog([[NSString alloc] initWithString:@"Error writing JPEG file\n"]);
}


CFRelease(ref);
CGImageRelease(image);
}
else
{
while ((i < count)) {
CGImageRef image = CGImageSourceCreateThumbnailAtIndex(source, i, (CFDictionaryRef)thumbOpts);


outpath = [[[NSString alloc] initWithFormat:@"%s%i.jpg",argv [2],i+1] stringByExpandingTildeInPath];
NSURL * outurl = [NSURL fileURLWithPath: outpath];
CGImageDestinationRef ref = CGImageDestinationCreateWithURL ((CFURLRef)outurl, (CFStringRef)@"public.jpeg", 1, NULL);

// add image to the ImageIO destination (specify the image we want to save)
CGImageDestinationAddImage(ref, image, NULL);

if (!CGImageDestinationFinalize(ref))
{
NSLog([[NSString alloc] initWithString:@"Error writing JPEG file\n"]);
}

CFRelease(ref);
CGImageRelease(image);

i++;
}
}

}
else // couldn't make image source for image, so display nothing
{
NSLog([[NSString alloc] initWithString:@"Error reading source file\n"]);
}
[pool release];

return 1;
}





This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information and/or information protected by intellectual property rights.
If you are not the intended recipient, please note that any review, dissemination, disclosure, alteration, printing, copying or transmission of this e-mail and/or any file transmitted with it, is strictly prohibited and may be unlawful.
If you have received this e-mail by mistake, please immediately notify the sender and permanently delete the original as well as any copy of any e-mail and any printout thereof.
We may monitor e-mail to and from our network.


NSS nv
Tieltstraat 167
8740 Pittem
Belgium


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >converting/reading input argument as utf8 (From: "koen gogne" <email@hidden>)
 >Re: converting/reading input argument as utf8 (From: Deborah Goldsmith <email@hidden>)

  • Prev by Date: Advice: Plugin preference strategy
  • Next by Date: Re: Advice: Plugin preference strategy
  • Previous by thread: Re: converting/reading input argument as utf8
  • Next by thread: QTKit and shoutcast streams
  • Index(es):
    • Date
    • Thread