1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-10 05:03:06 +03:00
* locale/lc-time.c (_nl_parse_alt_digit): New function.
	* locale/localeinfo.h: Add prototype for it.
	* time/strptime.c (get_alt_number): Use _nl_parse_alt_digit to get
	the value.  Correct computation of hour for %OI.  If no %EC given
	but %Ey use numeric formular.
This commit is contained in:
Ulrich Drepper
2001-08-10 02:09:02 +00:00
parent 5b643faffc
commit 2b15132f98
4 changed files with 94 additions and 43 deletions

View File

@@ -1,5 +1,11 @@
2001-08-09 Ulrich Drepper <drepper@redhat.com> 2001-08-09 Ulrich Drepper <drepper@redhat.com>
* locale/lc-time.c (_nl_parse_alt_digit): New function.
* locale/localeinfo.h: Add prototype for it.
* time/strptime.c (get_alt_number): Use _nl_parse_alt_digit to get
the value. Correct computation of hour for %OI. If no %EC given
but %Ey use numeric formular.
* dlfcn/Makefile (tststatic-ENV): Also add $(common-objpfx)elf for * dlfcn/Makefile (tststatic-ENV): Also add $(common-objpfx)elf for
ld.so. ld.so.

View File

@@ -1,5 +1,5 @@
/* Define current locale data for LC_TIME category. /* Define current locale data for LC_TIME category.
Copyright (C) 1995-1999, 2000 Free Software Foundation, Inc. Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or The GNU C Library is free software; you can redistribute it and/or
@@ -250,6 +250,63 @@ _nl_get_walt_digit (unsigned int number)
} }
int
_nl_parse_alt_digit (const char **strp)
{
const char *str = *strp;
int result = -1;
size_t cnt;
size_t maxlen = 0;
__libc_lock_lock (__libc_setlocale_lock);
if (alt_digits_initialized == 0)
{
alt_digits_initialized = 1;
if (alt_digits == NULL)
alt_digits = malloc (100 * sizeof (const char *));
if (alt_digits != NULL)
{
const char *ptr = _NL_CURRENT (LC_TIME, ALT_DIGITS);
if (alt_digits != NULL)
for (cnt = 0; cnt < 100; ++cnt)
{
alt_digits[cnt] = ptr;
/* Skip digit format. */
ptr = strchr (ptr, '\0') + 1;
}
}
}
/* Matching is not unambiguos. The alternative digits could be like
I, II, III, ... and the first one is a substring of the second
and third. Therefore we must keep on searching until we found
the longest possible match. Note that this is not specified in
the standard. */
for (cnt = 0; cnt < 100; ++cnt)
{
size_t len = strlen (alt_digits[cnt]);
if (len > maxlen && strncmp (alt_digits[cnt], str, len) == 0)
{
maxlen = len;
result = (int) cnt;
}
}
__libc_lock_unlock (__libc_setlocale_lock);
if (result != -1)
*strp += maxlen;
return result;
}
static void static void
free_mem (void) free_mem (void)
{ {

View File

@@ -205,6 +205,9 @@ extern const char *_nl_get_alt_digit (unsigned int number);
/* Similar, but now for wide characters. */ /* Similar, but now for wide characters. */
extern const wchar_t *_nl_get_walt_digit (unsigned int number); extern const wchar_t *_nl_get_walt_digit (unsigned int number);
/* Parse string as alternative digit and return numeric value. */
extern int _nl_parse_alt_digit (const char **strp);
/* Postload processing. */ /* Postload processing. */
extern void _nl_postload_ctype (void); extern void _nl_postload_ctype (void);
extern void _nl_postload_time (void); extern void _nl_postload_time (void);

View File

@@ -39,7 +39,7 @@
#ifndef __P #ifndef __P
# if defined (__GNUC__) || (defined (__STDC__) && __STDC__) # if defined __GNUC__ || (defined __STDC__ && __STDC__)
# define __P(args) args # define __P(args) args
# else # else
# define __P(args) () # define __P(args) ()
@@ -101,47 +101,24 @@ localtime_r (t, tp)
#ifdef _NL_CURRENT #ifdef _NL_CURRENT
# define get_alt_number(from, to, n) \ # define get_alt_number(from, to, n) \
({ \ ({ \
__label__ do_normal; \ __label__ do_normal; \
if (*decided != raw) \ \
{ \ if (*decided != raw) \
const char *alts = _NL_CURRENT (LC_TIME, ALT_DIGITS); \ { \
int __n = n; \ val = _nl_parse_alt_digit (&rp); \
int any = 0; \ if (val == -1 && *decided != loc) \
while (*rp == ' ') \ { \
++rp; \ *decided = loc; \
val = 0; \ goto do_normal; \
do { \ } \
val *= 10; \
while (*alts != '\0') \
{ \
size_t len = strlen (alts); \
if (strncasecmp (alts, rp, len) == 0) \
break; \
alts += len + 1; \
++val; \
} \
if (*alts == '\0') \
{ \
if (*decided == not && ! any) \
goto do_normal; \
/* If we haven't read anything it's an error. */ \
if (! any) \
return NULL; \
/* Correct the premature multiplication. */ \
val /= 10; \
break; \
} \
else \
*decided = loc; \
} while (--__n > 0 && val * 10 <= to); \
if (val < from || val > to) \ if (val < from || val > to) \
return NULL; \ return NULL; \
} \ } \
else \ else \
{ \ { \
do_normal: \ do_normal: \
get_number (from, to, n); \ get_number (from, to, n); \
} \ } \
0; \ 0; \
}) })
#else #else
@@ -770,6 +747,7 @@ strptime_internal (rp, fmt, tm, decided, era_cnt)
tm->tm_year = val; tm->tm_year = val;
want_era = 1; want_era = 1;
want_xday = 1; want_xday = 1;
want_century = 1;
break; break;
case 'Y': case 'Y':
if (*decided != raw) if (*decided != raw)
@@ -893,7 +871,7 @@ strptime_internal (rp, fmt, tm, decided, era_cnt)
/* Match hour in 12-hour clock using alternate numeric /* Match hour in 12-hour clock using alternate numeric
symbols. */ symbols. */
get_alt_number (1, 12, 2); get_alt_number (1, 12, 2);
tm->tm_hour = val - 1; tm->tm_hour = val % 12;
have_I = 1; have_I = 1;
break; break;
case 'm': case 'm':
@@ -963,7 +941,7 @@ strptime_internal (rp, fmt, tm, decided, era_cnt)
if (era_cnt != -1) if (era_cnt != -1)
{ {
era = _nl_select_era_entry(era_cnt); era = _nl_select_era_entry (era_cnt);
if (want_era) if (want_era)
tm->tm_year = (era->start_date[0] tm->tm_year = (era->start_date[0]
+ ((tm->tm_year - era->offset) + ((tm->tm_year - era->offset)
@@ -974,7 +952,12 @@ strptime_internal (rp, fmt, tm, decided, era_cnt)
} }
else else
if (want_era) if (want_era)
return NULL; {
/* No era found but we have seen an E modifier. Rectify some
values. */
if (want_century && century == -1 && tm->tm_year < 69)
tm->tm_year += 100;
}
if (want_xday && !have_wday) if (want_xday && !have_wday)
{ {
@@ -993,8 +976,10 @@ strptime_internal (rp, fmt, tm, decided, era_cnt)
} }
day_of_the_week (tm); day_of_the_week (tm);
} }
if (want_xday && !have_yday) if (want_xday && !have_yday)
day_of_the_year (tm); day_of_the_year (tm);
if ((have_uweek || have_wweek) && have_wday) if ((have_uweek || have_wweek) && have_wday)
{ {
int save_wday = tm->tm_wday; int save_wday = tm->tm_wday;