>From 5e8b609038b91156e8f5d77baf692e4e5014e209 Mon Sep 17 00:00:00 2001
From: Robert Dubner <[email protected]>
Date: Wed, 18 Nov 2026 09:11:38 -0500
Subject: [PATCH] cobol: Fix UNSTRING behavior
UNSTRING processing now abides by the ISO specification general rules,
where the first matching delimiter at a position "wins".
libgcobol/ChangeLog:
* unstring.cc (unstring_fixed): Keep the first listed delimiter
when
matches start at the same position.
---
libgcobol/unstring.cc | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)
diff --git a/libgcobol/unstring.cc b/libgcobol/unstring.cc
index c89ee7d16f1..f9bbcf4394f 100644
--- a/libgcobol/unstring.cc
+++ b/libgcobol/unstring.cc
@@ -751,15 +751,6 @@ 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,
@@ -769,10 +760,10 @@ unstring_fixed( const cblc_referlet_t *id2,
if( nfound != right )
{
// We found a delimiter
- if( nfound > best_leftmost )
+ if( nfound >= best_leftmost )
{
- // This delimiter lives to the right of the best one we found
so far.
- // Ignore it, and proceed to the next delimiter.
+ // Keep the first listed delimiter when matches start at the
same
+ // position, and ignore matches to its right.
continue;
}
// This delimiter is the leftmost we've seen so far:
--
2.34.1