Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit d452e3a

Browse files
committed
Merge branch 'develop' into feature-lcbtyperename
This required some changes to the new codeunit module in order to complete the merge, including removing a bogus function and updating a lot of handler definitions with the new type names. Conflicts: libscript/src/foreign.mlc
2 parents 5c32185 + ca0d2f9 commit d452e3a

31 files changed

+2284
-807
lines changed

engine/src/chunk.cpp

Lines changed: 16 additions & 542 deletions
Large diffs are not rendered by default.

engine/src/chunk.h

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1717
#ifndef CHUNK_H
1818
#define CHUNK_H
1919

20+
#ifndef __MC_FOUNDATION_CHUNK__
21+
#include "foundation-chunk.h"
22+
#endif
23+
2024
#include "express.h"
2125

2226
class MCCRef
@@ -236,42 +240,6 @@ class MCChunk : public MCExpression
236240
}
237241
};
238242

239-
class MCTextChunkIterator
240-
{
241-
MCStringRef text;
242-
MCScriptPoint *sp;
243-
Chunk_term type;
244-
MCRange range;
245-
bool exhausted;
246-
uindex_t length;
247-
bool first_chunk;
248-
MCAutoArray<MCRange> breaks;
249-
uindex_t break_position;
250-
251-
// store the number of codeunits matched in text when searching for
252-
// delimiter, so that we can increment the range appropriately.
253-
uindex_t delimiter_length;
254-
255-
public:
256-
MCTextChunkIterator(Chunk_term p_chunk_type, MCStringRef p_text);
257-
// AL-2015-02-10: [[ Bug 14532 ]] Add text chunk iterator constructor for restricted range chunk operations.
258-
MCTextChunkIterator(Chunk_term p_chunk_type, MCStringRef p_text, MCRange p_restriction);
259-
~MCTextChunkIterator();
260-
261-
MCRange getrange()
262-
{
263-
return range;
264-
}
265-
266-
bool isexhausted()
267-
{
268-
return exhausted;
269-
}
270-
271-
bool next(MCExecContext& ctxt);
272-
bool copystring(MCStringRef& r_string);
273-
uindex_t countchunks(MCExecContext& ctxt);
274-
bool isamong(MCExecContext& ctxt, MCStringRef p_needle);
275-
uindex_t chunkoffset(MCExecContext& ctxt, MCStringRef p_needle, uindex_t p_start_offset);
276-
};
243+
MCChunkType MCChunkTypeFromChunkTerm(Chunk_term p_chunk_term);
244+
277245
#endif

engine/src/exec-keywords.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -436,35 +436,35 @@ void MCKeywordsExecRepeatFor(MCExecContext& ctxt, MCStatement *statements, MCExp
436436
switch (each)
437437
{
438438
case FU_LINE:
439-
tci = new MCTextChunkIterator(CT_LINE, *t_string);
439+
tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_LINE);
440440
break;
441441
case FU_PARAGRAPH:
442-
tci = new MCTextChunkIterator(CT_PARAGRAPH, *t_string);
442+
tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_PARAGRAPH);
443443
break;
444444
case FU_SENTENCE:
445-
tci = new MCTextChunkIterator(CT_SENTENCE, *t_string);
445+
tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_SENTENCE);
446446
break;
447447
case FU_ITEM:
448-
tci = new MCTextChunkIterator(CT_ITEM, *t_string);
448+
tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_ITEM);
449449
break;
450450
case FU_WORD:
451-
tci = new MCTextChunkIterator(CT_WORD, *t_string);
451+
tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_WORD);
452452
break;
453453
case FU_TRUEWORD:
454-
tci = new MCTextChunkIterator(CT_TRUEWORD, *t_string);
454+
tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_TRUEWORD);
455455
break;
456456
case FU_TOKEN:
457-
tci = new MCTextChunkIterator(CT_TOKEN, *t_string);
457+
tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_TOKEN);
458458
break;
459459
case FU_CODEPOINT:
460-
tci = new MCTextChunkIterator(CT_CODEPOINT, *t_string);
460+
tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_CODEPOINT);
461461
break;
462462
case FU_CODEUNIT:
463-
tci = new MCTextChunkIterator(CT_CODEUNIT, *t_string);
463+
tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_CODEUNIT);
464464
break;
465465
case FU_CHARACTER:
466466
default:
467-
tci = new MCTextChunkIterator(CT_CHARACTER, *t_string);
467+
tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_CHARACTER);
468468
break;
469469
}
470470
}
@@ -541,16 +541,16 @@ void MCKeywordsExecRepeatFor(MCExecContext& ctxt, MCStatement *statements, MCExp
541541

542542
default:
543543
{
544-
t_found = tci -> next(ctxt);
545-
endnext = tci -> isexhausted();
546-
544+
t_found = MCStringsTextChunkIteratorNext(ctxt, tci);
545+
endnext = tci -> IsExhausted();
546+
547547
if (!t_found)
548548
{
549549
t_unit = kMCEmptyString;
550550
done = true;
551551
}
552552
else
553-
tci -> copystring(&t_unit);
553+
tci -> CopyString(&t_unit);
554554
}
555555
}
556556
// MW-2010-12-15: [[ Bug 9218 ]] Added KEY to the type of repeat that already

engine/src/exec-strings-chunk.cpp

Lines changed: 87 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,19 @@ void MCStringsCountChunksInRange(MCExecContext& ctxt, Chunk_term p_chunk_type, M
7676

7777
if (p_chunk_type == CT_CODEUNIT)
7878
{
79-
r_count = MCU_min(MCStringGetLength(p_string), p_range . length) - p_range . offset;
79+
// AL-2015-03-03: [[ Bug 14744 ]] Fix incorrect codeunit count calculation
80+
r_count = MCU_min(MCStringGetLength(p_string) - p_range . offset, p_range . length);
8081
return;
8182
}
8283

84+
MCChunkType t_type;
85+
t_type = MCChunkTypeFromChunkTerm(p_chunk_type);
86+
8387
MCTextChunkIterator *tci;
84-
tci = new MCTextChunkIterator(p_chunk_type, p_string, p_range);
85-
r_count = tci -> countchunks(ctxt);
88+
tci = MCStringsTextChunkIteratorCreate(ctxt, p_string, p_chunk_type);
89+
90+
r_count = tci -> CountChunks();
91+
8692
delete tci;
8793
return;
8894
}
@@ -107,36 +113,7 @@ uinteger_t MCStringsCountChunkCallback(void *context)
107113

108114
void MCStringsSkipWord(MCExecContext& ctxt, MCStringRef p_string, bool p_skip_spaces, uindex_t& x_offset)
109115
{
110-
uindex_t t_space_offset;
111-
uindex_t t_length = MCStringGetLength(p_string);
112-
uindex_t t_end_quote_offset = t_length;
113-
uindex_t t_end_line_offset = t_length;
114-
115-
if (MCStringGetCharAtIndex(p_string, x_offset) == '"')
116-
{
117-
// then bump the offset up to the next quotation mark + 1, or the beginning of the next line
118-
// if neither of these are present then set offset to string length.
119-
MCStringFirstIndexOfChar(p_string, '"', x_offset + 1, kMCCompareExact, t_end_quote_offset);
120-
MCStringFirstIndexOf(p_string, ctxt . GetLineDelimiter(), x_offset + 1, kMCCompareExact, t_end_line_offset);
121-
122-
if (t_end_quote_offset < t_end_line_offset)
123-
x_offset = t_end_quote_offset + 1;
124-
else if (t_end_line_offset < t_end_quote_offset)
125-
x_offset = t_end_line_offset + MCStringGetLength(ctxt . GetLineDelimiter());
126-
else
127-
x_offset = t_length;
128-
}
129-
else
130-
{
131-
while (!MCUnicodeIsWhitespace(MCStringGetCharAtIndex(p_string, x_offset)) && x_offset < t_length)
132-
x_offset++;
133-
}
134-
135-
if (p_skip_spaces)
136-
{
137-
while (MCUnicodeIsWhitespace(MCStringGetCharAtIndex(p_string, x_offset)) && x_offset < t_length)
138-
x_offset++;
139-
}
116+
MCChunkSkipWord(p_string, ctxt . GetLineDelimiter(), ctxt . GetStringComparisonType(), p_skip_spaces, x_offset);
140117
}
141118

142119
// AL-2015-02-10: [[ Bug 14532 ]] Allow chunk extents to be counted in a given range, to prevent substring copying in text chunk resolution.
@@ -199,35 +176,35 @@ void MCStringsGetExtentsByOrdinalInRange(MCExecContext& ctxt, Chunk_term p_chunk
199176
void MCStringsGetExtentsByRangeInRange(MCExecContext& ctxt, Chunk_term p_chunk_type, integer_t p_first, integer_t p_last, MCValueRef p_string, MCRange *p_range, uinteger_t& r_first, uinteger_t& r_chunk_count)
200177
{
201178
if (MCValueGetTypeCode(p_string) == kMCValueTypeCodeData)
202-
MCChunkGetExtentsOfByteChunkByRangeInRange((MCDataRef)p_string, p_range, p_first, p_last, r_first, r_chunk_count);
179+
MCChunkGetExtentsOfByteChunkByRangeInRange((MCDataRef)p_string, p_range, p_first, p_last, false, false, false, r_first, r_chunk_count);
203180
else if (p_chunk_type == CT_CODEUNIT)
204-
MCChunkGetExtentsOfCodeunitChunkByRangeInRange((MCStringRef)p_string, p_range, p_first, p_last, r_first, r_chunk_count);
181+
MCChunkGetExtentsOfCodeunitChunkByRangeInRange((MCStringRef)p_string, p_range, p_first, p_last, false, false, false, r_first, r_chunk_count);
205182
else
206183
{
207184
MCChunkCountState t_state;
208185
t_state . string = (MCStringRef)p_string;
209186
t_state . chunk = p_chunk_type;
210187
t_state . ctxt = &ctxt;
211188
t_state . range = p_range;
212-
MCChunkGetExtentsByRangeInRange(p_first, p_last, MCStringsCountChunkCallback, &t_state, r_first, r_chunk_count);
189+
MCChunkGetExtentsByRangeInRange(false, false, false, p_first, p_last, MCStringsCountChunkCallback, &t_state, r_first, r_chunk_count);
213190
}
214191
}
215192

216193
// AL-2015-02-10: [[ Bug 14532 ]] Allow chunk extents to be counted in a given range, to prevent substring copying in text chunk resolution.
217194
void MCStringsGetExtentsByExpressionInRange(MCExecContext& ctxt, Chunk_term p_chunk_type, integer_t p_first, MCStringRef p_string, MCRange *p_range, uinteger_t& r_first, uinteger_t& r_chunk_count)
218195
{
219196
if (MCValueGetTypeCode(p_string) == kMCValueTypeCodeData)
220-
MCChunkGetExtentsOfByteChunkByExpressionInRange((MCDataRef)p_string, p_range, p_first, r_first, r_chunk_count);
197+
MCChunkGetExtentsOfByteChunkByExpressionInRange((MCDataRef)p_string, p_range, p_first, false, false, false, r_first, r_chunk_count);
221198
else if (p_chunk_type == CT_CODEUNIT)
222-
MCChunkGetExtentsOfCodeunitChunkByExpressionInRange((MCStringRef)p_string, p_range, p_first, r_first, r_chunk_count);
199+
MCChunkGetExtentsOfCodeunitChunkByExpressionInRange((MCStringRef)p_string, p_range, p_first, false, false, false, r_first, r_chunk_count);
223200
else
224201
{
225202
MCChunkCountState t_state;
226203
t_state . string = (MCStringRef)p_string;
227204
t_state . chunk = p_chunk_type;
228205
t_state . ctxt = &ctxt;
229206
t_state . range = p_range;
230-
MCChunkGetExtentsByExpressionInRange(p_first, MCStringsCountChunkCallback, &t_state, r_first, r_chunk_count);
207+
MCChunkGetExtentsByExpressionInRange(false, false, false, p_first, MCStringsCountChunkCallback, &t_state, r_first, r_chunk_count);
231208
}
232209
}
233210

@@ -1150,3 +1127,74 @@ void MCStringsMarkBytesOfTextByOrdinal(MCExecContext& ctxt, Chunk_term p_ordinal
11501127
x_mark . start = t_cu_range . offset + t_first;
11511128
x_mark . finish = x_mark . start + t_chunk_count;
11521129
}
1130+
1131+
////////////////////////////////////////////////////////////////////////////////
1132+
1133+
MCTextChunkIterator_Tokenized::MCTextChunkIterator_Tokenized(MCStringRef p_text, MCChunkType p_chunk_type) : MCTextChunkIterator(p_text, p_chunk_type)
1134+
{
1135+
m_sp = new MCScriptPoint(p_text);
1136+
}
1137+
1138+
MCTextChunkIterator_Tokenized::MCTextChunkIterator_Tokenized(MCStringRef p_text, MCChunkType p_chunk_type, MCRange p_restriction) : MCTextChunkIterator(p_text, p_chunk_type, p_restriction)
1139+
{
1140+
MCAutoStringRef t_substring;
1141+
MCStringCopySubstring(m_text, p_restriction, &t_substring);
1142+
MCValueAssign(m_text, *t_substring);
1143+
m_sp = new MCScriptPoint(m_text);
1144+
}
1145+
1146+
MCTextChunkIterator_Tokenized::~MCTextChunkIterator_Tokenized()
1147+
{
1148+
delete m_sp;
1149+
}
1150+
1151+
bool MCTextChunkIterator_Tokenized::Next()
1152+
{
1153+
MCerrorlock++;
1154+
1155+
bool t_found = true;
1156+
uint2 t_pos;
1157+
Parse_stat ps = m_sp -> nexttoken();
1158+
if (ps == PS_ERROR || ps == PS_EOF)
1159+
t_found = false;
1160+
1161+
if (t_found)
1162+
{
1163+
m_range . offset = m_sp -> getindex();
1164+
m_range . length = MCStringGetLength(m_sp -> gettoken_stringref());
1165+
}
1166+
1167+
return t_found;
1168+
}
1169+
1170+
1171+
MCTextChunkIterator *MCStringsTextChunkIteratorCreate(MCExecContext& ctxt, MCStringRef p_text, Chunk_term p_chunk_type)
1172+
{
1173+
if (p_chunk_type == CT_TOKEN)
1174+
{
1175+
MCTextChunkIterator *tci;
1176+
tci = new MCTextChunkIterator_Tokenized(p_text, MCChunkTypeFromChunkTerm(p_chunk_type));
1177+
return tci;
1178+
}
1179+
1180+
return MCChunkCreateTextChunkIterator(p_text, MCChunkTypeFromChunkTerm(p_chunk_type), p_chunk_type == CT_LINE ? ctxt . GetLineDelimiter() : ctxt . GetItemDelimiter(), ctxt . GetStringComparisonType());
1181+
}
1182+
1183+
bool MCStringsTextChunkIteratorNext(MCExecContext& ctxt, MCTextChunkIterator *tci)
1184+
{
1185+
tci -> SetOptions(ctxt . GetStringComparisonType());
1186+
1187+
MCChunkType t_type;
1188+
t_type = tci -> GetType();
1189+
1190+
if (t_type == kMCChunkTypeLine || t_type == kMCChunkTypeItem)
1191+
{
1192+
MCStringRef t_delimiter;
1193+
t_delimiter = t_type == kMCChunkTypeLine ? ctxt . GetLineDelimiter() : ctxt . GetItemDelimiter();
1194+
reinterpret_cast<MCTextChunkIterator_Delimited *>(tci) -> SetDelimiter(t_delimiter);
1195+
}
1196+
1197+
return tci -> Next();
1198+
}
1199+
1200+
////////////////////////////////////////////////////////////////////////////////

engine/src/exec-strings.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
3636
#include "chunk.h"
3737
#include "date.h"
3838

39+
#include "foundation-chunk.h"
40+
3941
////////////////////////////////////////////////////////////////////////////////
4042

4143
MC_EXEC_DEFINE_EVAL_METHOD(Strings, ToLower, 2)
@@ -1596,12 +1598,18 @@ void MCStringsEvalEndsWith(MCExecContext& ctxt, MCStringRef p_whole, MCStringRef
15961598

15971599
bool MCStringsEvalIsAmongTheChunksOf(MCExecContext& ctxt, MCStringRef p_chunk, MCStringRef p_text, Chunk_term p_chunk_type)
15981600
{
1601+
MCChunkType t_type;
1602+
t_type = MCChunkTypeFromChunkTerm(p_chunk_type);
1603+
15991604
MCTextChunkIterator *tci;
1600-
tci = new MCTextChunkIterator(p_chunk_type, p_text);
1605+
tci = MCStringsTextChunkIteratorCreate(ctxt, p_text, p_chunk_type);
1606+
16011607
bool t_result;
1602-
t_result = tci -> isamong(ctxt, p_chunk);
1608+
t_result = tci -> IsAmong(p_chunk);
1609+
16031610
delete tci;
16041611
return t_result;
1612+
16051613
}
16061614

16071615
void MCStringsEvalIsAmongTheLinesOf(MCExecContext& ctxt, MCStringRef p_chunk, MCStringRef p_string, bool& r_result)
@@ -1734,9 +1742,14 @@ void MCStringsEvalIsNotAmongTheBytesOf(MCExecContext& ctxt, MCDataRef p_chunk, M
17341742

17351743
uindex_t MCStringsChunkOffset(MCExecContext& ctxt, MCStringRef p_chunk, MCStringRef p_string, uindex_t p_start_offset, Chunk_term p_chunk_type)
17361744
{
1745+
MCChunkType t_type;
1746+
t_type = MCChunkTypeFromChunkTerm(p_chunk_type);
1747+
17371748
MCTextChunkIterator *tci;
1738-
tci = new MCTextChunkIterator(p_chunk_type, p_string);
1739-
uindex_t t_offset = tci -> chunkoffset(ctxt, p_chunk, p_start_offset);
1749+
tci = MCStringsTextChunkIteratorCreate(ctxt, p_string, p_chunk_type);
1750+
1751+
uindex_t t_offset = tci -> ChunkOffset(p_chunk, p_start_offset, nil, ctxt . GetWholeMatches());
1752+
17401753
delete tci;
17411754
return t_offset;
17421755
}

engine/src/exec.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,6 +2329,11 @@ void MCStringsMarkBytesOfTextByOrdinal(MCExecContext& ctxt, Chunk_term p_ordinal
23292329

23302330
void MCStringsSkipWord(MCExecContext& ctxt, MCStringRef p_string, bool p_skip_spaces, uindex_t& x_offset);
23312331

2332+
class MCTextChunkIterator;
2333+
2334+
MCTextChunkIterator *MCStringsTextChunkIteratorCreate(MCExecContext& ctxt, MCStringRef p_text, Chunk_term p_chunk_type);
2335+
bool MCStringsTextChunkIteratorNext(MCExecContext& ctxt, MCTextChunkIterator *tci);
2336+
23322337
///////////
23332338

23342339
struct MCInterfaceBackdrop;

engine/src/modules.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern "C"
3030
extern builtin_module_descriptor __com_livecode_bitwise_module_info;
3131
extern builtin_module_descriptor __com_livecode_byte_module_info;
3232
extern builtin_module_descriptor __com_livecode_char_module_info;
33+
extern builtin_module_descriptor __com_livecode_codeunit_module_info;
3334
extern builtin_module_descriptor __com_livecode_date_module_info;
3435
extern builtin_module_descriptor __com_livecode_encoding_module_info;
3536
extern builtin_module_descriptor __com_livecode_file_module_info;
@@ -59,6 +60,7 @@ extern "C"
5960
&__com_livecode_bitwise_module_info,
6061
&__com_livecode_byte_module_info,
6162
&__com_livecode_char_module_info,
63+
&__com_livecode_codeunit_module_info,
6264
&__com_livecode_date_module_info,
6365
//&__com_livecode_encoding_module_info,
6466
&__com_livecode_file_module_info,
@@ -87,6 +89,7 @@ extern "C"
8789
extern void (*MCBitwiseEvalBitwiseAnd)();
8890
extern void (*MCByteEvalNumberOfBytesIn)();
8991
extern void (*MCCharEvalNumberOfCharsIn)();
92+
extern void (*MCCodeunitEvalNumberOfCodeunitsIn)();
9093
extern void (*MCDateExecGetLocalTime)();
9194
extern void (*MCFileExecGetContents)();
9295
extern void (*MCListEvalHeadOf)();
@@ -111,6 +114,7 @@ extern "C"
111114
&MCBitwiseEvalBitwiseAnd,
112115
&MCByteEvalNumberOfBytesIn,
113116
&MCCharEvalNumberOfCharsIn,
117+
&MCCodeunitEvalNumberOfCodeunitsIn,
114118
&MCDateExecGetLocalTime,
115119
&MCFileExecGetContents,
116120
&MCListEvalHeadOf,

0 commit comments

Comments
 (0)