]> Savannah Git Hosting - gnulib.git/commitdiff
unilbrk: Fix bugs in implementation of Unicode rules (LB15a), (LB15b).
authorBruno Haible <bruno@clisp.org>
Sun, 15 Sep 2024 10:59:46 +0000 (12:59 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 15 Sep 2024 10:59:46 +0000 (12:59 +0200)
* lib/gen-uni-tables.c (output_lbrk_rules_as_tables): Fix typo in
comment.
* lib/unilbrk/u8-possible-linebreaks.c (u8_possible_linebreaks_loop):
Do the LBP_QU2 to LBP_QU1 mapping for (LB15a) after the table lookup but
before the assignment to last_prop. Do the LBP_QU3 to LBP_QU1 mapping
for (LB15b) in a way that does not influence prev_prop or last_prop.
* lib/unilbrk/u16-possible-linebreaks.c (u16_possible_linebreaks_loop):
Likewise.
* lib/unilbrk/u32-possible-linebreaks.c (u32_possible_linebreaks_loop):
Likewise.

ChangeLog
lib/gen-uni-tables.c
lib/unilbrk/u16-possible-linebreaks.c
lib/unilbrk/u32-possible-linebreaks.c
lib/unilbrk/u8-possible-linebreaks.c

index fc9883023910b6fba235196bc9b284b8d06ac061..7b61ebaf3cb813a60c93cddbeff9478256b091ef 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2024-09-15  Bruno Haible  <bruno@clisp.org>
+
+       unilbrk: Fix bugs in implementation of Unicode rules (LB15a), (LB15b).
+       * lib/gen-uni-tables.c (output_lbrk_rules_as_tables): Fix typo in
+       comment.
+       * lib/unilbrk/u8-possible-linebreaks.c (u8_possible_linebreaks_loop):
+       Do the LBP_QU2 to LBP_QU1 mapping for (LB15a) after the table lookup but
+       before the assignment to last_prop. Do the LBP_QU3 to LBP_QU1 mapping
+       for (LB15b) in a way that does not influence prev_prop or last_prop.
+       * lib/unilbrk/u16-possible-linebreaks.c (u16_possible_linebreaks_loop):
+       Likewise.
+       * lib/unilbrk/u32-possible-linebreaks.c (u32_possible_linebreaks_loop):
+       Likewise.
+
 2024-09-14  Bruno Haible  <bruno@clisp.org>
 
        unilbrk: Fix bug in implementation of Unicode rule (LB16).
index 0ea9de9f2852fe81959b174efd5137fa779d33bb..6ac81d0821746813fdaafcc1d97dd4147c81391c 100644 (file)
@@ -9424,7 +9424,7 @@ output_lbrk_rules_as_tables (const char *filename, const char *version)
                        set_table_cell (prohibited_with_sp, true);
     }
 
-  /* (LB15a) Do not break before an ambiguous quotation that is an initial
+  /* (LB15a) Do not break after an ambiguous quotation that is an initial
      punctuation, even after spaces.  */
   for (after = 0; after < NLBP; after++)
     {
index e327575a344cfc1f9c1d7d8e9100ac47a36eb91b..d2d6343234873f8dc3c47fbfdf550ef1ce5fc632 100644 (file)
@@ -158,51 +158,6 @@ u16_possible_linebreaks_loop (const uint16_t *s, size_t n, const char *encoding,
                   /* This is arbitrary.  */
                   prop = LBP_AL1;
                   break;
-                case LBP_QU2:
-                  /* For (LB15a): Replace LBP_QU2 with LBP_QU1 if the previous
-                     character's line break property was not one of
-                     BK, CR, LF, OP, QU, GL, SP, ZW.  */
-                  switch (prev_prop)
-                    {
-                    case LBP_BK:
-                    case LBP_CR:
-                    case LBP_LF:
-                    case LBP_OP1: case LBP_OP2:
-                    case LBP_QU1: case LBP_QU2: case LBP_QU3:
-                    case LBP_GL:
-                    case LBP_SP:
-                    case LBP_ZW:
-                      break;
-                    default:
-                      prop = LBP_QU1;
-                      break;
-                    }
-                  break;
-                case LBP_QU3:
-                  /* For (LB15b): Replace LBP_QU3 with LBP_QU1 if the next
-                     character's line break property is not one of
-                     BK, CR, LF, SP, GL, WJ, CL, QU, CP, EX, IS, SY, ZW.  */
-                  switch (PROP (lookahead1_prop_ea))
-                    {
-                    case LBP_BK:
-                    case LBP_CR:
-                    case LBP_LF:
-                    case LBP_SP:
-                    case LBP_GL:
-                    case LBP_WJ:
-                    case LBP_CL:
-                    case LBP_QU1: case LBP_QU2: case LBP_QU3:
-                    case LBP_CP1: case LBP_CP2:
-                    case LBP_EX:
-                    case LBP_IS:
-                    case LBP_SY:
-                    case LBP_ZW:
-                      break;
-                    default:
-                      prop = LBP_QU1;
-                      break;
-                    }
-                  break;
                 }
 
               /* Deal with spaces and combining characters.  */
@@ -343,7 +298,35 @@ u16_possible_linebreaks_loop (const uint16_t *s, size_t n, const char *encoding,
                     }
                   else
                     {
-                      switch (unilbrk_table [last_prop] [prop])
+                      int this_prop = prop;
+                      if (prop == LBP_QU3)
+                        {
+                          /* For (LB15b): Replace LBP_QU3 with LBP_QU1 if the
+                             next character's line break property is not one of
+                             BK, CR, LF, SP, GL, WJ, CL, QU, CP, EX, IS, SY, ZW.  */
+                          switch (PROP (lookahead1_prop_ea))
+                            {
+                            case LBP_BK:
+                            case LBP_CR:
+                            case LBP_LF:
+                            case LBP_SP:
+                            case LBP_GL:
+                            case LBP_WJ:
+                            case LBP_CL:
+                            case LBP_QU1: case LBP_QU2: case LBP_QU3:
+                            case LBP_CP1: case LBP_CP2:
+                            case LBP_EX:
+                            case LBP_IS:
+                            case LBP_SY:
+                            case LBP_ZW:
+                              break;
+                            default:
+                              this_prop = LBP_QU1;
+                              break;
+                            }
+                        }
+
+                      switch (unilbrk_table [last_prop] [this_prop])
                         {
                         case D:
                           *p = UC_BREAK_POSSIBLE;
@@ -358,6 +341,29 @@ u16_possible_linebreaks_loop (const uint16_t *s, size_t n, const char *encoding,
                           abort ();
                         }
                     }
+
+                  if (prop == LBP_QU2)
+                    {
+                      /* For (LB15a): Replace LBP_QU2 with LBP_QU1 if the
+                         previous character's line break property was not one of
+                         BK, CR, LF, OP, QU, GL, SP, ZW.  */
+                      switch (prev_prop)
+                        {
+                        case LBP_BK:
+                        case LBP_CR:
+                        case LBP_LF:
+                        case LBP_OP1: case LBP_OP2:
+                        case LBP_QU1: case LBP_QU2: case LBP_QU3:
+                        case LBP_GL:
+                        case LBP_SP:
+                        case LBP_ZW:
+                          break;
+                        default:
+                          prop = LBP_QU1;
+                          break;
+                        }
+                    }
+
                   last_prop = prop;
                   seen_space = NULL;
                 }
index b351ece0d4d563e78547ac0b099cd45a768c06ce..10f39a8d054f4a93660b59952c7c446374352f39 100644 (file)
@@ -151,51 +151,6 @@ u32_possible_linebreaks_loop (const uint32_t *s, size_t n, const char *encoding,
                   /* This is arbitrary.  */
                   prop = LBP_AL1;
                   break;
-                case LBP_QU2:
-                  /* For (LB15a): Replace LBP_QU2 with LBP_QU1 if the previous
-                     character's line break property was not one of
-                     BK, CR, LF, OP, QU, GL, SP, ZW.  */
-                  switch (prev_prop)
-                    {
-                    case LBP_BK:
-                    case LBP_CR:
-                    case LBP_LF:
-                    case LBP_OP1: case LBP_OP2:
-                    case LBP_QU1: case LBP_QU2: case LBP_QU3:
-                    case LBP_GL:
-                    case LBP_SP:
-                    case LBP_ZW:
-                      break;
-                    default:
-                      prop = LBP_QU1;
-                      break;
-                    }
-                  break;
-                case LBP_QU3:
-                  /* For (LB15b): Replace LBP_QU3 with LBP_QU1 if the next
-                     character's line break property is not one of
-                     BK, CR, LF, SP, GL, WJ, CL, QU, CP, EX, IS, SY, ZW.  */
-                  switch (PROP (lookahead1_prop_ea))
-                    {
-                    case LBP_BK:
-                    case LBP_CR:
-                    case LBP_LF:
-                    case LBP_SP:
-                    case LBP_GL:
-                    case LBP_WJ:
-                    case LBP_CL:
-                    case LBP_QU1: case LBP_QU2: case LBP_QU3:
-                    case LBP_CP1: case LBP_CP2:
-                    case LBP_EX:
-                    case LBP_IS:
-                    case LBP_SY:
-                    case LBP_ZW:
-                      break;
-                    default:
-                      prop = LBP_QU1;
-                      break;
-                    }
-                  break;
                 }
 
               /* Deal with spaces and combining characters.  */
@@ -336,7 +291,35 @@ u32_possible_linebreaks_loop (const uint32_t *s, size_t n, const char *encoding,
                     }
                   else
                     {
-                      switch (unilbrk_table [last_prop] [prop])
+                      int this_prop = prop;
+                      if (prop == LBP_QU3)
+                        {
+                          /* For (LB15b): Replace LBP_QU3 with LBP_QU1 if the
+                             next character's line break property is not one of
+                             BK, CR, LF, SP, GL, WJ, CL, QU, CP, EX, IS, SY, ZW.  */
+                          switch (PROP (lookahead1_prop_ea))
+                            {
+                            case LBP_BK:
+                            case LBP_CR:
+                            case LBP_LF:
+                            case LBP_SP:
+                            case LBP_GL:
+                            case LBP_WJ:
+                            case LBP_CL:
+                            case LBP_QU1: case LBP_QU2: case LBP_QU3:
+                            case LBP_CP1: case LBP_CP2:
+                            case LBP_EX:
+                            case LBP_IS:
+                            case LBP_SY:
+                            case LBP_ZW:
+                              break;
+                            default:
+                              this_prop = LBP_QU1;
+                              break;
+                            }
+                        }
+
+                      switch (unilbrk_table [last_prop] [this_prop])
                         {
                         case D:
                           *p = UC_BREAK_POSSIBLE;
@@ -351,6 +334,29 @@ u32_possible_linebreaks_loop (const uint32_t *s, size_t n, const char *encoding,
                           abort ();
                         }
                     }
+
+                  if (prop == LBP_QU2)
+                    {
+                      /* For (LB15a): Replace LBP_QU2 with LBP_QU1 if the
+                         previous character's line break property was not one of
+                         BK, CR, LF, OP, QU, GL, SP, ZW.  */
+                      switch (prev_prop)
+                        {
+                        case LBP_BK:
+                        case LBP_CR:
+                        case LBP_LF:
+                        case LBP_OP1: case LBP_OP2:
+                        case LBP_QU1: case LBP_QU2: case LBP_QU3:
+                        case LBP_GL:
+                        case LBP_SP:
+                        case LBP_ZW:
+                          break;
+                        default:
+                          prop = LBP_QU1;
+                          break;
+                        }
+                    }
+
                   last_prop = prop;
                   seen_space = NULL;
                 }
index dd7d7c6fbdc5ed29759ccf31db6308a751fd730c..65248e5c403a51300600664f630124dd63826e62 100644 (file)
@@ -158,51 +158,6 @@ u8_possible_linebreaks_loop (const uint8_t *s, size_t n, const char *encoding,
                   /* This is arbitrary.  */
                   prop = LBP_AL1;
                   break;
-                case LBP_QU2:
-                  /* For (LB15a): Replace LBP_QU2 with LBP_QU1 if the previous
-                     character's line break property was not one of
-                     BK, CR, LF, OP, QU, GL, SP, ZW.  */
-                  switch (prev_prop)
-                    {
-                    case LBP_BK:
-                    case LBP_CR:
-                    case LBP_LF:
-                    case LBP_OP1: case LBP_OP2:
-                    case LBP_QU1: case LBP_QU2: case LBP_QU3:
-                    case LBP_GL:
-                    case LBP_SP:
-                    case LBP_ZW:
-                      break;
-                    default:
-                      prop = LBP_QU1;
-                      break;
-                    }
-                  break;
-                case LBP_QU3:
-                  /* For (LB15b): Replace LBP_QU3 with LBP_QU1 if the next
-                     character's line break property is not one of
-                     BK, CR, LF, SP, GL, WJ, CL, QU, CP, EX, IS, SY, ZW.  */
-                  switch (PROP (lookahead1_prop_ea))
-                    {
-                    case LBP_BK:
-                    case LBP_CR:
-                    case LBP_LF:
-                    case LBP_SP:
-                    case LBP_GL:
-                    case LBP_WJ:
-                    case LBP_CL:
-                    case LBP_QU1: case LBP_QU2: case LBP_QU3:
-                    case LBP_CP1: case LBP_CP2:
-                    case LBP_EX:
-                    case LBP_IS:
-                    case LBP_SY:
-                    case LBP_ZW:
-                      break;
-                    default:
-                      prop = LBP_QU1;
-                      break;
-                    }
-                  break;
                 }
 
               /* Deal with spaces and combining characters.  */
@@ -343,7 +298,35 @@ u8_possible_linebreaks_loop (const uint8_t *s, size_t n, const char *encoding,
                     }
                   else
                     {
-                      switch (unilbrk_table [last_prop] [prop])
+                      int this_prop = prop;
+                      if (prop == LBP_QU3)
+                        {
+                          /* For (LB15b): Replace LBP_QU3 with LBP_QU1 if the
+                             next character's line break property is not one of
+                             BK, CR, LF, SP, GL, WJ, CL, QU, CP, EX, IS, SY, ZW.  */
+                          switch (PROP (lookahead1_prop_ea))
+                            {
+                            case LBP_BK:
+                            case LBP_CR:
+                            case LBP_LF:
+                            case LBP_SP:
+                            case LBP_GL:
+                            case LBP_WJ:
+                            case LBP_CL:
+                            case LBP_QU1: case LBP_QU2: case LBP_QU3:
+                            case LBP_CP1: case LBP_CP2:
+                            case LBP_EX:
+                            case LBP_IS:
+                            case LBP_SY:
+                            case LBP_ZW:
+                              break;
+                            default:
+                              this_prop = LBP_QU1;
+                              break;
+                            }
+                        }
+
+                      switch (unilbrk_table [last_prop] [this_prop])
                         {
                         case D:
                           *p = UC_BREAK_POSSIBLE;
@@ -358,6 +341,29 @@ u8_possible_linebreaks_loop (const uint8_t *s, size_t n, const char *encoding,
                           abort ();
                         }
                     }
+
+                  if (prop == LBP_QU2)
+                    {
+                      /* For (LB15a): Replace LBP_QU2 with LBP_QU1 if the
+                         previous character's line break property was not one of
+                         BK, CR, LF, OP, QU, GL, SP, ZW.  */
+                      switch (prev_prop)
+                        {
+                        case LBP_BK:
+                        case LBP_CR:
+                        case LBP_LF:
+                        case LBP_OP1: case LBP_OP2:
+                        case LBP_QU1: case LBP_QU2: case LBP_QU3:
+                        case LBP_GL:
+                        case LBP_SP:
+                        case LBP_ZW:
+                          break;
+                        default:
+                          prop = LBP_QU1;
+                          break;
+                        }
+                    }
+
                   last_prop = prop;
                   seen_space = NULL;
                 }