@@ -80,14 +80,17 @@ uindex_t MCChunkCountChunkChunks(MCStringRef p_string, MCStringRef p_delimiter,
8080 return t_count;
8181}
8282
83- void MCChunkGetExtentsByRange ( integer_t p_first, integer_t p_last, MCChunkCountCallback p_callback, void *p_context, uindex_t & r_first, uindex_t & r_chunk_count)
83+ bool MCChunkEnsureExtentsByRange ( bool p_strict, integer_t p_first, integer_t p_last, MCChunkCountCallback p_callback, void *p_context, uindex_t & r_first, uindex_t & r_chunk_count)
8484{
8585 int32_t t_chunk_count;
86+ uinteger_t t_count;
87+ bool t_counted;
88+ t_counted = false ;
8689
8790 if (p_first < 0 || p_last < 0 )
8891 {
89- uinteger_t t_count;
9092 t_count = p_callback (p_context);
93+ t_counted = true ;
9194
9295 if (p_first < 0 )
9396 p_first += t_count;
@@ -111,32 +114,73 @@ void MCChunkGetExtentsByRange(integer_t p_first, integer_t p_last, MCChunkCountC
111114 if (t_chunk_count < 0 )
112115 t_chunk_count = 0 ;
113116
117+ if (p_strict)
118+ {
119+ if (t_chunk_count == 0 )
120+ return false ;
121+
122+ if (!t_counted)
123+ t_count = p_callback (p_context);
124+
125+ if (p_first + t_chunk_count > t_count)
126+ return false ;
127+ }
128+
114129 r_chunk_count = t_chunk_count;
115130 r_first = p_first;
131+ return true ;
116132}
117133
118- void MCChunkGetExtentsByExpression (integer_t p_first, MCChunkCountCallback p_callback, void *p_context, uindex_t & r_first, uindex_t & r_chunk_count)
134+ void MCChunkGetExtentsByRange (integer_t p_first, integer_t p_last, MCChunkCountCallback p_callback, void *p_context, uindex_t & r_first, uindex_t & r_chunk_count)
135+ {
136+ MCChunkEnsureExtentsByRange (false , p_first, p_last, p_callback, p_context, r_first, r_chunk_count);
137+ }
138+
139+ bool MCChunkEnsureExtentsByExpression (bool p_strict, integer_t p_first, MCChunkCountCallback p_callback, void *p_context, uindex_t & r_first, uindex_t & r_chunk_count)
119140{
120- r_chunk_count = 1 ;
141+ int32_t t_chunk_count;
142+ t_chunk_count = 1 ;
143+
144+ uinteger_t t_count;
145+ bool t_counted;
146+ t_counted = false ;
121147
122148 if (p_first < 0 )
123149 {
124- uinteger_t t_count;
125150 t_count = p_callback (p_context);
151+ t_counted = true ;
126152 p_first += t_count;
127153 }
128154 else
129155 p_first--;
130156
131157 if (p_first < 0 )
132158 {
133- r_chunk_count = 0 ;
159+ t_chunk_count = 0 ;
134160 p_first = 0 ;
135161 }
136162
163+ if (p_strict)
164+ {
165+ if (t_chunk_count == 0 )
166+ return false ;
167+
168+ if (!t_counted)
169+ t_count = p_callback (p_context);
170+
171+ if (p_first + t_chunk_count > t_count)
172+ return false ;
173+ }
174+
137175 r_first = p_first;
176+ r_chunk_count = t_chunk_count;
177+ return true ;
138178}
139179
180+ void MCChunkGetExtentsByExpression (integer_t p_first, MCChunkCountCallback p_callback, void *p_context, uindex_t & r_first, uindex_t & r_chunk_count)
181+ {
182+ MCChunkEnsureExtentsByExpression (false , p_first, p_callback, p_context, r_first, r_chunk_count);
183+ }
140184// //////////////////////////////////////////////////////////////////////////////
141185
142186void MCChunkGetExtentsOfByteChunkByRange (MCDataRef p_data, integer_t p_first, integer_t p_last, uindex_t & r_first, uindex_t & r_chunk_count)
@@ -159,14 +203,14 @@ void MCChunkGetExtentsOfCodeunitChunkByExpression(MCStringRef p_string, integer_
159203 MCChunkGetExtentsByExpression (p_first, MCChunkCountCodeunitChunkCallback, &p_string, r_first, r_chunk_count);
160204}
161205
162- void MCChunkGetExtentsOfGraphemeChunkByRange (MCStringRef p_string, integer_t p_first, integer_t p_last, uindex_t & r_first, uindex_t & r_chunk_count)
206+ bool MCChunkGetExtentsOfGraphemeChunkByRange (MCStringRef p_string, integer_t p_first, integer_t p_last, bool p_strict , uindex_t & r_first, uindex_t & r_chunk_count)
163207{
164- MCChunkGetExtentsByRange ( p_first, p_last, MCChunkCountCodeunitChunkCallback , &p_string, r_first, r_chunk_count);
208+ return MCChunkEnsureExtentsByRange (p_strict, p_first, p_last, MCChunkCountGraphemeChunkCallback , &p_string, r_first, r_chunk_count);
165209}
166210
167- void MCChunkGetExtentsOfGraphemeChunkByExpression (MCStringRef p_string, integer_t p_first, uindex_t & r_first, uindex_t & r_chunk_count)
211+ bool MCChunkGetExtentsOfGraphemeChunkByExpression (MCStringRef p_string, integer_t p_first, bool p_strict , uindex_t & r_first, uindex_t & r_chunk_count)
168212{
169- MCChunkGetExtentsByExpression ( p_first, MCChunkCountGraphemeChunkCallback, &p_string, r_first, r_chunk_count);
213+ return MCChunkEnsureExtentsByExpression (p_strict, p_first, MCChunkCountGraphemeChunkCallback, &p_string, r_first, r_chunk_count);
170214}
171215
172216void MCChunkGetExtentsOfElementChunkByRange (MCProperListRef p_string, integer_t p_first, integer_t p_last, uindex_t & r_first, uindex_t & r_chunk_count)
@@ -265,6 +309,7 @@ bool MCChunkApply(MCStringRef p_string, MCStringRef p_delimiter, MCStringOptions
265309bool MCChunkIterate (MCRange& x_range, MCStringRef p_string, MCStringRef p_delimiter, MCStringOptions p_options, bool p_first)
266310{
267311 // Currently assumes delimiter is 1 char long.
312+ // Reimplement with MCTextChunkIterator_Delimited to accommodate arbitrary delimiters.
268313 uindex_t t_delimiter_offset;
269314
270315 if (!p_first)
@@ -560,7 +605,7 @@ MCTextChunkIterator_ICU::MCTextChunkIterator_ICU(MCStringRef p_text, MCChunkType
560605 {
561606 MCRange t_range;
562607 uindex_t t_end;
563- /* UNCHECKED */ MCLocaleBreakIteratorCreate (kMCBasicLocale , p_chunk_type == kMCChunkTypeSentence ? kMCBreakIteratorTypeSentence : kMCBreakIteratorTypeCharacter , break_iterator);
608+ /* UNCHECKED */ MCLocaleBreakIteratorCreate (kMCLocaleBasic , p_chunk_type == kMCChunkTypeSentence ? kMCBreakIteratorTypeSentence : kMCBreakIteratorTypeCharacter , break_iterator);
564609 /* UNCHECKED */ MCLocaleBreakIteratorSetText (break_iterator, m_text);
565610 t_range . length = 0 ;
566611 t_range . offset = 0 ;
@@ -576,7 +621,7 @@ MCTextChunkIterator_ICU::MCTextChunkIterator_ICU(MCStringRef p_text, MCChunkType
576621 case kMCChunkTypeTrueWord :
577622 {
578623 MCAutoArray<uindex_t > t_breaks;
579- /* UNCHECKED */ MCLocaleBreakIteratorCreate (kMCBasicLocale , kMCBreakIteratorTypeWord , break_iterator);
624+ /* UNCHECKED */ MCLocaleBreakIteratorCreate (kMCLocaleBasic , kMCBreakIteratorTypeWord , break_iterator);
580625 /* UNCHECKED */ MCLocaleBreakIteratorSetText (break_iterator, m_text);
581626 MCRange t_range = MCRangeMake (0 , 0 );
582627
@@ -587,6 +632,8 @@ MCTextChunkIterator_ICU::MCTextChunkIterator_ICU(MCStringRef p_text, MCChunkType
587632 }
588633 }
589634 break ;
635+ default :
636+ break ;
590637 }
591638
592639 if (break_iterator != nil)
@@ -677,9 +724,6 @@ MCTextChunkIterator *MCChunkCreateTextChunkIterator(MCStringRef p_text, MCChunkT
677724 case kMCChunkTypeParagraph :
678725 t_iterator = new MCTextChunkIterator_Delimited (p_text, p_chunk_type, MCSTR (" \n " ));
679726 break ;
680- case kMCChunkTypeToken :
681- t_iterator = new MCTextChunkIterator_Tokenized (p_text, p_chunk_type);
682- break ;
683727 case kMCChunkTypeWord :
684728 t_iterator = new MCTextChunkIterator_Word (p_text, p_chunk_type, p_delimiter);
685729 break ;
0 commit comments