https://gcc.gnu.org/g:26d55e675e39db9380ac286ab4b9b1f08a496bad
commit r17-6376-g26d55e675e39db9380ac286ab4b9b1f08a496bad Author: Robert Dubner <[email protected]> Date: Wed Nov 18 00:22:50 2026 -0500 cobol: Use longest delimiter for UNSTRING The UNSTRING statement can take multiple delimiters. The existing code was improperly selecting the last one in the list that matched the text. This patch causes it to properly select the longest matching delimiter. libgcobol/ChangeLog: * unstring.cc (unstring_fixed): When checking for delimiters skip any that are shorter than the current "winner". Diff: --- libgcobol/unstring.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libgcobol/unstring.cc b/libgcobol/unstring.cc index 10701e225de0..c89ee7d16f1b 100644 --- a/libgcobol/unstring.cc +++ b/libgcobol/unstring.cc @@ -606,7 +606,7 @@ unstring_fixed( const cblc_referlet_t *id2, // There are complexities because of figurative constants, including the // LOW-VALUE figurative constant, which precludes the use of string - // operations that would be confused by embedded NUL characters. Dammit. + // operations that would be confused by embedded NUL characters. // For each delimiter, there is an identifier-4 receiver that must be // resolved. Each might have an identifier-5 delimiter, and each might have @@ -751,6 +751,15 @@ unstring_fixed( const cblc_referlet_t *id2, { continue; } + if( best_delimiter < ndelimiteds + && str_id2.size() < delimiters[best_delimiter].size() ) + { + // When there are multiple possible matches, the longest delimiter + // takes precedence. This one is shorter than the current winner, so + // there is no point in even looking at it. + continue; + } + size_t nfound = left + finder_t::find( str_id1.data() + left * stride_id1, (right - left) * stride_id1,
