Skip to content

Commit 3bd1e88

Browse files
author
runrevali
committed
[[ Char As Grapheme ]] Fix a couple of merge issues
1 parent 422995d commit 3bd1e88

5 files changed

Lines changed: 47 additions & 13 deletions

File tree

engine/src/exec-strings-chunk.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void MCStringsCountChunksInRange(MCExecContext& ctxt, Chunk_term p_chunk_type, M
8484
t_type = MCChunkTypeFromChunkTerm(p_chunk_type);
8585

8686
MCTextChunkIterator *tci;
87-
tci = MCStringsTextChunkIteratorCreate(ctxt, p_string, p_chunk_type);
87+
tci = MCStringsTextChunkIteratorCreateWithRange(ctxt, p_string, p_range, p_chunk_type);
8888

8989
r_count = tci -> CountChunks();
9090

@@ -1176,7 +1176,19 @@ MCTextChunkIterator *MCStringsTextChunkIteratorCreate(MCExecContext& ctxt, MCStr
11761176
return tci;
11771177
}
11781178

1179-
return MCChunkCreateTextChunkIterator(p_text, MCChunkTypeFromChunkTerm(p_chunk_type), p_chunk_type == CT_LINE ? ctxt . GetLineDelimiter() : ctxt . GetItemDelimiter(), ctxt . GetStringComparisonType());
1179+
return MCChunkCreateTextChunkIterator(p_text, nil, MCChunkTypeFromChunkTerm(p_chunk_type), p_chunk_type == CT_LINE ? ctxt . GetLineDelimiter() : ctxt . GetItemDelimiter(), ctxt . GetStringComparisonType());
1180+
}
1181+
1182+
MCTextChunkIterator *MCStringsTextChunkIteratorCreateWithRange(MCExecContext& ctxt, MCStringRef p_text, MCRange p_range, Chunk_term p_chunk_type)
1183+
{
1184+
if (p_chunk_type == CT_TOKEN)
1185+
{
1186+
MCTextChunkIterator *tci;
1187+
tci = new MCTextChunkIterator_Tokenized(p_text, MCChunkTypeFromChunkTerm(p_chunk_type), p_range);
1188+
return tci;
1189+
}
1190+
1191+
return MCChunkCreateTextChunkIterator(p_text, &p_range, MCChunkTypeFromChunkTerm(p_chunk_type), p_chunk_type == CT_LINE ? ctxt . GetLineDelimiter() : ctxt . GetItemDelimiter(), ctxt . GetStringComparisonType());
11801192
}
11811193

11821194
bool MCStringsTextChunkIteratorNext(MCExecContext& ctxt, MCTextChunkIterator *tci)

engine/src/exec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,6 +2332,7 @@ void MCStringsSkipWord(MCExecContext& ctxt, MCStringRef p_string, bool p_skip_sp
23322332
class MCTextChunkIterator;
23332333

23342334
MCTextChunkIterator *MCStringsTextChunkIteratorCreate(MCExecContext& ctxt, MCStringRef p_text, Chunk_term p_chunk_type);
2335+
MCTextChunkIterator *MCStringsTextChunkIteratorCreateWithRange(MCExecContext& ctxt, MCStringRef p_text, MCRange p_range, Chunk_term p_chunk_type);
23352336
bool MCStringsTextChunkIteratorNext(MCExecContext& ctxt, MCTextChunkIterator *tci);
23362337

23372338
///////////

libfoundation/include/foundation-chunk.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,6 @@ class MCTextChunkIterator_Tokenized : public MCTextChunkIterator
284284
virtual bool Next();
285285
};
286286

287-
MCTextChunkIterator *MCChunkCreateTextChunkIterator(MCStringRef p_text, MCChunkType p_chunk_type, MCStringRef p_delimiter, MCStringOptions p_options);
287+
MCTextChunkIterator *MCChunkCreateTextChunkIterator(MCStringRef p_text, MCRange *p_range, MCChunkType p_chunk_type, MCStringRef p_delimiter, MCStringOptions p_options);
288288

289289
#endif // __MC_FOUNDATION_CHUNK__

libfoundation/src/foundation-chunk.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ bool MCTextChunkIterator_Word::Next()
869869

870870
////////////////////////////////////////////////////////////////////////////////
871871

872-
MCTextChunkIterator *MCChunkCreateTextChunkIterator(MCStringRef p_text, MCChunkType p_chunk_type, MCStringRef p_delimiter, MCStringOptions p_options)
872+
MCTextChunkIterator *MCChunkCreateTextChunkIterator(MCStringRef p_text, MCRange *p_range, MCChunkType p_chunk_type, MCStringRef p_delimiter, MCStringOptions p_options)
873873
{
874874
if (p_chunk_type == kMCChunkTypeCharacter && (MCStringIsNative(p_text) || (MCStringIsSimple(p_text) && MCStringIsUncombined(p_text))))
875875
p_chunk_type = kMCChunkTypeCodeunit;
@@ -881,23 +881,44 @@ MCTextChunkIterator *MCChunkCreateTextChunkIterator(MCStringRef p_text, MCChunkT
881881
case kMCChunkTypeCharacter:
882882
case kMCChunkTypeSentence:
883883
case kMCChunkTypeTrueWord:
884-
t_iterator = new MCTextChunkIterator_ICU(p_text, p_chunk_type);
884+
if (p_range != nil)
885+
t_iterator = new MCTextChunkIterator_ICU(p_text, p_chunk_type, *p_range);
886+
else
887+
t_iterator = new MCTextChunkIterator_ICU(p_text, p_chunk_type);
885888
break;
886889
case kMCChunkTypeLine:
887890
case kMCChunkTypeItem:
888-
t_iterator = new MCTextChunkIterator_Delimited(p_text, p_chunk_type, p_delimiter);
891+
if (p_range != nil)
892+
t_iterator = new MCTextChunkIterator_Delimited(p_text, p_chunk_type, p_delimiter, *p_range);
893+
else
894+
t_iterator = new MCTextChunkIterator_Delimited(p_text, p_chunk_type, p_delimiter);
895+
break;
896+
889897
break;
890898
case kMCChunkTypeParagraph:
891-
t_iterator = new MCTextChunkIterator_Delimited(p_text, p_chunk_type, MCSTR("\n"));
899+
if (p_range != nil)
900+
t_iterator = new MCTextChunkIterator_Delimited(p_text, p_chunk_type, MCSTR("\n"), *p_range);
901+
else
902+
t_iterator = new MCTextChunkIterator_Delimited(p_text, p_chunk_type, MCSTR("\n"));
903+
break;
892904
break;
893905
case kMCChunkTypeWord:
894-
t_iterator = new MCTextChunkIterator_Word(p_text, p_chunk_type, p_delimiter);
906+
if (p_range != nil)
907+
t_iterator = new MCTextChunkIterator_Word(p_text, p_chunk_type, p_delimiter, *p_range);
908+
else
909+
t_iterator = new MCTextChunkIterator_Word(p_text, p_chunk_type, p_delimiter);
895910
break;
896911
case kMCChunkTypeCodepoint:
897-
t_iterator = new MCTextChunkIterator_Codepoint(p_text, p_chunk_type);
912+
if (p_range != nil)
913+
t_iterator = new MCTextChunkIterator_Codepoint(p_text, p_chunk_type, *p_range);
914+
else
915+
t_iterator = new MCTextChunkIterator_Codepoint(p_text, p_chunk_type);
898916
break;
899917
case kMCChunkTypeCodeunit:
900-
t_iterator = new MCTextChunkIterator_Codeunit(p_text, p_chunk_type);
918+
if (p_range != nil)
919+
t_iterator = new MCTextChunkIterator_Codeunit(p_text, p_chunk_type, *p_range);
920+
else
921+
t_iterator = new MCTextChunkIterator_Codeunit(p_text, p_chunk_type);
901922
break;
902923
default:
903924
MCAssert(false);

libscript/src/module-char.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bool MCCharStoreChunk(MCStringRef &x_target, MCStringRef p_value, MCRange p_grap
5050
extern "C" MC_DLLEXPORT void MCCharEvalNumberOfCharsIn(MCStringRef p_target, index_t& r_output)
5151
{
5252
MCTextChunkIterator *tci;
53-
tci = MCChunkCreateTextChunkIterator(p_target, kMCChunkTypeCharacter, nil, kMCStringOptionCompareExact);
53+
tci = MCChunkCreateTextChunkIterator(p_target, nil, kMCChunkTypeCharacter, nil, kMCStringOptionCompareExact);
5454
r_output = tci -> CountChunks();
5555
}
5656

@@ -66,7 +66,7 @@ extern "C" MC_DLLEXPORT void MCCharEvalIsAmongTheCharsOf(MCStringRef p_needle, M
6666
}
6767

6868
MCTextChunkIterator *tci;
69-
tci = MCChunkCreateTextChunkIterator(p_target, kMCChunkTypeCharacter, nil, kMCStringOptionCompareExact);
69+
tci = MCChunkCreateTextChunkIterator(p_target, nil, kMCChunkTypeCharacter, nil, kMCStringOptionCompareExact);
7070
r_output = tci -> IsAmong(p_needle);
7171
}
7272

@@ -247,7 +247,7 @@ extern "C" MC_DLLEXPORT bool MCCharRepeatForEachChar(void*& x_iterator, MCString
247247
if ((uintptr_t)x_iterator == 0)
248248
{
249249
t_first = true;
250-
t_iterator = MCChunkCreateTextChunkIterator(p_string, kMCChunkTypeCharacter, nil, kMCStringOptionCompareExact);
250+
t_iterator = MCChunkCreateTextChunkIterator(p_string, nil, kMCChunkTypeCharacter, nil, kMCStringOptionCompareExact);
251251
}
252252
else
253253
t_iterator = (MCTextChunkIterator *)x_iterator;

0 commit comments

Comments
 (0)