aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-02-24 21:39:45 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2015-02-24 21:39:45 +0100
commit9f8af6c27b629d9ecd866ea7a1af6c2f86cfaf6c (patch)
tree9ebd4b17bdc76c60b51daf351711250b381fd893
parent1ef34fbb92ae25b86ed5c79922309aef97f640a5 (diff)
downloadtdv-9f8af6c27b629d9ecd866ea7a1af6c2f86cfaf6c.tar.gz
tdv-9f8af6c27b629d9ecd866ea7a1af6c2f86cfaf6c.tar.xz
tdv-9f8af6c27b629d9ecd866ea7a1af6c2f86cfaf6c.zip
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*
-rw-r--r--src/stardict.c28
1 files changed, 28 insertions, 0 deletions
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 <glib/gi18n.h>
#include <unicode/ucol.h>
+#include <unicode/ustring.h>
#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. */