mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-11-04 10:08:56 +01:00 
			
		
		
		
	win32_strftime_helper: Support nominative/genitive month names
A similar change to the commit be4f96b650,
supports %OB, %Ob, %Oh (alternative, standalone, nominative) month names
along with the old %B, %b, %h (primary, in full date format context,
genitive) month names.
https://bugzilla.gnome.org/show_bug.cgi?id=749206
			
			
This commit is contained in:
		
				
					committed by
					
						
						Philip Withnall
					
				
			
			
				
	
			
			
			
						parent
						
							5520a87930
						
					
				
				
					commit
					fa12658809
				
			
							
								
								
									
										41
									
								
								glib/gdate.c
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								glib/gdate.c
									
									
									
									
									
								
							@@ -2137,17 +2137,42 @@ static void
 | 
				
			|||||||
append_month_name (GArray     *result,
 | 
					append_month_name (GArray     *result,
 | 
				
			||||||
		   LCID        lcid,
 | 
							   LCID        lcid,
 | 
				
			||||||
		   SYSTEMTIME *systemtime,
 | 
							   SYSTEMTIME *systemtime,
 | 
				
			||||||
		   gboolean    abbreviated)
 | 
							   gboolean    abbreviated,
 | 
				
			||||||
 | 
							   gboolean    alternative)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  int n;
 | 
					  int n;
 | 
				
			||||||
  WORD base;
 | 
					  WORD base;
 | 
				
			||||||
 | 
					  LPCWSTR lpFormat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (alternative)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
      base = abbreviated ? LOCALE_SABBREVMONTHNAME1 : LOCALE_SMONTHNAME1;
 | 
					      base = abbreviated ? LOCALE_SABBREVMONTHNAME1 : LOCALE_SMONTHNAME1;
 | 
				
			||||||
      n = GetLocaleInfoW (lcid, base + systemtime->wMonth - 1, NULL, 0);
 | 
					      n = GetLocaleInfoW (lcid, base + systemtime->wMonth - 1, NULL, 0);
 | 
				
			||||||
      g_array_set_size (result, result->len + n);
 | 
					      g_array_set_size (result, result->len + n);
 | 
				
			||||||
      GetLocaleInfoW (lcid, base + systemtime->wMonth - 1,
 | 
					      GetLocaleInfoW (lcid, base + systemtime->wMonth - 1,
 | 
				
			||||||
		      ((wchar_t *) result->data) + result->len - n, n);
 | 
							      ((wchar_t *) result->data) + result->len - n, n);
 | 
				
			||||||
      g_array_set_size (result, result->len - 1);
 | 
					      g_array_set_size (result, result->len - 1);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      /* According to MSDN, this is the correct method to obtain
 | 
				
			||||||
 | 
					       * the form of the month name used when formatting a full
 | 
				
			||||||
 | 
					       * date; it must be a genitive case in some languages.
 | 
				
			||||||
 | 
					       */
 | 
				
			||||||
 | 
					      lpFormat = abbreviated ? L"ddMMM" : L"ddMMMM";
 | 
				
			||||||
 | 
					      n = GetDateFormatW (lcid, 0, systemtime, lpFormat, NULL, 0);
 | 
				
			||||||
 | 
					      g_array_set_size (result, result->len + n);
 | 
				
			||||||
 | 
					      GetDateFormatW (lcid, 0, systemtime, lpFormat,
 | 
				
			||||||
 | 
							      ((wchar_t *) result->data) + result->len - n, n);
 | 
				
			||||||
 | 
					      /* We have obtained a day number as two digits and the month name.
 | 
				
			||||||
 | 
					       * Now let's get rid of those two digits: overwrite them with the
 | 
				
			||||||
 | 
					       * month name.
 | 
				
			||||||
 | 
					       */
 | 
				
			||||||
 | 
					      memmove (((wchar_t *) result->data) + result->len - n,
 | 
				
			||||||
 | 
						       ((wchar_t *) result->data) + result->len - n + 2,
 | 
				
			||||||
 | 
						       (n - 2) * sizeof (wchar_t));
 | 
				
			||||||
 | 
					      g_array_set_size (result, result->len - 3);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static gsize
 | 
					static gsize
 | 
				
			||||||
@@ -2163,7 +2188,7 @@ win32_strftime_helper (const GDate     *d,
 | 
				
			|||||||
  int n, k;
 | 
					  int n, k;
 | 
				
			||||||
  GArray *result;
 | 
					  GArray *result;
 | 
				
			||||||
  const gchar *p;
 | 
					  const gchar *p;
 | 
				
			||||||
  gunichar c;
 | 
					  gunichar c, modifier;
 | 
				
			||||||
  const wchar_t digits[] = L"0123456789";
 | 
					  const wchar_t digits[] = L"0123456789";
 | 
				
			||||||
  gchar *convbuf;
 | 
					  gchar *convbuf;
 | 
				
			||||||
  glong convlen = 0;
 | 
					  glong convlen = 0;
 | 
				
			||||||
@@ -2196,10 +2221,14 @@ win32_strftime_helper (const GDate     *d,
 | 
				
			|||||||
	      return 0;
 | 
						      return 0;
 | 
				
			||||||
	    }
 | 
						    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						  modifier = '\0';
 | 
				
			||||||
	  c = g_utf8_get_char (p);
 | 
						  c = g_utf8_get_char (p);
 | 
				
			||||||
	  if (c == 'E' || c == 'O')
 | 
						  if (c == 'E' || c == 'O')
 | 
				
			||||||
	    {
 | 
						    {
 | 
				
			||||||
	      /* Ignore modified conversion specifiers for now. */
 | 
						      /* "%OB", "%Ob", and "%Oh" are supported, ignore other modified
 | 
				
			||||||
 | 
						       * conversion specifiers for now.
 | 
				
			||||||
 | 
						       */
 | 
				
			||||||
 | 
						      modifier = c;
 | 
				
			||||||
	      p = g_utf8_next_char (p);
 | 
						      p = g_utf8_next_char (p);
 | 
				
			||||||
	      if (!*p)
 | 
						      if (!*p)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@@ -2236,10 +2265,12 @@ win32_strftime_helper (const GDate     *d,
 | 
				
			|||||||
	      break;
 | 
						      break;
 | 
				
			||||||
	    case 'b':
 | 
						    case 'b':
 | 
				
			||||||
	    case 'h':
 | 
						    case 'h':
 | 
				
			||||||
	      append_month_name (result, lcid, &systemtime, TRUE);
 | 
						      append_month_name (result, lcid, &systemtime, TRUE,
 | 
				
			||||||
 | 
									 modifier == 'O');
 | 
				
			||||||
	      break;
 | 
						      break;
 | 
				
			||||||
	    case 'B':
 | 
						    case 'B':
 | 
				
			||||||
	      append_month_name (result, lcid, &systemtime, FALSE);
 | 
						      append_month_name (result, lcid, &systemtime, FALSE,
 | 
				
			||||||
 | 
									 modifier == 'O');
 | 
				
			||||||
	      break;
 | 
						      break;
 | 
				
			||||||
	    case 'c':
 | 
						    case 'c':
 | 
				
			||||||
	      n = GetDateFormatW (lcid, 0, &systemtime, NULL, NULL, 0);
 | 
						      n = GetDateFormatW (lcid, 0, &systemtime, NULL, NULL, 0);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user