@@ -5421,9 +5421,18 @@ void MCChunk::compile_object_ptr(MCSyntaxFactoryRef ctxt)
54215421
54225422// //////////////////////////////////////////////////////////////////////////////
54235423
5424- static bool need_increment ( Chunk_term p_chunk_type)
5424+ static uindex_t delim_increment (MCExecContext& ctxt, Chunk_term p_chunk_type)
54255425{
5426- return (p_chunk_type == CT_LINE || p_chunk_type == CT_ITEM || p_chunk_type == CT_PARAGRAPH );
5426+ if (p_chunk_type == CT_PARAGRAPH )
5427+ return 1 ;
5428+
5429+ if (p_chunk_type == CT_LINE )
5430+ return MCStringGetLength (ctxt . GetLineDelimiter ());
5431+
5432+ if (p_chunk_type == CT_ITEM )
5433+ return MCStringGetLength (ctxt . GetItemDelimiter ());
5434+
5435+ return 0 ;
54275436}
54285437
54295438static bool MCStringsIsAmongTheChunksOfRange (MCExecContext& ctxt, MCStringRef p_chunk, MCStringRef p_string, Chunk_term p_chunk_type, MCStringOptions p_options, MCRange p_range)
@@ -5432,17 +5441,17 @@ static bool MCStringsIsAmongTheChunksOfRange(MCExecContext& ctxt, MCStringRef p_
54325441 if (!MCStringFind (p_string, p_range, p_chunk, p_options, &t_range))
54335442 return false ;
54345443
5435- char_t t_delimiter;
5444+ MCStringRef t_delimiter;
54365445 t_delimiter = p_chunk_type == CT_ITEM ? ctxt . GetItemDelimiter () : ctxt . GetLineDelimiter ();
54375446
54385447 // if there is no delimiter to the left then continue searching the string.
54395448 if (t_range . offset != 0 &&
5440- MCStringGetNativeCharAtIndex (p_string, t_range . offset - 1 ) != t_delimiter)
5449+ ! MCStringSubstringEndsWith (p_string, MCRangeMake ( 0 , t_range . offset), t_delimiter, p_options) )
54415450 return MCStringsIsAmongTheChunksOfRange (ctxt, p_chunk, p_string, p_chunk_type, p_options, MCRangeMake (t_range . offset + t_range . length, p_range . length));
54425451
54435452 // if there is no delimiter to the right then continue searching the string.
54445453 if (t_range . offset + t_range . length != MCStringGetLength (p_string) &&
5445- MCStringGetNativeCharAtIndex (p_string, t_range . offset + t_range . length) != t_delimiter)
5454+ ! MCStringSubstringBeginsWith (p_string, MCRangeMake ( t_range . offset + t_range . length, UINDEX_MAX ), t_delimiter, p_options) )
54465455 return MCStringsIsAmongTheChunksOfRange (ctxt, p_chunk, p_string, p_chunk_type, p_options, MCRangeMake (t_range . offset + t_range . length, p_range . length));
54475456
54485457 return true ;
@@ -5481,17 +5490,17 @@ static bool MCStringsFindChunkInRange(MCExecContext& ctxt, MCStringRef p_string,
54815490 return false ;
54825491
54835492 // Work out the delimiter.
5484- char_t t_delimiter;
5493+ MCStringRef t_delimiter;
54855494 t_delimiter = p_chunk_type == CT_ITEM ? ctxt . GetItemDelimiter () : ctxt . GetLineDelimiter ();
54865495
54875496 // If we are in wholeMatches mode, ensure the delimiter is either side.
54885497 if (ctxt . GetWholeMatches ())
54895498 {
54905499 if (t_range . offset > 0 &&
5491- MCStringGetNativeCharAtIndex (p_string, t_range . offset - 1 ) != t_delimiter)
5500+ ! MCStringSubstringEndsWith (p_string, MCRangeMake ( 0 , t_range . offset), t_delimiter, p_options) )
54925501 return MCStringsFindChunkInRange (ctxt, p_string, p_needle, p_chunk_type, p_options, MCRangeMake (t_range . offset + t_range . length, p_range . length), r_offset);
54935502 if (t_range . offset + t_range . length < MCStringGetLength (p_string) &&
5494- MCStringGetNativeCharAtIndex (p_string, t_range . offset + t_range . length) != t_delimiter)
5503+ ! MCStringSubstringBeginsWith (p_string, MCRangeMake ( t_range . offset + t_range . length, UINDEX_MAX ), t_delimiter, p_options) )
54955504 return MCStringsFindChunkInRange (ctxt, p_string, p_needle, p_chunk_type, p_options, MCRangeMake (t_range . offset + t_range . length + 1 , p_range . length), r_offset);
54965505 }
54975506
@@ -5639,8 +5648,8 @@ bool MCTextChunkIterator::next(MCExecContext& ctxt)
56395648
56405649 uindex_t t_offset = range . offset + range . length;
56415650
5642- if (!first_chunk && need_increment (type) )
5643- t_offset++ ;
5651+ if (!first_chunk)
5652+ t_offset += delim_increment (ctxt, type) ;
56445653
56455654 if (t_offset >= length)
56465655 return false ;
@@ -5653,13 +5662,13 @@ bool MCTextChunkIterator::next(MCExecContext& ctxt)
56535662 case CT_LINE :
56545663 case CT_ITEM :
56555664 {
5656- char_t t_line_delimiter = ctxt . GetLineDelimiter ();
5657- char_t t_item_delimiter = ctxt . GetItemDelimiter ();
5665+ MCStringRef t_line_delimiter = ctxt . GetLineDelimiter ();
5666+ MCStringRef t_item_delimiter = ctxt . GetItemDelimiter ();
56585667
5659- char_t t_delimiter = (type == CT_LINE ) ? t_line_delimiter : t_item_delimiter;
5668+ MCStringRef t_delimiter = (type == CT_LINE ) ? t_line_delimiter : t_item_delimiter;
56605669
56615670 // calculate the length of the line / item
5662- if (!MCStringFirstIndexOfChar (text, t_delimiter, t_offset, kMCCompareExact , t_offset))
5671+ if (!MCStringFirstIndexOf (text, t_delimiter, t_offset, kMCCompareExact , t_offset))
56635672 {
56645673 range . length = length - range . offset;
56655674 exhausted = true ;
@@ -5831,12 +5840,12 @@ uindex_t MCTextChunkIterator::chunkoffset(MCExecContext& ctxt, MCStringRef p_nee
58315840 return 0 ;
58325841 }
58335842
5834- codepoint_t t_delimiter;
5843+ MCStringRef t_delimiter;
58355844 t_delimiter = type == CT_ITEM ? ctxt . GetItemDelimiter () : ctxt . GetLineDelimiter ();
58365845
58375846 // Count the number of delimiters between the start of the first chunk
58385847 // and the start of the found string.
5839- t_chunk_offset += MCStringCountChar (text, MCRangeMake (range . offset, t_found_offset - range . offset), t_delimiter, t_options);
5848+ t_chunk_offset += MCStringCount (text, MCRangeMake (range . offset, t_found_offset - range . offset), t_delimiter, t_options);
58405849
58415850 if (type == CT_PARAGRAPH )
58425851 t_chunk_offset += MCStringCountChar (text, MCRangeMake (range . offset, t_found_offset - range . offset), 0x2029 , t_options);
0 commit comments