From 9f8af6c27b629d9ecd866ea7a1af6c2f86cfaf6c Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Tue, 24 Feb 2015 21:39:45 +0100
Subject: Fix build with ICU versions < 50
I'll try to describe my feelings with this excerpt from
David Firth's video "Take This Pill":
PAIN.
*oooowww...*
Hurts, doesn't it?
*...wwwwwww*
---
src/stardict.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/src/stardict.c b/src/stardict.c
index 00659e4..b1eb96f 100644
--- a/src/stardict.c
+++ b/src/stardict.c
@@ -28,12 +28,17 @@
#include
#include
+#include
#include "stardict.h"
#include "stardict-private.h"
#include "dictzip-input-stream.h"
#include "utils.h"
+#if ! GLIB_CHECK_VERSION (2, 40, 0)
+#define g_info g_debug
+#endif
+
// --- Utilities ---------------------------------------------------------------
@@ -668,7 +673,30 @@ stardict_dict_strcoll (gconstpointer s1, gconstpointer s2, gpointer data)
{
StardictDict *sd = data;
UErrorCode error = U_ZERO_ERROR;
+
+#if U_ICU_VERSION_MAJOR_NUM >= 50
return ucol_strcollUTF8 (sd->priv->collator, s1, -1, s2, -1, &error);
+#else // U_ICU_VERSION_MAJOR_NUM >= 50
+ // This remarkably retarded API absolutely reeks of corporate;
+ // I don't have to tell you that this code runs slow, do I?
+
+ int32_t uc1_len = 0;
+ int32_t uc2_len = 0;
+
+ error = U_ZERO_ERROR;
+ u_strFromUTF8WithSub (NULL, 0, &uc1_len, s1, -1, 0xFFFD, NULL, &error);
+ error = U_ZERO_ERROR;
+ u_strFromUTF8WithSub (NULL, 0, &uc2_len, s2, -1, 0xFFFD, NULL, &error);
+
+ UChar uc1[uc1_len];
+ UChar uc2[uc2_len];
+ error = U_ZERO_ERROR;
+ u_strFromUTF8WithSub (uc1, uc1_len, NULL, s1, -1, 0xFFFD, NULL, &error);
+ error = U_ZERO_ERROR;
+ u_strFromUTF8WithSub (uc2, uc2_len, NULL, s2, -1, 0xFFFD, NULL, &error);
+
+ return ucol_strcoll (sd->priv->collator, uc1, uc1_len, uc2, uc2_len);
+#endif // U_ICU_VERSION_MAJOR_NUM >= 50
}
/** Stricter stardict_dict_strcoll() used to sort the collated index. */
--
cgit v1.2.3-70-g09d2