* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
+#include <config.h>
#include <stdio.h>
#include <glib.h>
#include <unicode-data.h>
#include <errno.h>
-#ifdef _MSC_VER
-/* FIXME */
-#define CODESET 1
-#include <Windows.h>
-typedef int iconv_t;
+#if defined(_MSC_VER) || defined(G_OS_WIN32)
+/* FIXME */
+# define CODESET 1
+# include <windows.h>
#else
-#include <langinfo.h>
-#include <iconv.h>
+# ifdef HAVE_LANGINFO_H
+# include <langinfo.h>
+# endif
+# ifdef HAVE_LOCALCHARSET_H
+# include <localcharset.h>
+# endif
#endif
static char *my_charset;
GUnicodeType
g_unichar_type (gunichar c)
{
-int i;
+ int i;
guint16 cp = (guint16) c;
for (i = 0; i < unicode_category_ranges_count; i++) {
return 0;
}
+GUnicodeBreakType
+g_unichar_break_type (gunichar c)
+{
+ // MOONLIGHT_FIXME
+ return G_UNICODE_BREAK_UNKNOWN;
+}
+
gunichar
g_unichar_case (gunichar c, gboolean upper)
{
return -1;
}
+gboolean
+g_unichar_isspace (gunichar c)
+{
+ GUnicodeType type = g_unichar_type (c);
+ if (type == G_UNICODE_LINE_SEPARATOR ||
+ type == G_UNICODE_PARAGRAPH_SEPARATOR ||
+ type == G_UNICODE_SPACE_SEPARATOR)
+ return TRUE;
+
+ return FALSE;
+}
+
gchar *
g_convert (const gchar *str, gssize len,
const gchar *to_codeset, const gchar *from_codeset,
gsize *bytes_read, gsize *bytes_written, GError **error)
{
- char *result = NULL;
-#ifdef G_OS_WIN32
-#else
- iconv_t convertor;
- char *buffer, *output;
- const char *strptr = (const char *) str;
size_t str_len = len == -1 ? strlen (str) : len;
- size_t buffer_size;
- size_t left, out_left;
+ const char *strptr = (const char *) str;
+ size_t left, out_left, buffer_size;
+ char *buffer, *output;
+ char *result = NULL;
+ GIConv cd;
- convertor = iconv_open (to_codeset, from_codeset);
- if (convertor == (iconv_t) -1){
- *bytes_written = 0;
- *bytes_read = 0;
+ if ((cd = g_iconv_open (to_codeset, from_codeset)) == (GIConv) -1) {
+ if (bytes_written)
+ *bytes_written = 0;
+ if (bytes_read)
+ *bytes_read = 0;
return NULL;
}
-
+
buffer_size = str_len + 1 + 8;
buffer = g_malloc (buffer_size);
out_left = str_len;
output = buffer;
left = str_len;
+
while (left > 0){
- int res = iconv (convertor, (char **) &strptr, &left, &output, &out_left);
+ int res = g_iconv (cd, (char **) &strptr, &left, &output, &out_left);
if (res == (size_t) -1){
if (errno == E2BIG){
char *n;
*output = 0;
result = buffer;
leave:
- iconv_close (convertor);
-#endif
+ g_iconv_close (cd);
+
return result;
}
gboolean
g_get_charset (G_CONST_RETURN char **charset)
{
+ if (my_charset == NULL) {
#ifdef G_OS_WIN32
- static char buf[14];
- sprintf (buf, "CP%u", GetACP ());
- *charset = buf;
- is_utf8 = FALSE;
+ static char buf [14];
+ sprintf (buf, "CP%u", GetACP ());
+ my_charset = buf;
+ is_utf8 = FALSE;
+#else
+ /* These shouldn't be heap allocated */
+#if HAVE_LOCALCHARSET_H
+ my_charset = locale_charset ();
+#elif defined(HAVE_LANGINFO_H)
+ my_charset = nl_langinfo (CODESET);
#else
- if (my_charset == NULL){
- my_charset = g_strdup (nl_langinfo (CODESET));
+ my_charset = "UTF-8";
+#endif
is_utf8 = strcmp (my_charset, "UTF-8") == 0;
+#endif
}
if (charset != NULL)
*charset = my_charset;
-#endif
return is_utf8;
}