* nlsfuncs.cc (lc_wcstombs): Add `return_invalid' flag to specify
whether invalid chars should be ignored or not. Change comment. (__set_lc_monetary_from_win): Call lc_wcstombs with return_invalid flag set. (__set_lc_messages_from_win): Simplify to accommodate the fact that lc_wcstombs just ignores invalid chars. Explain why.
This commit is contained in:
		| @@ -229,12 +229,13 @@ __get_lcid_from_locale (const char *name) | |||||||
|   return last_lcid; |   return last_lcid; | ||||||
| } | } | ||||||
|  |  | ||||||
| /* Never returns -1, *iff* s is not NULL.  Just skips invalid chars | /* Never returns -1.  Just skips invalid chars instead.  Only if return_invalid | ||||||
|    instead.  s==NULL returns -1 since it's used to recognize invalid |    is set, s==NULL returns -1 since then it's used to recognize invalid strings | ||||||
|    strings in the used charset. */ |    in the used charset. */ | ||||||
| static size_t | static size_t | ||||||
| lc_wcstombs (wctomb_p f_wctomb, const char *charset, | lc_wcstombs (wctomb_p f_wctomb, const char *charset, | ||||||
| 	     char *s, const wchar_t *pwcs, size_t n) | 	     char *s, const wchar_t *pwcs, size_t n, | ||||||
|  | 	     bool return_invalid = false) | ||||||
| { | { | ||||||
|   char *ptr = s; |   char *ptr = s; | ||||||
|   size_t max = n; |   size_t max = n; | ||||||
| @@ -249,9 +250,10 @@ lc_wcstombs (wctomb_p f_wctomb, const char *charset, | |||||||
|       while (*pwcs != 0) |       while (*pwcs != 0) | ||||||
| 	{ | 	{ | ||||||
| 	  bytes = f_wctomb (_REENT, buf, *pwcs++, charset, &state); | 	  bytes = f_wctomb (_REENT, buf, *pwcs++, charset, &state); | ||||||
| 	  if (bytes == (size_t) -1) | 	  if (bytes != (size_t) -1) | ||||||
|  | 	    num_bytes += bytes; | ||||||
|  | 	  else if (return_invalid) | ||||||
| 	    return (size_t) -1; | 	    return (size_t) -1; | ||||||
| 	  num_bytes += bytes; |  | ||||||
| 	} | 	} | ||||||
|       return num_bytes; |       return num_bytes; | ||||||
|     } |     } | ||||||
| @@ -610,7 +612,7 @@ __set_lc_monetary_from_win (const char *name, | |||||||
|        given charset, use int_curr_symbol. */ |        given charset, use int_curr_symbol. */ | ||||||
|     wchar_t wbuf[14]; |     wchar_t wbuf[14]; | ||||||
|     GetLocaleInfoW (lcid, LOCALE_SCURRENCY, wbuf, 14); |     GetLocaleInfoW (lcid, LOCALE_SCURRENCY, wbuf, 14); | ||||||
|     if (lc_wcstombs (f_wctomb, charset, NULL, wbuf, 0) == (size_t) -1) |     if (lc_wcstombs (f_wctomb, charset, NULL, wbuf, 0, true) == (size_t) -1) | ||||||
|       { |       { | ||||||
| 	_monetary_locale->currency_symbol = lc_monetary_ptr; | 	_monetary_locale->currency_symbol = lc_monetary_ptr; | ||||||
| 	lc_monetary_ptr = stpncpy (lc_monetary_ptr, | 	lc_monetary_ptr = stpncpy (lc_monetary_ptr, | ||||||
| @@ -717,23 +719,16 @@ __set_lc_messages_from_win (const char *name, | |||||||
|   if (!res) |   if (!res) | ||||||
|     return 0; |     return 0; | ||||||
|  |  | ||||||
|   /* Evaluate string length in target charset. */ |   /* Evaluate string length in target charset.  Characters invalid in the | ||||||
|   size_t len, total = 0; |      target charset are simply ignored, as on Linux. */ | ||||||
|   total += (len = lc_wcstombs (f_wctomb, charset, NULL, res->yesexpr, 0)) + 1; |   size_t len = 0; | ||||||
|   if (len == (size_t) -1) |   len += lc_wcstombs (f_wctomb, charset, NULL, res->yesexpr, 0) + 1; | ||||||
|     return -1; |   len += lc_wcstombs (f_wctomb, charset, NULL, res->noexpr, 0) + 1; | ||||||
|   total += (len = lc_wcstombs (f_wctomb, charset, NULL, res->noexpr, 0)) + 1; |   len += lc_wcstombs (f_wctomb, charset, NULL, res->yesstr, 0) + 1; | ||||||
|   if (len == (size_t) -1) |   len += lc_wcstombs (f_wctomb, charset, NULL, res->nostr, 0) + 1; | ||||||
|     return -1; |  | ||||||
|   total += (len = lc_wcstombs (f_wctomb, charset, NULL, res->yesstr, 0)) + 1; |  | ||||||
|   if (len == (size_t) -1) |  | ||||||
|     return -1; |  | ||||||
|   total += (len = lc_wcstombs (f_wctomb, charset, NULL, res->nostr, 0)) + 1; |  | ||||||
|   if (len == (size_t) -1) |  | ||||||
|     return -1; |  | ||||||
|   /* Allocate. */ |   /* Allocate. */ | ||||||
|   char *new_lc_messages_buf = (char *) malloc (total); |   char *new_lc_messages_buf = (char *) malloc (len); | ||||||
|   const char *lc_messages_end = new_lc_messages_buf + total; |   const char *lc_messages_end = new_lc_messages_buf + len; | ||||||
|  |  | ||||||
|   if (!new_lc_messages_buf) |   if (!new_lc_messages_buf) | ||||||
|     return -1; |     return -1; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user