Finish Latin-1 to MARC-8 conversion handling.
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 9 May 2006 21:37:02 +0000 (21:37 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 9 May 2006 21:37:02 +0000 (21:37 +0000)
src/siconv.c
test/tsticonv.c

index bee184b..7b2bf0f 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2006, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: siconv.c,v 1.22 2006-04-24 23:21:26 adam Exp $
+ * $Id: siconv.c,v 1.23 2006-05-09 21:37:02 adam Exp $
  */
 /**
  * \file siconv.c
@@ -785,9 +785,9 @@ static size_t flush_combos(yaz_iconv_t cd,
     return 0;
 }
 
-static size_t yaz_write_marc8(yaz_iconv_t cd, unsigned long x,
-                              char **outbuf, size_t *outbytesleft,
-                              int last)
+static size_t yaz_write_marc8_2(yaz_iconv_t cd, unsigned long x,
+                                char **outbuf, size_t *outbytesleft,
+                                int last)
 {
     int comb = 0;
     const char *page_chr = 0;
@@ -837,6 +837,41 @@ static size_t yaz_write_marc8(yaz_iconv_t cd, unsigned long x,
     return 0;
 }
 
+static size_t yaz_write_marc8(yaz_iconv_t cd, unsigned long x,
+                              char **outbuf, size_t *outbytesleft,
+                              int last)
+{
+    int i;
+    for (i = 0; latin1_comb[i].x1; i++)
+    {
+        if (x == latin1_comb[i].y)
+        {
+            size_t r ;
+            /* save the output pointers .. */
+            char *outbuf0 = *outbuf;
+            size_t outbytesleft0 = *outbytesleft;
+            int last_ch = cd->write_marc8_last;
+
+            r = yaz_write_marc8_2(cd, latin1_comb[i].x1,
+                                  outbuf, outbytesleft, 0);
+            if (r)
+                return r;
+            r = yaz_write_marc8_2(cd, latin1_comb[i].x2,
+                                  outbuf, outbytesleft, last);
+            if (r && cd->my_errno == YAZ_ICONV_E2BIG)
+            {
+                /* not enough room. reset output to original values */
+                *outbuf = outbuf0;
+                *outbytesleft = outbytesleft0;
+                cd->write_marc8_last = last_ch;
+            }
+            return r;
+        }
+    }
+    return yaz_write_marc8_2(cd, x, outbuf, outbytesleft, last);
+}
+
+
 #if HAVE_WCHAR_H
 static size_t yaz_write_wchar_t (yaz_iconv_t cd, unsigned long x,
                                  char **outbuf, size_t *outbytesleft,
index 55cd9d1..b376aad 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2006, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: tsticonv.c,v 1.19 2006-05-03 13:01:04 adam Exp $
+ * $Id: tsticonv.c,v 1.20 2006-05-09 21:37:03 adam Exp $
  */
 
 #if HAVE_CONFIG_H
@@ -483,13 +483,18 @@ static void tst_latin1_to_marc8()
     /** D8: UPPERCASE SCANDINAVIAN O */
     YAZ_CHECK(tst_convert(cd, "S\xd8", "S\xa2"));
 
-#if 0
-    /* does not pass yet */
     /** E9: LATIN SMALL LETTER E WITH ACUTE */
-    YAZ_CHECK(tst_convert(cd,
-                          "Cours de math\xe9",
-                          "Cours de mathâe"));
-#endif         
+    YAZ_CHECK(tst_convert(cd, "Cours de math\xe9", "Cours de mathâe"));
+    YAZ_CHECK(tst_convert(cd, "Cours de math", "Cours de math"
+                  ));
+    YAZ_CHECK(tst_convert(cd, "Cours de mathé", "Cours de mathâe" ));
+    YAZ_CHECK(tst_convert(cd, "12345678é","12345678âe"));
+    YAZ_CHECK(tst_convert(cd, "123456789é", "123456789âe"));
+    YAZ_CHECK(tst_convert(cd, "1234567890é","1234567890âe"));
+    YAZ_CHECK(tst_convert(cd, "12345678901é", "12345678901âe"));
+    YAZ_CHECK(tst_convert(cd, "Cours de mathém", "Cours de mathâem"));
+    YAZ_CHECK(tst_convert(cd, "Cours de mathématiques",
+                          "Cours de mathâematiques"));
     yaz_iconv_close(cd);
 }