1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
/*
* hdate_strings.c: convert libhdate internal numbers to readable hebrew strings.
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*/
#include <gnumeric-config.h>
#include <gnumeric.h>
#include <gnm-i18n.h>
#include <stdlib.h>
#include <string.h>
#include "hdate.h"
#define UNICODE_GERESH "\xd7\xb3"
#define UNICODE_GERSHAYIM "\xd7\xb4"
/**
@brief convert an integer to hebrew string UTF-8 (logical)
@param n The int to convert
@attention ( 0 < n < 10000)
@warning uses a static string, so output should be copied away.
*/
void
hdate_int_to_hebrew (GString *res, int n)
{
int oldlen = res->len;
int length;
static const char *digits[3][10] = {
{" ", "א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט"},
{"ט", "י", "כ", "ל", "מ", "נ", "ס", "ע", "פ", "צ"},
{" ", "ק", "ר", "ש", "ת"}
};
/* sanity checks */
if (n < 1 || n > 10000)
{
return;
}
if (n >= 1000)
{
g_string_append (res, digits[0][n / 1000]);
n %= 1000;
}
while (n >= 400)
{
g_string_append (res, digits[2][4]);
n -= 400;
}
if (n >= 100)
{
g_string_append (res, digits[2][n / 100]);
n %= 100;
}
if (n >= 10)
{
if (n == 15 || n == 16)
n -= 9;
g_string_append (res, digits[1][n / 10]);
n %= 10;
}
if (n > 0)
g_string_append (res, digits[0][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 (res, UNICODE_GERESH);
else
g_string_insert
(res,
g_utf8_offset_to_pointer (res->str + oldlen,
length - 1) - res->str,
UNICODE_GERSHAYIM);
}
/**
@brief Return a static string, with name of hebrew month.
@param month The number of the month 0..13 (0 - tishre, 12 - adar 1, 13 - adar 2).
@warning uses a static string, so output should be copied away.
*/
const char *
hdate_get_hebrew_month_name (int month)
{
static const char *heb_months[] = {
/* We are using the spellings as included in the */
/* Merriam-Webster dictionary */
/* xgettext: Tishri to Adar II are transliterations of the */
/* xgettext: hebrew months' names using Latin characters. */
N_("Tishri"), N_("Heshwan"), N_("Kislev"),
N_("Tebet"), N_("Shebat"), N_("Adar"),
N_("Nisan"), N_("Iyar"), N_("Sivan"), N_("Tammuz"),
N_("Ab"), N_("Elul"), N_("Adar I"), N_("Adar II")
};
if (month < 0 || month > 13)
return NULL;
return heb_months[month];
}
/**
@brief Return a static string, with name of hebrew month in hebrew.
@param month The number of the month 0..13 (0 - tishre, 12 - adar 1, 13 - adar 2).
@warning uses a static string, so output should be copied away.
*/
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)
return NULL;
return h_heb_months[month];
}
|