From fc1448456bd429de98e3c5a854430af2555b9a07 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tim=20R=C3=BChsen?= <tim.ruehsen@gmx.de>
Date: Wed, 9 Jan 2019 16:59:54 +0100
Subject: [PATCH] Remove overhead from error.c, add missing TR46 values

---
 lib/error.c | 279 +++++++++++++-----------------------------------------------
 1 file changed, 57 insertions(+), 222 deletions(-)

diff --git a/lib/error.c b/lib/error.c
index 9ab4fb1..0304044 100644
--- a/lib/error.c
+++ b/lib/error.c
@@ -46,114 +46,39 @@
 const char *
 idn2_strerror (int rc)
 {
-  const char *p;
-
   bindtextdomain (PACKAGE, LOCALEDIR);
 
   switch (rc)
     {
-    case IDN2_OK:
-      p = _("success");
-      break;
-
-    case IDN2_MALLOC:
-      p = _("out of memory");
-      break;
-
-    case IDN2_NO_CODESET:
-      p = _("could not determine locale encoding format");
-      break;
-
-    case IDN2_ICONV_FAIL:
-      p = _("could not convert string to UTF-8");
-      break;
-
-    case IDN2_ENCODING_ERROR:
-      p = _("string encoding error");
-      break;
-
-    case IDN2_NFC:
-      p = _("string could not be NFC normalized");
-      break;
-
-    case IDN2_PUNYCODE_BAD_INPUT:
-      p = _("string contains invalid punycode data");
-      break;
-
-    case IDN2_PUNYCODE_BIG_OUTPUT:
-      p = _("punycode encoded data will be too large");
-      break;
-
-    case IDN2_PUNYCODE_OVERFLOW:
-      p = _("punycode conversion resulted in overflow");
-      break;
-
-    case IDN2_TOO_BIG_DOMAIN:
-      p = _("domain name longer than 255 characters");
-      break;
-
-    case IDN2_TOO_BIG_LABEL:
-      p = _("domain label longer than 63 characters");
-      break;
-
-    case IDN2_INVALID_ALABEL:
-      p = _("input A-label is not valid");
-      break;
-
-    case IDN2_UALABEL_MISMATCH:
-      p = _("input A-label and U-label does not match");
-      break;
-
-    case IDN2_NOT_NFC:
-      p = _("string is not in Unicode NFC format");
-      break;
-
-    case IDN2_2HYPHEN:
-      p = _("string contains forbidden two hyphens pattern");
-      break;
-
-    case IDN2_HYPHEN_STARTEND:
-      p = _("string start/ends with forbidden hyphen");
-      break;
-
-    case IDN2_LEADING_COMBINING:
-      p = _("string contains a forbidden leading combining character");
-      break;
-
-    case IDN2_DISALLOWED:
-      p = _("string contains a disallowed character");
-      break;
-
-    case IDN2_CONTEXTJ:
-      p = _("string contains a forbidden context-j character");
-      break;
-
-    case IDN2_CONTEXTJ_NO_RULE:
-      p = _("string contains a context-j character with null rule");
-      break;
-
-    case IDN2_CONTEXTO:
-      p = _("string contains a forbidden context-o character");
-      break;
-
-    case IDN2_CONTEXTO_NO_RULE:
-      p = _("string contains a context-o character with null rule");
-      break;
-
-    case IDN2_UNASSIGNED:
-      p = _("string contains unassigned code point");
-      break;
-
-    case IDN2_BIDI:
-      p = _("string has forbidden bi-directional properties");
-      break;
-
-    default:
-      p = _("Unknown error");
-      break;
+    case IDN2_OK: return _("success");
+    case IDN2_MALLOC: return _("out of memory");
+    case IDN2_NO_CODESET: return _("could not determine locale encoding format");
+    case IDN2_ICONV_FAIL: return _("could not convert string to UTF-8");
+    case IDN2_ENCODING_ERROR: return _("string encoding error");
+    case IDN2_NFC: return _("string could not be NFC normalized");
+    case IDN2_PUNYCODE_BAD_INPUT: return _("string contains invalid punycode data");
+    case IDN2_PUNYCODE_BIG_OUTPUT: return _("punycode encoded data will be too large");
+    case IDN2_PUNYCODE_OVERFLOW: return _("punycode conversion resulted in overflow");
+    case IDN2_TOO_BIG_DOMAIN: return _("domain name longer than 255 characters");
+    case IDN2_TOO_BIG_LABEL: return _("domain label longer than 63 characters");
+    case IDN2_INVALID_ALABEL: return _("input A-label is not valid");
+    case IDN2_UALABEL_MISMATCH: return _("input A-label and U-label does not match");
+    case IDN2_NOT_NFC: return _("string is not in Unicode NFC format");
+    case IDN2_2HYPHEN: return _("string contains forbidden two hyphens pattern");
+    case IDN2_HYPHEN_STARTEND: return _("string start/ends with forbidden hyphen");
+    case IDN2_LEADING_COMBINING: return _("string contains a forbidden leading combining character");
+    case IDN2_DISALLOWED: return _("string contains a disallowed character");
+    case IDN2_CONTEXTJ: return _("string contains a forbidden context-j character");
+    case IDN2_CONTEXTJ_NO_RULE: return _("string contains a context-j character with null rule");
+    case IDN2_CONTEXTO: return _("string contains a forbidden context-o character");
+    case IDN2_CONTEXTO_NO_RULE: return _("string contains a context-o character with null rule");
+    case IDN2_UNASSIGNED: return _("string contains unassigned code point");
+    case IDN2_BIDI: return _("string has forbidden bi-directional properties");
+    case IDN2_DOT_IN_LABEL: return _("domain label has forbidden dot (TR46)");
+    case IDN2_INVALID_TRANSITIONAL: return _("domain label has character forbidden in transitional mode (TR46)");
+    case IDN2_INVALID_NONTRANSITIONAL: return _("domain label has character forbidden in non-transitional mode (TR46)");
+    default: return _("Unknown error");
     }
-
-  return p;
 }
 
 #define ERR2STR(name) #name
@@ -174,126 +99,36 @@ idn2_strerror (int rc)
 const char *
 idn2_strerror_name (int rc)
 {
-  const char *p;
-
   switch (rc)
     {
-    case IDN2_OK:
-      p = ERR2STR (IDN2_OK);
-      break;
-
-    case IDN2_MALLOC:
-      p = ERR2STR (IDN2_MALLOC);
-      break;
-
-    case IDN2_NO_CODESET:
-      p = ERR2STR (IDN2_NO_NODESET);
-      break;
-
-    case IDN2_ICONV_FAIL:
-      p = ERR2STR (IDN2_ICONV_FAIL);
-      break;
-
-    case IDN2_ENCODING_ERROR:
-      p = ERR2STR (IDN2_ENCODING_ERROR);
-      break;
-
-    case IDN2_NFC:
-      p = ERR2STR (IDN2_NFC);
-      break;
-
-    case IDN2_PUNYCODE_BAD_INPUT:
-      p = ERR2STR (IDN2_PUNYCODE_BAD_INPUT);
-      break;
-
-    case IDN2_PUNYCODE_BIG_OUTPUT:
-      p = ERR2STR (IDN2_PUNYCODE_BIG_OUTPUT);
-      break;
-
-    case IDN2_PUNYCODE_OVERFLOW:
-      p = ERR2STR (IDN2_PUNYCODE_OVERFLOW);
-      break;
-
-    case IDN2_TOO_BIG_DOMAIN:
-      p = ERR2STR (IDN2_TOO_BIG_DOMAIN);
-      break;
-
-    case IDN2_TOO_BIG_LABEL:
-      p = ERR2STR (IDN2_TOO_BIG_LABEL);
-      break;
-
-    case IDN2_INVALID_ALABEL:
-      p = ERR2STR (IDN2_INVALID_ALABEL);
-      break;
-
-    case IDN2_UALABEL_MISMATCH:
-      p = ERR2STR (IDN2_UALABEL_MISMATCH);
-      break;
-
-    case IDN2_INVALID_FLAGS:
-      p = ERR2STR (IDN2_INVALID_FLAGS);
-      break;
-
-    case IDN2_NOT_NFC:
-      p = ERR2STR (IDN2_NOT_NFC);
-      break;
-
-  case IDN2_2HYPHEN:
-      p = ERR2STR (IDN2_2HYPHEN);
-      break;
-
-    case IDN2_HYPHEN_STARTEND:
-      p = ERR2STR (IDN2_HYPHEN_STARTEND);
-      break;
-
-    case IDN2_LEADING_COMBINING:
-      p = ERR2STR (IDN2_LEADING_COMBINING);
-      break;
-
-    case IDN2_DISALLOWED:
-      p = ERR2STR (IDN2_DISALLOWED);
-      break;
-
-    case IDN2_CONTEXTJ:
-      p = ERR2STR (IDN2_CONTEXTJ);
-      break;
-
-    case IDN2_CONTEXTJ_NO_RULE:
-      p = ERR2STR (IDN2_CONTEXTJ_NO_RULE);
-      break;
-
-    case IDN2_CONTEXTO:
-      p = ERR2STR (IDN2_CONTEXTO);
-      break;
-
-    case IDN2_CONTEXTO_NO_RULE:
-      p = ERR2STR (IDN2_CONTEXTO_NO_RULE);
-      break;
-
-    case IDN2_UNASSIGNED:
-      p = ERR2STR (IDN2_UNASSIGNED);
-      break;
-
-    case IDN2_BIDI:
-      p = ERR2STR (IDN2_BIDI);
-      break;
-
-    case IDN2_DOT_IN_LABEL:
-      p = ERR2STR (IDN2_DOT_IN_LABEL);
-      break;
-
-    case IDN2_INVALID_TRANSITIONAL:
-      p = ERR2STR (IDN2_INVALID_TRANSITIONAL);
-      break;
-
-    case IDN2_INVALID_NONTRANSITIONAL:
-      p = ERR2STR (IDN2_INVALID_NONTRANSITIONAL);
-      break;
-
-    default:
-      p = "IDN2_UNKNOWN";
-      break;
+    case IDN2_OK: return ERR2STR (IDN2_OK);
+    case IDN2_MALLOC: return ERR2STR (IDN2_MALLOC);
+    case IDN2_NO_CODESET:  return ERR2STR (IDN2_NO_NODESET);
+    case IDN2_ICONV_FAIL:  return  ERR2STR (IDN2_ICONV_FAIL);
+    case IDN2_ENCODING_ERROR: return ERR2STR (IDN2_ENCODING_ERROR);
+    case IDN2_NFC: return ERR2STR (IDN2_NFC);
+    case IDN2_PUNYCODE_BAD_INPUT: return ERR2STR (IDN2_PUNYCODE_BAD_INPUT);
+    case IDN2_PUNYCODE_BIG_OUTPUT: return ERR2STR (IDN2_PUNYCODE_BIG_OUTPUT);
+    case IDN2_PUNYCODE_OVERFLOW: return ERR2STR (IDN2_PUNYCODE_OVERFLOW);
+    case IDN2_TOO_BIG_DOMAIN: return ERR2STR (IDN2_TOO_BIG_DOMAIN);
+    case IDN2_TOO_BIG_LABEL: return ERR2STR (IDN2_TOO_BIG_LABEL);
+    case IDN2_INVALID_ALABEL: return ERR2STR (IDN2_INVALID_ALABEL);
+    case IDN2_UALABEL_MISMATCH: return ERR2STR (IDN2_UALABEL_MISMATCH);
+    case IDN2_INVALID_FLAGS: return ERR2STR (IDN2_INVALID_FLAGS);
+    case IDN2_NOT_NFC: return ERR2STR (IDN2_NOT_NFC);
+    case IDN2_2HYPHEN: return ERR2STR (IDN2_2HYPHEN);
+    case IDN2_HYPHEN_STARTEND: return ERR2STR (IDN2_HYPHEN_STARTEND);
+    case IDN2_LEADING_COMBINING: return ERR2STR (IDN2_LEADING_COMBINING);
+    case IDN2_DISALLOWED: return ERR2STR (IDN2_DISALLOWED);
+    case IDN2_CONTEXTJ: return ERR2STR (IDN2_CONTEXTJ);
+    case IDN2_CONTEXTJ_NO_RULE: return ERR2STR (IDN2_CONTEXTJ_NO_RULE);
+    case IDN2_CONTEXTO: return ERR2STR (IDN2_CONTEXTO);
+    case IDN2_CONTEXTO_NO_RULE: return ERR2STR (IDN2_CONTEXTO_NO_RULE);
+    case IDN2_UNASSIGNED: return ERR2STR (IDN2_UNASSIGNED);
+    case IDN2_BIDI: return ERR2STR (IDN2_BIDI);
+    case IDN2_DOT_IN_LABEL: return ERR2STR (IDN2_DOT_IN_LABEL);
+    case IDN2_INVALID_TRANSITIONAL: return ERR2STR (IDN2_INVALID_TRANSITIONAL);
+    case IDN2_INVALID_NONTRANSITIONAL: return ERR2STR (IDN2_INVALID_NONTRANSITIONAL);
+    default: return "IDN2_UNKNOWN";
     }
-
-  return p;
 }
-- 
1.8.3.1

