Skip to content

Commit d2f694a

Browse files
committed
Merge pull request livecode#3491 from livecodeali/bugfix-16303
[[ Bug 16303 ]] Fix trueWord chunk evaluation
2 parents 6bfd45e + fb0a7f5 commit d2f694a

File tree

3 files changed

+67
-7
lines changed

3 files changed

+67
-7
lines changed

docs/notes/bugfix-16303.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Ensure trueWord chunk expressions resolve correctly

libfoundation/src/foundation-chunk.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -816,14 +816,14 @@ MCTextChunkIterator_ICU::MCTextChunkIterator_ICU(MCStringRef p_text, MCChunkType
816816
MCAutoArray<uindex_t> t_breaks;
817817
/* UNCHECKED */ MCLocaleBreakIteratorCreate(kMCLocaleBasic, kMCBreakIteratorTypeWord, break_iterator);
818818
/* UNCHECKED */ MCLocaleBreakIteratorSetText(break_iterator, *t_substring);
819-
MCRange t_range;
820-
t_range . length = p_restriction . length;
821-
t_range . offset = p_restriction . offset;
822-
823-
while (MCLocaleWordBreakIteratorAdvance(*t_substring, break_iterator, t_range)
824-
&& t_range . offset + t_range . length != kMCLocaleBreakIteratorDone)
819+
MCRange t_rel_range;
820+
t_rel_range = MCRangeMake(0, 0);
821+
822+
while (MCLocaleWordBreakIteratorAdvance(*t_substring, break_iterator, t_rel_range)
823+
&& t_rel_range . offset + t_rel_range . length != kMCLocaleBreakIteratorDone)
825824
{
826-
m_breaks . Push(t_range);
825+
m_breaks . Push(MCRangeMake(t_rel_range . offset + p_restriction . offset,
826+
t_rel_range . length + p_restriction . length));
827827
}
828828
}
829829
break;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
script "CoreChunksTrueWord"
2+
/*
3+
Copyright (C) 2015 LiveCode Ltd.
4+
5+
This file is part of LiveCode.
6+
7+
LiveCode is free software; you can redistribute it and/or modify it under
8+
the terms of the GNU General Public License v3 as published by the Free
9+
Software Foundation.
10+
11+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
12+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
18+
19+
on TestTrueWordRanges
20+
TestAssert "overlong prefix", trueWord -4 to -2 of "three trueWord sentence" is "three trueWord"
21+
TestAssert "overlong suffix", trueWord 2 to 4 of "three trueWord sentence" is "trueWord sentence"
22+
end TestTrueWordRanges
23+
24+
on TestTrueWordRangesEmpty
25+
TestAssert "empty prefix", trueWord -5 to -4 of "three trueWord sentence" is ""
26+
TestAssert "empty suffix", trueWord 4 to 5 of "three trueWord sentence" is ""
27+
TestAssert "empty range", trueWord 5 to 4 of "three trueWord sentence" is ""
28+
end TestTrueWordRangesEmpty
29+
30+
on TestTrueWordRangesSingle
31+
TestAssert "single trueWord range", trueWord 1 to 1 of "three trueWord sentence" is "three"
32+
TestAssert "single trueWord range from back", trueWord -2 to -2 of "three trueWord sentence" is "trueWord"
33+
end TestTrueWordRangesSingle
34+
35+
on TestTrueWordExpressions
36+
TestAssert "single trueWord", trueWord 1 of "three trueWord sentence" is "three"
37+
TestAssert "single trueWord from back", trueWord -3 of "three trueWord sentence" is "three"
38+
end TestTrueWordExpressions
39+
40+
on TestTrueWordExpressionsEmpty
41+
TestAssert "single trueWord", trueWord 4 of "three trueWord sentence" is ""
42+
TestAssert "single trueWord", trueWord -4 of "three trueWord sentence" is ""
43+
end TestTrueWordExpressionsEmpty
44+
45+
on TestTrueWordLineBreakCount
46+
TestAssert "count with line break", the number of trueWords in ("one" & return & "two") is 2
47+
end TestTrueWordLineBreakCount
48+
49+
on TestTrueWordLineBreakExpression
50+
TestAssert "single trueWord", trueWord 2 of ("one" & return & "two") is "two"
51+
end TestTrueWordLineBreakExpression
52+
53+
on TestTrueWordCount
54+
TestAssert "count", the number of trueWords in "three trueWord sentence" is 3
55+
end TestTrueWordCount
56+
57+
on TestLastTrueWord
58+
TestAssert "last trueWord", the last trueWord of "three trueWord sentence" is "sentence"
59+
end TestLastTrueWord

0 commit comments

Comments
 (0)