Skip to content

Commit a8f7126

Browse files
authored
Merge pull request livecode#6254 from runrevmark/bugfix-20811
[[ Bug 20811 ]] Make 'encoding' analyse the specified range of text
2 parents ac1752a + 5c5db9f commit a8f7126

4 files changed

Lines changed: 60 additions & 9 deletions

File tree

docs/notes/bugfix-20811.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Make the encoding property of field char chunks more useful
2+
3+
The 'encoding' char-level field property will now return native
4+
if all chars in the chunk can be encoded in the native encoding,
5+
and unicode otherwise.
6+
7+
This means that the property will now return the identical value
8+
as it did in 6.7 and before, assuming that the field text hadn't
9+
had its encoding changed by script (via the textFont ',unicode'
10+
flag).

engine/src/exec-interface-field-chunk.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,16 +1786,23 @@ void MCField::SetVisitedOfCharChunk(MCExecContext& ctxt, uint32_t p_part_id, int
17861786
SetCharPropOfCharChunk< PodFieldPropType<bool> >(ctxt, this, false, p_part_id, si, ei, &MCBlock::SetVisited,p_value);
17871787
}
17881788

1789-
void MCField::GetEncodingOfCharChunk(MCExecContext& ctxt, uint32_t p_part_id, int32_t si, int32_t ei, intenum_t &r_encoding)
1789+
void MCField::GetEncodingOfCharChunk(MCExecContext& ctxt, uint32_t p_part_id, int32_t p_start, int32_t p_finish, intenum_t& r_encoding)
17901790
{
1791-
intenum_t t_encoding;
1792-
bool t_mixed;
1793-
GetParagraphPropOfCharChunk< PodFieldPropType<intenum_t> >(ctxt, this, p_part_id, si, ei, &MCParagraph::GetEncoding, t_mixed, t_encoding);
1794-
1795-
if (!t_mixed)
1796-
r_encoding = t_encoding;
1791+
MCAutoStringRef t_value;
1792+
if (!exportastext(p_part_id, p_start, p_finish, &t_value))
1793+
{
1794+
ctxt.Throw();
1795+
return;
1796+
}
1797+
1798+
if (MCStringCanBeNative(*t_value))
1799+
{
1800+
r_encoding = 0;
1801+
}
17971802
else
1798-
r_encoding = 2;
1803+
{
1804+
r_encoding = 1;
1805+
}
17991806
}
18001807

18011808
void MCField::GetFlaggedOfCharChunk(MCExecContext& ctxt, uint32_t p_part_id, int32_t si, int32_t ei, bool& r_mixed, bool& r_value)

engine/src/exec-interface-object.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,6 @@ MCExecEnumTypeElementInfo _kMCInterfaceEncodingElementInfo[] =
11681168
{
11691169
{ MCnativestring, 0, true },
11701170
{ MCunicodestring, 1, true },
1171-
{ MCmixedstring, 2, true },
11721171
};
11731172

11741173
MCExecEnumTypeInfo _kMCInterfaceEncodingTypeInfo =
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
script "CoreFieldEncoding"
2+
/*
3+
Copyright (C) 2018 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 TestEncodingOfCharChunk
20+
create stack "Test"
21+
set the defaultStack to "Test"
22+
23+
create field "TestField"
24+
put "a" & numToCodepoint(0x1d11e) into field "TestField"
25+
26+
TestAssert "encoding of native field chunk is 'native'", \
27+
the encoding of char 1 to 1 of field "TestField" is "native"
28+
29+
TestAssert "encoding of non-native field chunk is 'unicode'", \
30+
the encoding of char 2 to 2 of field "TestField" is "unicode"
31+
32+
TestAssert "encoding of mixed field chunk is 'unicode'", \
33+
the encoding of char 1 to 2 of field "TestField" is "unicode"
34+
35+
end TestEncodingOfCharChunk

0 commit comments

Comments
 (0)