mirror of https://github.com/Gnucash/gnucash
* qof_time_format_from_utf8 converts an strftime format specification from UTF-8 to the locale encoding * qof_format_time calls strftime repeatedly with growing allocated buffers until the result fits into one, or return NULL * qof_formatted_time_to_utf8 converts the result back to UTF-8 * qof_strftime takes similar arguments to strftime, but in UTF-8 * the conversion functions on Windows are implemented in qof-win32.c to allow them to use windows.h, as they need wcstombs and mbstowcs git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@15795 57a11ea4-9604-0410-9ed3-97b8803252fdzzzoldfeatures/dogtail
parent
91eb3d4262
commit
095c71a5f1
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* gnc-date-p.h
|
||||
*
|
||||
* Copyright (C) 2007 Andreas Koehler <andi5.py@gmx.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2 of the GNU General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* 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, contact:
|
||||
*
|
||||
* Free Software Foundation Voice: +1-617-542-5942
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org
|
||||
*/
|
||||
|
||||
#ifndef __GNC_DATE_P_H__
|
||||
#define __GNC_DATE_P_H__
|
||||
|
||||
#include "gnc-date.h"
|
||||
|
||||
/** Convert a given date/time format from UTF-8 to an encoding suitable for the
|
||||
* strftime system call.
|
||||
*
|
||||
* @param utf8_format Date/time format specification in UTF-8.
|
||||
*
|
||||
* @return A newly allocated string on success, or NULL otherwise.
|
||||
*/
|
||||
gchar *qof_time_format_from_utf8(const gchar *utf8_format);
|
||||
|
||||
/** Convert a result of a call to strftime back to UTF-8.
|
||||
*
|
||||
* @param locale_string The result of a call to strftime.
|
||||
*
|
||||
* @return A newly allocated string on success, or NULL otherwise.
|
||||
*/
|
||||
gchar *qof_formatted_time_to_utf8(const gchar *locale_string);
|
||||
|
||||
#endif /* __GNC_DATE_P_H__ */
|
||||
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* qof-win32.c
|
||||
*
|
||||
* Copyright (C) 2007 Andreas Koehler <andi5.py@gmx.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of version 2 of the GNU General Public
|
||||
* License as published by the Free Software Foundation.
|
||||
*
|
||||
* 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, contact:
|
||||
*
|
||||
* Free Software Foundation Voice: +1-617-542-5942
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include "gnc-date-p.h"
|
||||
#include <windows.h>
|
||||
|
||||
gchar *
|
||||
qof_time_format_from_utf8(const gchar *utf8_format)
|
||||
{
|
||||
gunichar2 *utf16_format;
|
||||
gchar *retval;
|
||||
gsize count;
|
||||
|
||||
utf16_format = g_utf8_to_utf16(utf8_format, -1, NULL, NULL, NULL);
|
||||
if (!utf16_format)
|
||||
return NULL;
|
||||
|
||||
/* get number of resulting wide characters */
|
||||
count = wcstombs(NULL, utf16_format, 0);
|
||||
if (count <= 0)
|
||||
return NULL;
|
||||
|
||||
/* malloc and convert */
|
||||
retval = g_malloc((count+1) * sizeof(gchar));
|
||||
count = wcstombs(retval, utf16_format, count+1);
|
||||
g_free(utf16_format);
|
||||
if (count <= 0) {
|
||||
g_free(retval);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
gchar *
|
||||
qof_formatted_time_to_utf8(const gchar *locale_string)
|
||||
{
|
||||
gunichar2 *utf16_string;
|
||||
gchar *retval;
|
||||
gsize count;
|
||||
|
||||
/* get number of resulting wide characters */
|
||||
count = mbstowcs(NULL, locale_string, 0);
|
||||
if (count <= 0)
|
||||
return NULL;
|
||||
|
||||
/* malloc and convert */
|
||||
utf16_string = g_malloc((count+1) * sizeof(gunichar2));
|
||||
count = mbstowcs(utf16_string, locale_string, count+1);
|
||||
if (count <= 0) {
|
||||
g_free(utf16_string);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
retval = g_utf16_to_utf8(utf16_string, -1, NULL, NULL, NULL);
|
||||
g_free(utf16_string);
|
||||
|
||||
return retval;
|
||||
}
|
||||
Loading…
Reference in new issue