--- a/zrus.c Wed Aug 29 00:19:14 2007 +0200
+++ b/zrus.c Sat Sep 01 00:50:11 2007 +0200
@@ -1,4 +1,7 @@
#include <stdio.h>
+#include <unicode/uchar.h>
+#include <unicode/ustring.h>
+#include <unicode/utypes.h>
#include "dictre.h"
static int closed_accent(const unsigned char *tmp)
@@ -146,3 +149,99 @@
return -1;
}
+
+int get_case(enum Case *vcase, const char *str)
+{
+ UChar32 c;
+ int i;
+ int o;
+ int len;
+
+ len = strlen(str);
+
+ i=0;
+ o=0;
+ do
+ {
+ U8_NEXT(str, i, len, c);
+ /*printf("[%i] ", c);*/
+ if (c == 0)
+ break;
+ if (u_islower(c))
+ vcase[o] = LCASE;
+ else
+ vcase[o] = UCASE;
+ ++o;
+ } while(1);
+
+ return o;
+}
+
+void get_lowcase_str(char *out, const char *str)
+{
+ UChar32 c;
+ int i;
+ int o;
+ int len;
+ char iserror = 0;
+
+ len = strlen(str);
+
+ i=0;
+ o=0;
+ do
+ {
+ U8_NEXT(str, i, len, c);
+ /*printf("[%i] ", c);*/
+ c = u_tolower(c);
+ U8_APPEND(out, o, MAXWORD, c, iserror);
+ if (iserror)
+ break;
+ if (c == 0)
+ break;
+ } while(1);
+}
+
+void reapply_case(char *out, const char *in, const enum Case *vcase)
+{
+ UChar32 c;
+ int i;
+ int o;
+ int vcasepos;
+ int len;
+ char iserror = 0;
+ const UChar32 inverted = '`';
+
+ len = strlen(in);
+
+ i=0;
+ o=0;
+ vcasepos = 0;
+ do
+ {
+ U8_NEXT(in, i, len, c);
+ /*printf("[%i] ", c);*/
+ if (c == inverted || u_hasBinaryProperty(c, UCHAR_DIACRITIC))
+ {
+ U8_APPEND(out, o, MAXWORD, c, iserror);
+ /* Here we don't increment vcasepos,
+ * so the ` or diacritics gets copied without being taken
+ * care in the recase process. It will
+ * be the only sign that may be _added_ */
+ continue;
+ }
+
+ if (vcase[vcasepos] == LCASE)
+ c = u_tolower(c);
+ else
+ c = u_toupper(c);
+ vcasepos += 1;
+
+ U8_APPEND(out, o, MAXWORD, c, iserror);
+
+ if (iserror)
+ break;
+ if (c == 0)
+ break;
+ } while(1);
+}