On Oct 3, 2012, at 12:19 PM, Jens Ayton wrote:
>
> In summary, "figure out what Cocoa does." :-)
>
Under OSX 10.6.8 it misbehaves badly with wide strings, but has no hard
feelings about char arrays (not terminated by \0);
I've got following output:
2012-10-03 15:51:34.667 printf[3894:903] abcd
кириллица
2012-10-03 15:51:34.671 printf[3894:903] –∫–∏—Ä–∏–
2012-10-03 15:51:34.671 printf[3894:903] –
2012-10-03 15:51:34.672 printf[3894:903] –
кириллица
кири?
кириллица
For the program:
#import <Foundation/Foundation.h>
#include "wchar.h"
static
void test_string(const char *cstr, int precision)
{
char *array = malloc(strlen(cstr));
memcpy(array, cstr, strlen(cstr));
NSLog(@"%@", [NSString stringWithFormat:@"%.*s", precision, array]);
}
static
void test_string_long(const wchar_t *wcstr, int precision)
{
wchar_t *array = malloc(wcslen(wcstr) * sizeof(wchar_t));
memcpy(array, wcstr, wcslen(wcstr) * sizeof(wchar_t));
NSLog(@"%@", [NSString stringWithFormat:@"%.*ls", precision, array]);
}
static
void test_printf_long(const wchar_t *wcstr, int precision)
{
wchar_t *array = malloc(wcslen(wcstr) * sizeof(wchar_t));
memcpy(array, wcstr, wcslen(wcstr) * sizeof(wchar_t));
printf("%.*ls\n", precision, array);
}
int main (int argc, const char * argv[])
{
@autoreleasepool {
test_string("abcd", 4);
printf("%s\n", "кириллица");
test_string("кириллица", 9);
wchar_t *wcstr = L"кириллица";
test_string_long(wcstr, 9);
NSLog(@"%@", [NSString stringWithFormat:@"%ls", wcstr]);
printf("%ls\n", wcstr);
test_printf_long(wcstr, 9);
test_printf_long(wcstr, 18);
}
return 0;
}
I presume there is no need to test Apple's Foundation behavior with surrogate
UTF-16 pairs._______________________________________________
Gnustep-dev mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/gnustep-dev