mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-10 16:20:42 +00:00
Minor fix and output improvements.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@9166 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
5cbddd279d
commit
000d0cc4e6
3 changed files with 158 additions and 61 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,9 @@
|
|||
2001-02-19 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/GSLocale.m: Tidy, defined __USE_GNU to get YESSTR and NOSTR
|
||||
on later versions of glibc.
|
||||
* Source/NSString.m: Log more info when parsing a property list fails.
|
||||
|
||||
2001-02-13 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Version: 0.9.1
|
||||
|
@ -11,8 +17,8 @@
|
|||
-GSXMLNode name
|
||||
-GSXMLNode ns
|
||||
-GSXMLNode nsDef
|
||||
* NSString.m: handle NULL bytes in -initWithUTF8String: (Treat it as zero
|
||||
length string and NSDebugMLog a warning).
|
||||
* NSString.m: handle NULL bytes in -initWithUTF8String:
|
||||
(Treat it as zero length string and NSDebugMLog a warning).
|
||||
|
||||
2001-02-09 Jonathan Gapen <jagapen@home.com>
|
||||
|
||||
|
|
|
@ -30,6 +30,10 @@
|
|||
|
||||
#include <locale.h>
|
||||
#ifdef HAVE_LANGINFO_H
|
||||
/*
|
||||
* Define __USE_GNU to get YESSTR and NOSTR in glibc-2.2.2
|
||||
*/
|
||||
#define __USE_GNU
|
||||
#include <langinfo.h>
|
||||
#endif
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
|
@ -47,17 +51,23 @@ GSSetLocale(NSString *locale)
|
|||
const char *clocale;
|
||||
|
||||
clocale = NULL;
|
||||
if (locale)
|
||||
clocale = [locale cString];
|
||||
if (locale != nil)
|
||||
{
|
||||
clocale = [locale cString];
|
||||
}
|
||||
clocale = setlocale(LC_ALL, clocale);
|
||||
|
||||
if (clocale == NULL || strcmp(clocale, "C") == 0
|
||||
|| strcmp(clocale, "POSIX") == 0)
|
||||
clocale = NULL;
|
||||
|| strcmp(clocale, "POSIX") == 0)
|
||||
{
|
||||
clocale = NULL;
|
||||
}
|
||||
|
||||
locale = nil;
|
||||
if (clocale)
|
||||
locale = [NSString stringWithCString: clocale];
|
||||
if (clocale != 0)
|
||||
{
|
||||
locale = [NSString stringWithCString: clocale];
|
||||
}
|
||||
return locale;
|
||||
}
|
||||
|
||||
|
@ -70,74 +80,102 @@ NSDictionary *
|
|||
GSDomainFromDefaultLocale(void)
|
||||
{
|
||||
#ifdef HAVE_LANGINFO_H
|
||||
int i;
|
||||
struct lconv *lconv;
|
||||
NSMutableDictionary *dict;
|
||||
NSMutableArray *arr;
|
||||
NSString *str1, *str2;
|
||||
int i;
|
||||
struct lconv *lconv;
|
||||
NSMutableDictionary *dict;
|
||||
NSMutableArray *arr;
|
||||
NSString *str1;
|
||||
NSString *str2;
|
||||
|
||||
dict = [NSMutableDictionary dictionary];
|
||||
|
||||
/* Time/Date Information */
|
||||
arr = [NSMutableArray arrayWithCapacity: 7];
|
||||
for (i = 0; i < 7; i++)
|
||||
[arr addObject: GSLanginfo(DAY_1+i)];
|
||||
{
|
||||
[arr addObject: GSLanginfo(DAY_1+i)];
|
||||
}
|
||||
[dict setObject: arr forKey: NSWeekDayNameArray];
|
||||
|
||||
arr = [NSMutableArray arrayWithCapacity: 7];
|
||||
for (i = 0; i < 7; i++)
|
||||
[arr addObject: GSLanginfo(ABDAY_1+i)];
|
||||
{
|
||||
[arr addObject: GSLanginfo(ABDAY_1+i)];
|
||||
}
|
||||
[dict setObject: arr forKey: NSShortWeekDayNameArray];
|
||||
|
||||
arr = [NSMutableArray arrayWithCapacity: 12];
|
||||
for (i = 0; i < 12; i++)
|
||||
[arr addObject: GSLanginfo(MON_1+i)];
|
||||
{
|
||||
[arr addObject: GSLanginfo(MON_1+i)];
|
||||
}
|
||||
[dict setObject: arr forKey: NSMonthNameArray];
|
||||
|
||||
arr = [NSMutableArray arrayWithCapacity: 12];
|
||||
for (i = 0; i < 12; i++)
|
||||
[arr addObject: GSLanginfo(ABMON_1+i)];
|
||||
{
|
||||
[arr addObject: GSLanginfo(ABMON_1+i)];
|
||||
}
|
||||
[dict setObject: arr forKey: NSShortMonthNameArray];
|
||||
|
||||
str1 = GSLanginfo(AM_STR);
|
||||
str2 = GSLanginfo(PM_STR);
|
||||
if (str1 && str2)
|
||||
[dict setObject: [NSArray arrayWithObjects: str1, str2, nil]
|
||||
forKey: NSAMPMDesignation];
|
||||
if (str1 != nil && str2 != nil)
|
||||
{
|
||||
[dict setObject: [NSArray arrayWithObjects: str1, str2, nil]
|
||||
forKey: NSAMPMDesignation];
|
||||
}
|
||||
|
||||
[dict setObject: GSLanginfo(D_T_FMT) forKey: NSTimeDateFormatString];
|
||||
[dict setObject: GSLanginfo(D_FMT) forKey: NSShortDateFormatString];
|
||||
[dict setObject: GSLanginfo(T_FMT) forKey: NSTimeFormatString];
|
||||
[dict setObject: GSLanginfo(D_T_FMT)
|
||||
forKey: NSTimeDateFormatString];
|
||||
[dict setObject: GSLanginfo(D_FMT)
|
||||
forKey: NSShortDateFormatString];
|
||||
[dict setObject: GSLanginfo(T_FMT)
|
||||
forKey: NSTimeFormatString];
|
||||
|
||||
lconv = localeconv();
|
||||
|
||||
/* Currency Information */
|
||||
if (lconv->currency_symbol)
|
||||
[dict setObject: [NSString stringWithCString: lconv->currency_symbol ]
|
||||
forKey: NSCurrencySymbol];
|
||||
{
|
||||
[dict setObject: [NSString stringWithCString: lconv->currency_symbol]
|
||||
forKey: NSCurrencySymbol];
|
||||
}
|
||||
if (lconv->int_curr_symbol)
|
||||
[dict setObject: [NSString stringWithCString: lconv->int_curr_symbol]
|
||||
forKey: NSInternationalCurrencyString ];
|
||||
{
|
||||
[dict setObject: [NSString stringWithCString: lconv->int_curr_symbol]
|
||||
forKey: NSInternationalCurrencyString];
|
||||
}
|
||||
if (lconv->mon_decimal_point)
|
||||
[dict setObject: [NSString stringWithCString: lconv->mon_decimal_point]
|
||||
forKey: NSInternationalCurrencyString ];
|
||||
{
|
||||
[dict setObject: [NSString stringWithCString: lconv->mon_decimal_point]
|
||||
forKey: NSInternationalCurrencyString];
|
||||
}
|
||||
if (lconv->mon_thousands_sep)
|
||||
[dict setObject: [NSString stringWithCString: lconv->mon_thousands_sep]
|
||||
forKey: NSInternationalCurrencyString ];
|
||||
{
|
||||
[dict setObject: [NSString stringWithCString: lconv->mon_thousands_sep]
|
||||
forKey: NSInternationalCurrencyString];
|
||||
}
|
||||
/* FIXME: Get currency format from localeconv */
|
||||
|
||||
|
||||
/* Miscellaneous */
|
||||
if (nl_langinfo(YESSTR))
|
||||
[dict setObject: GSLanginfo(YESSTR) forKey: @"NSYesStr"];
|
||||
{
|
||||
[dict setObject: GSLanginfo(YESSTR) forKey: @"NSYesStr"];
|
||||
}
|
||||
if (nl_langinfo(NOSTR))
|
||||
[dict setObject: GSLanginfo(NOSTR) forKey: @"NSNoStr"];
|
||||
{
|
||||
[dict setObject: GSLanginfo(NOSTR) forKey: @"NSNoStr"];
|
||||
}
|
||||
|
||||
str1 = [NSString stringWithCString: setlocale(LC_ALL, NULL)];
|
||||
[dict setObject: str1 forKey: NSLocale];
|
||||
str2 = GSLanguageFromLocale(str1);
|
||||
if (str2)
|
||||
[dict setObject: str2 forKey: NSLanguageName];
|
||||
{
|
||||
[dict setObject: str2 forKey: NSLanguageName];
|
||||
}
|
||||
|
||||
return dict;
|
||||
#else /* HAVE_LANGINFO_H */
|
||||
|
@ -148,8 +186,8 @@ GSDomainFromDefaultLocale(void)
|
|||
NSString *
|
||||
GSLanguageFromLocale(NSString *locale)
|
||||
{
|
||||
NSString *language = nil;
|
||||
NSString *aliases = nil;
|
||||
NSString *language = nil;
|
||||
NSString *aliases = nil;
|
||||
|
||||
if (locale == nil || [locale isEqual: @"C"] || [locale isEqual: @"POSIX"])
|
||||
return @"English";
|
||||
|
@ -157,12 +195,13 @@ GSLanguageFromLocale(NSString *locale)
|
|||
aliases = [NSBundle pathForGNUstepResource: @"Locale"
|
||||
ofType: @"aliases"
|
||||
inDirectory: @"Resources/Languages"];
|
||||
if (aliases)
|
||||
if (aliases != nil)
|
||||
{
|
||||
NSDictionary *dict;
|
||||
NSDictionary *dict;
|
||||
|
||||
dict = [NSDictionary dictionaryWithContentsOfFile: aliases];
|
||||
language = [dict objectForKey: locale];
|
||||
if (language == nil && [locale pathExtension])
|
||||
if (language == nil && [locale pathExtension] != nil)
|
||||
{
|
||||
locale = [locale stringByDeletingPathExtension];
|
||||
language = [dict objectForKey: locale];
|
||||
|
@ -199,5 +238,3 @@ GSLanguageFromLocale(NSString *locale)
|
|||
#endif /* !HAVE_LOCALE_H */
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -4083,11 +4083,24 @@ GSPropertyList(NSString *string)
|
|||
pldata *pld = &_pld;
|
||||
unsigned length = [string length];
|
||||
NSData *d;
|
||||
id pl;
|
||||
#if HAVE_LIBXML
|
||||
unsigned index = 0;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* An empty string is a nil property list.
|
||||
*/
|
||||
if (length == 0)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
#if HAVE_LIBXML
|
||||
if (whitespce == nil)
|
||||
setupWhitespce();
|
||||
{
|
||||
setupWhitespce();
|
||||
}
|
||||
while (index < length)
|
||||
{
|
||||
unsigned c = [string characterAtIndex: index];
|
||||
|
@ -4122,7 +4135,8 @@ GSPropertyList(NSString *string)
|
|||
[[[parser doc] root] name]);
|
||||
return nil;
|
||||
}
|
||||
return AUTORELEASE(RETAIN(nodeToObject([[[parser doc] root] children])));
|
||||
pl = AUTORELEASE(RETAIN(nodeToObject([[[parser doc] root] children])));
|
||||
return pl;
|
||||
}
|
||||
#endif
|
||||
d = [string dataUsingEncoding: NSUnicodeStringEncoding];
|
||||
|
@ -4132,8 +4146,16 @@ GSPropertyList(NSString *string)
|
|||
_pld.err = nil;
|
||||
_pld.lin = 1;
|
||||
if (plAlloc == 0)
|
||||
setupPl();
|
||||
return AUTORELEASE(parsePlItem(pld));
|
||||
{
|
||||
setupPl();
|
||||
}
|
||||
pl = AUTORELEASE(parsePlItem(pld));
|
||||
if (pl == nil && _pld.err != nil)
|
||||
{
|
||||
NSLog(@"Parse failed at line %d (char %d) - %@",
|
||||
_pld.lin, _pld.pos, _pld.err);
|
||||
}
|
||||
return pl;
|
||||
}
|
||||
|
||||
static id
|
||||
|
@ -4145,6 +4167,14 @@ GSPropertyListFromStringsFormat(NSString *string)
|
|||
unsigned length = [string length];
|
||||
NSData *d;
|
||||
|
||||
/*
|
||||
* An empty string is a nil property list.
|
||||
*/
|
||||
if (length == 0)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
d = [string dataUsingEncoding: NSUnicodeStringEncoding];
|
||||
_pld.ptr = (unichar*)[d bytes];
|
||||
_pld.pos = 1;
|
||||
|
@ -4152,7 +4182,9 @@ GSPropertyListFromStringsFormat(NSString *string)
|
|||
_pld.err = nil;
|
||||
_pld.lin = 1;
|
||||
if (plAlloc == 0)
|
||||
setupPl();
|
||||
{
|
||||
setupPl();
|
||||
}
|
||||
|
||||
dict = [[plDictionary allocWithZone: NSDefaultMallocZone()]
|
||||
initWithCapacity: 0];
|
||||
|
@ -4162,16 +4194,24 @@ GSPropertyListFromStringsFormat(NSString *string)
|
|||
id val;
|
||||
|
||||
if (pld->ptr[pld->pos] == '"')
|
||||
key = parseQuotedString(pld);
|
||||
{
|
||||
key = parseQuotedString(pld);
|
||||
}
|
||||
else
|
||||
key = parseUnquotedString(pld);
|
||||
{
|
||||
key = parseUnquotedString(pld);
|
||||
}
|
||||
if (key == nil)
|
||||
return nil;
|
||||
{
|
||||
DESTROY(dict);
|
||||
break;
|
||||
}
|
||||
if (skipSpace(pld) == NO)
|
||||
{
|
||||
pld->err = @"incomplete final entry (no semicolon?)";
|
||||
RELEASE(key);
|
||||
return nil;
|
||||
DESTROY(dict);
|
||||
break;
|
||||
}
|
||||
if (pld->ptr[pld->pos] == ';')
|
||||
{
|
||||
|
@ -4185,44 +4225,58 @@ GSPropertyListFromStringsFormat(NSString *string)
|
|||
if (skipSpace(pld) == NO)
|
||||
{
|
||||
RELEASE(key);
|
||||
return nil;
|
||||
DESTROY(dict);
|
||||
break;
|
||||
}
|
||||
if (pld->ptr[pld->pos] == '"')
|
||||
val = parseQuotedString(pld);
|
||||
{
|
||||
val = parseQuotedString(pld);
|
||||
}
|
||||
else
|
||||
val = parseUnquotedString(pld);
|
||||
{
|
||||
val = parseUnquotedString(pld);
|
||||
}
|
||||
if (val == nil)
|
||||
{
|
||||
RELEASE(key);
|
||||
return nil;
|
||||
DESTROY(dict);
|
||||
break;
|
||||
}
|
||||
if (skipSpace(pld) == NO)
|
||||
{
|
||||
pld->err = @"missing final semicolon";
|
||||
RELEASE(key);
|
||||
RELEASE(val);
|
||||
return nil;
|
||||
DESTROY(dict);
|
||||
break;
|
||||
}
|
||||
(*plSet)(dict, @selector(setObject:forKey:), val, key);
|
||||
RELEASE(key);
|
||||
RELEASE(val);
|
||||
if (pld->ptr[pld->pos] == ';')
|
||||
pld->pos++;
|
||||
{
|
||||
pld->pos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
pld->err = @"unexpected character (wanted ';')";
|
||||
RELEASE(dict);
|
||||
return nil;
|
||||
DESTROY(dict);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RELEASE(key);
|
||||
RELEASE(dict);
|
||||
pld->err = @"unexpected character (wanted '=' or ';')";
|
||||
return nil;
|
||||
RELEASE(key);
|
||||
DESTROY(dict);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dict == nil && _pld.err != nil)
|
||||
{
|
||||
NSLog(@"Parse failed at line %d (char %d) - %@",
|
||||
_pld.lin, _pld.pos, _pld.err);
|
||||
}
|
||||
return AUTORELEASE(dict);
|
||||
}
|
||||
#endif /* NO_GNUSTEP */
|
||||
|
|
Loading…
Reference in a new issue