[gnumeric] fix hdate_heb and date2hdate_heb [#625177]



commit 6be9c2e51c42c13dcf8700fbbee0a418967916a0
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Sun Jul 25 13:53:21 2010 -0600

    fix hdate_heb and date2hdate_heb [#625177]
    
    2010-07-25  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* functions.c (build_hdate): new
    	(gnumeric_hdate_heb): use build_hdate
    	(gnumeric_date2hdate_heb): use build_hdate
    	* hdate_strings.c (hdate_int_to_hebrew): fix character/byte confusion and
    	  use hebrew quotes
    	(hdate_get_hebrew_month_name_heb): use the complete names

 NEWS                                   |    2 +-
 plugins/fn-hebrew-date/ChangeLog       |    9 ++++++++
 plugins/fn-hebrew-date/functions.c     |   23 +++++++++++---------
 plugins/fn-hebrew-date/hdate_strings.c |   35 +++++++++++++++++++++++++------
 4 files changed, 51 insertions(+), 18 deletions(-)
---
diff --git a/NEWS b/NEWS
index bac22ec..4ec3f8d 100644
--- a/NEWS
+++ b/NEWS
@@ -16,7 +16,7 @@ Andreas:
 	* Fix various function docs issues.  [#623669][#624559][#625102]
 	* Improve the presentation of the examples in the function
 	  documentation. [#623455]
-	* Fix HDATE and friends. [#623764]
+	* Fix HDATE and friends. [#623764][#625177]
 	* New functions DATE2HDATE, DATE2HDATE_HEB and DATE2JULIAN.
 	* Add hyperlink and comment removal menu items.
 	* Add merge and unmerge menu items.
diff --git a/plugins/fn-hebrew-date/ChangeLog b/plugins/fn-hebrew-date/ChangeLog
index be5cb06..278c01c 100644
--- a/plugins/fn-hebrew-date/ChangeLog
+++ b/plugins/fn-hebrew-date/ChangeLog
@@ -1,3 +1,12 @@
+2010-07-25  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* functions.c (build_hdate): new
+	(gnumeric_hdate_heb): use build_hdate
+	(gnumeric_date2hdate_heb): use build_hdate
+	* hdate_strings.c (hdate_int_to_hebrew): fix character/byte confusion and
+	  use hebrew quotes
+	(hdate_get_hebrew_month_name_heb): use the complete names
+
 2010-07-07  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* plugin.xml.in: new functions DATE2HDATE, DATE2HDATE_HEB, and
diff --git a/plugins/fn-hebrew-date/functions.c b/plugins/fn-hebrew-date/functions.c
index 23904dd..f141eef 100644
--- a/plugins/fn-hebrew-date/functions.c
+++ b/plugins/fn-hebrew-date/functions.c
@@ -48,6 +48,7 @@
 GNM_PLUGIN_MODULE_HEADER;
 
 #define DATE_CONV(ep)               workbook_date_conv ((ep)->sheet->workbook)
+#define UNICODE_MONTH_PREFIX "\xd7\x91\xd6\xbc\xd6\xb0"
 
 static void
 gnumeric_hdate_get_date (GnmValue const * const *arg, int *year, int *month, int *day)
@@ -167,6 +168,16 @@ static GnmFuncHelp const help_hdate_heb[] = {
 	{ GNM_FUNC_HELP_END }
 };
 
+static void
+build_hdate (GString *res, int hyear, int hmonth, int hday)
+{
+	hdate_int_to_hebrew (res, hday + 1);
+	g_string_append (res, " " UNICODE_MONTH_PREFIX);
+	g_string_append (res, hdate_get_hebrew_month_name_heb (hmonth));
+	g_string_append_c (res, ' ');
+	hdate_int_to_hebrew (res, hyear);
+}
+
 static GnmValue *
 gnumeric_hdate_heb (GnmFuncEvalInfo * ei, GnmValue const * const *argv)
 {
@@ -180,11 +191,7 @@ gnumeric_hdate_heb (GnmFuncEvalInfo * ei, GnmValue const * const *argv)
 		return value_new_error_VALUE (ei->pos);
 
 	res = g_string_new (NULL);
-	hdate_int_to_hebrew (res, hday + 1);
-	g_string_append_c (res, ' ');
-	g_string_append (res, hdate_get_hebrew_month_name_heb (hmonth));
-	g_string_append_c (res, ' ');
-	hdate_int_to_hebrew (res, hyear);
+	build_hdate (res, hyear, hmonth, hday);
 
 	return value_new_string_nocopy (g_string_free (res, FALSE));
 }
@@ -216,11 +223,7 @@ gnumeric_date2hdate_heb (GnmFuncEvalInfo * ei, GnmValue const * const *argv)
 		return value_new_error_VALUE (ei->pos);
 
 	res = g_string_new (NULL);
-	hdate_int_to_hebrew (res, hday + 1);
-	g_string_append_c (res, ' ');
-	g_string_append (res, hdate_get_hebrew_month_name_heb (hmonth));
-	g_string_append_c (res, ' ');
-	hdate_int_to_hebrew (res, hyear);
+	build_hdate (res, hyear, hmonth, hday);
 
 	return value_new_string_nocopy (g_string_free (res, FALSE));
 }
diff --git a/plugins/fn-hebrew-date/hdate_strings.c b/plugins/fn-hebrew-date/hdate_strings.c
index 815f401..caf91f6 100644
--- a/plugins/fn-hebrew-date/hdate_strings.c
+++ b/plugins/fn-hebrew-date/hdate_strings.c
@@ -2,8 +2,9 @@
 /*
  * hdate_strings.c: convert libhdate internal numbers to readable hebrew strings.
  *
- * Author:
+ * Authors:
  *   Yaacov Zamir <kzamir walla co il>
+ *   Andreas J. Guelzow <aguelzow taliesin ca>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -29,6 +30,9 @@
 
 #include "hdate.h"
 
+#define UNICODE_GERESH "\xd7\xb3"
+#define UNICODE_GERSHAYIM "\xd7\xb4"
+
 /**
  @brief convert an integer to hebrew string UTF-8 (logical)
  
@@ -80,11 +84,17 @@ hdate_int_to_hebrew (GString *res, int n)
 
 	length = g_utf8_strlen (res->str + oldlen, -1);
 
+	/* Note: length is in characters */
+
 	/* add the ' and " to hebrew numbers */
-	if (length <= 2)
-		g_string_append_c (res, '\'');
+	if (length < 2)
+		g_string_append (res, UNICODE_GERESH);
 	else
-		g_string_insert_c (res, length - 2, '"');
+		g_string_insert
+			(res, 
+			 g_utf8_offset_to_pointer (res->str + oldlen,
+						   length - 1) - res->str, 
+			 UNICODE_GERSHAYIM);
 }
 
 /**
@@ -123,9 +133,20 @@ const char *
 hdate_get_hebrew_month_name_heb (int month)
 {
 	static const char *h_heb_months[] = {
-		"תשר×?", "×?ש×?×?", "×?ס×?×?", "×?×?ת", "ש×?×?", "×?×?ר",
-		"× ×?ס×?", "×?×?ר", "ס×?×?×?", "ת×?×?×?", "×?×?", "×?×?×?×?", 
-		"×?×?ר ×?", "×?×?ר ×?"
+		"ת\xd6\xbc\xd6\xb4ש\xd7\x81\xd6\xb0ר\xd6\xb5×?", /* Tishri */
+		"×?\xd6\xb6ש\xd7\x81\xd6\xb0×?\xd7\x87×?",         /* Heshwan */ 
+		"×?\xd6\xbc\xd6\xb4ס\xd6\xb0×?\xd6\xb5×?",         /* Kislev */
+		"×?\xd6\xb5×?\xd6\xb5ת",                          /* Tebet */
+		"ש\xd7\x81\xd6\xb0×?\xd7\x87×?",                  /* Shebat */
+		"×?\xd6\xb7×?\xd7\x87ר",                          /* Adar */
+		"× \xd6\xb4×?ס\xd7\x87×?",                         /* Nissan */
+		"×?\xd6\xb4×?\xd7\x87×?ר",                         /* Iyar */
+		"ס\xd6\xb4×?×?\xd7\x87×?",                         /* Sivan */
+		"ת\xd6\xbc\xd7\x87×?×?\xd6\xbc×?",                 /* Tammuz */
+		"×?\xd6\xb8×?",                                   /* Ab */
+		"×?\xd6\xb1×?×?\xd6\xbc×?",                         /* Elul */
+		"×?\xd6\xb7×?\xd7\x87ר ×?\xd7\xb3",                /* Adar I*/
+		"×?\xd6\xb7×?\xd7\x87ר ×?\xd7\xb3"                 /* Adar II*/
 	};
 
 	if (month < 0 || month > 13)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]