@@ -1690,12 +1690,18 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
1690
1690
char * message = NULL ;
1691
1691
U32 this_flag_bit = 0 ;
1692
1692
1693
- /* Each 'if' clause handles one problem. They are ordered so that
1694
- * the first ones' messages will be displayed before the later
1695
- * ones; this is kinda in decreasing severity order. But the
1696
- * overlong must come last, as it changes 'uv' looked at by the
1697
- * others */
1698
- if (possible_problems & UTF8_GOT_OVERFLOW ) {
1693
+ /* Each 'case' handles one problem given by a bit in
1694
+ * 'possible_problems'. The lowest bit positions, as #defined in
1695
+ * utf8.h, are are handled first. Some of the ordering is
1696
+ * important so that higher priority items are done before lower
1697
+ * ones; some of which may depend on earlier actions. Also the
1698
+ * ordering tries to cause any messages to be displayed in kind of
1699
+ * decreasing severity order. But the overlong must come last, as
1700
+ * it changes 'uv' looked at by the others */
1701
+
1702
+ U32 this_problem = 1U << lsbit_pos32 (possible_problems );
1703
+ switch (this_problem ) {
1704
+ case UTF8_GOT_OVERFLOW :
1699
1705
1700
1706
/* Overflow means also got a super and are using Perl's
1701
1707
* extended UTF-8, but we handle all three cases here */
@@ -1747,8 +1753,10 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
1747
1753
}
1748
1754
}
1749
1755
}
1750
- }
1751
- else if (possible_problems & UTF8_GOT_EMPTY ) {
1756
+
1757
+ break ;
1758
+
1759
+ case UTF8_GOT_EMPTY :
1752
1760
possible_problems &= ~UTF8_GOT_EMPTY ;
1753
1761
* errors |= UTF8_GOT_EMPTY ;
1754
1762
@@ -1769,8 +1777,10 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
1769
1777
this_flag_bit = UTF8_GOT_EMPTY ;
1770
1778
}
1771
1779
}
1772
- }
1773
- else if (possible_problems & UTF8_GOT_CONTINUATION ) {
1780
+
1781
+ break ;
1782
+
1783
+ case UTF8_GOT_CONTINUATION :
1774
1784
possible_problems &= ~UTF8_GOT_CONTINUATION ;
1775
1785
* errors |= UTF8_GOT_CONTINUATION ;
1776
1786
@@ -1788,8 +1798,10 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
1788
1798
this_flag_bit = UTF8_GOT_CONTINUATION ;
1789
1799
}
1790
1800
}
1791
- }
1792
- else if (possible_problems & UTF8_GOT_SHORT ) {
1801
+
1802
+ break ;
1803
+
1804
+ case UTF8_GOT_SHORT :
1793
1805
possible_problems &= ~UTF8_GOT_SHORT ;
1794
1806
* errors |= UTF8_GOT_SHORT ;
1795
1807
@@ -1810,8 +1822,9 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
1810
1822
}
1811
1823
}
1812
1824
1813
- }
1814
- else if (possible_problems & UTF8_GOT_NON_CONTINUATION ) {
1825
+ break ;
1826
+
1827
+ case UTF8_GOT_NON_CONTINUATION :
1815
1828
possible_problems &= ~UTF8_GOT_NON_CONTINUATION ;
1816
1829
* errors |= UTF8_GOT_NON_CONTINUATION ;
1817
1830
@@ -1836,8 +1849,10 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
1836
1849
this_flag_bit = UTF8_GOT_NON_CONTINUATION ;
1837
1850
}
1838
1851
}
1839
- }
1840
- else if (possible_problems & UTF8_GOT_SURROGATE ) {
1852
+
1853
+ break ;
1854
+
1855
+ case UTF8_GOT_SURROGATE :
1841
1856
possible_problems &= ~UTF8_GOT_SURROGATE ;
1842
1857
1843
1858
if (flags & UTF8_WARN_SURROGATE ) {
@@ -1867,8 +1882,10 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
1867
1882
disallowed = TRUE;
1868
1883
* errors |= UTF8_GOT_SURROGATE ;
1869
1884
}
1870
- }
1871
- else if (possible_problems & UTF8_GOT_SUPER ) {
1885
+
1886
+ break ;
1887
+
1888
+ case UTF8_GOT_SUPER :
1872
1889
possible_problems &= ~UTF8_GOT_SUPER ;
1873
1890
1874
1891
if (flags & UTF8_WARN_SUPER ) {
@@ -1942,8 +1959,10 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
1942
1959
* errors |= UTF8_GOT_SUPER ;
1943
1960
disallowed = TRUE;
1944
1961
}
1945
- }
1946
- else if (possible_problems & UTF8_GOT_NONCHAR ) {
1962
+
1963
+ break ;
1964
+
1965
+ case UTF8_GOT_NONCHAR :
1947
1966
possible_problems &= ~UTF8_GOT_NONCHAR ;
1948
1967
1949
1968
if (flags & UTF8_WARN_NONCHAR ) {
@@ -1967,8 +1986,10 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
1967
1986
disallowed = TRUE;
1968
1987
* errors |= UTF8_GOT_NONCHAR ;
1969
1988
}
1970
- }
1971
- else if (possible_problems & UTF8_GOT_LONG ) {
1989
+
1990
+ break ;
1991
+
1992
+ case UTF8_GOT_LONG :
1972
1993
possible_problems &= ~UTF8_GOT_LONG ;
1973
1994
* errors |= UTF8_GOT_LONG ;
1974
1995
@@ -2033,7 +2054,15 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
2033
2054
this_flag_bit = UTF8_GOT_LONG ;
2034
2055
}
2035
2056
}
2036
- } /* End of looking through the possible flags */
2057
+
2058
+ break ;
2059
+
2060
+ default :
2061
+ Perl_croak (aTHX_ "panic: Unexpected case value in "
2062
+ " utf8n_to_uvchr_msgs() %d" , this_problem );
2063
+ /* NOTREACHED */
2064
+
2065
+ } /* End of switch() on the possible problems */
2037
2066
2038
2067
/* Display the message (if any) for the problem being handled in
2039
2068
* this iteration of the loop */
0 commit comments