This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
locale.c: Simplify code in Perl_langinfo()
authorKarl Williamson <khw@cpan.org>
Fri, 10 Nov 2017 02:23:13 +0000 (19:23 -0700)
committerKarl Williamson <khw@cpan.org>
Sat, 11 Nov 2017 05:57:09 +0000 (22:57 -0700)
Instead of a switch() statement we can use 'foo ? bar : baz;'

locale.c

index 436456a..5bc5fc5 100644 (file)
--- a/locale.c
+++ b/locale.c
@@ -1408,29 +1408,13 @@ S_my_nl_langinfo(const int item, bool toggle)
             if (! lc) {
                 retval = "";
             }
-            else switch (item) {
-                case PERL_RADIXCHAR:
-                    if (! lc->decimal_point) {
-                        retval = "";
-                    }
-                    else {
-                        retval = lc->decimal_point;
-                    }
-                    break;
-
-                case PERL_THOUSEP:
-                    if (! lc->thousands_sep || strEQ("", lc->thousands_sep)) {
-                        retval = "";
-                    }
-                    else {
-                        retval = lc->thousands_sep;
-                    }
-                    break;
-
-                default:
-                    LOCALE_UNLOCK;
-                    Perl_croak(aTHX_ "panic: %s: %d: switch case: %d problem",
-                                            __FILE__, __LINE__, item);
+            else {
+                retval = (item == PERL_RADIXCHAR)
+                         ? lc->decimal_point
+                         : lc->thousands_sep;
+                if (! retval) {
+                    retval = "";
+                }
             }
 
             save_to_buffer(retval, &PL_langinfo_buf, &PL_langinfo_bufsize, 0);