: <i>tcl_startOfPreviousWord ignores the last character when start is the string length</i> plus 8 other changes
by
.
D 2026-10-26T14:04:11.997
J assignee jan.nijtmans
J closedate 2461340.0862499652
J closer jan.nijtmans
J comment <tt>tcl_startOfPreviousWord</tt>\sreturns\sa\swrong\sresult\swhen\s<tt>start</tt>\sis\sequal\sto\s(or\sgreater\sthan)\sthe\slength\sof\sthe\sstring\sand\sthe\slast\sword\shas\sone\scharacter:\r\n\r\n<verbatim>\r\n%\stcl_startOfPreviousWord\s{a\sb\sc}\s5\r\n2\r\n%\stcl_startOfPreviousWord\s{ab\sc}\s4\r\n0\r\n</verbatim>\r\n\r\nThe\sexpected\sresults\sare\s4\sand\s3,\swhich\s8.5\sand\s8.6.13\sreturn.\sThe\slast\scharacter\sis\sdropped,\sso\sthe\slast\sword\sis\snot\sfound\swhen\sit\shas\sone\scharacter.\sFor\slonger\swords\sthe\sresult\shappens\sto\sbe\sright\s(word-2.6).\r\n\r\nThis\sis\sa\sregression\sfrom\sthe\sfix\sfor\s[16e25e1402]\s([8f65470f72],\s8.6.14):\s<tt>[string\srange\s[string\srange\s$str\s0\s$start]\s0\send-1]</tt>\sdrops\sthe\slast\scharacter\salso\swhen\s<tt>$start</tt>\sis\sbeyond\sthe\send\sof\sthe\sstring,\swhile\sthe\sold\s<tt>[string\srange\s$str\s0\s$start-1]</tt>\sdid\snot.\r\n\r\nIt\saffects\sTk:\sin\san\sentry\sor\sspinbox\susing\sthese\sprocedures\s(8.6,\sor\s<tt>-locale\stcl8</tt>\sin\s9.x),\sCtrl+Left\sfrom\sthe\send\sof\sthe\stext\sskips\sa\sfinal\sone-character\sword.\r\n\r\nA\spossible\sfix\sthat\skeeps\s<tt>end-1</tt>\sworking:\r\n<verbatim>\r\nset\sprefix\s[string\srange\s$str\s0\s$start]\r\nif\s{[string\sindex\s$str\s$start]\sne\s""}\s{\r\n\s\s\s\sset\sprefix\s[string\srange\s$prefix\s0\send-1]\r\n}\r\nregexp\s-indices\s--\s$WordBreakRE(previous)\s$prefix\sresult\sword\r\n</verbatim>\r\nwith\stests\ssuch\sas\s<tt>tcl_startOfPreviousWord\s"ab\sc"\s4</tt>\s→\s3\sand\s<tt>tcl_startOfPreviousWord\s"ab\sc"\send+1</tt>\s→\s3.\sWith\sit,\sall\sword-2.*\scases\sstill\sgive\sthe\ssame\sresults\s(checked\swith\s8.6.18\sand\s9.1.1\sby\sredefining\sthe\sprocedure).
J icomment Fix\smerged\sto\s[c79e0372a7|trunk],\score-9-0-branch\sand\score-8-6-branch\r\n\r\nMany\sthanks!
J login jan.nijtmans
J mimetype text/x-fossil-wiki
J resolution Fixed
J status Closed
K 3e7c4a039d32955f5bd5b6d2de3af84f5c5fca76
U jan.nijtmans
Z 60912b79c1864e2dd95bfadf62c36354