Skip to content

Commit f863b02

Browse files
author
Monte Goulding
authored
Merge pull request livecode#4291 from montegoulding/tokenoffset
Complete tokenOffset implementation
2 parents 3d9e68a + b49362f commit f863b02

5 files changed

Lines changed: 42 additions & 1 deletion

File tree

engine/src/funcs.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,15 @@ class MCByteOffset : public MCChunkOffset
454454
}
455455
};
456456

457+
class MCTokenOffset : public MCChunkOffset
458+
{
459+
public:
460+
MCTokenOffset()
461+
{
462+
delimiter = CT_TOKEN;
463+
}
464+
};
465+
457466
class MCClickChar : public MCConstantFunctionCtxt<MCStringRef, MCInterfaceEvalClickChar>
458467
{
459468
public:

engine/src/lextable.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,7 @@ LT factor_table[] =
17281728
{"to", TT_TO, PT_TO},
17291729
{"togglehilites", TT_PROPERTY, P_TOGGLE_HILITE},
17301730
{"token", TT_CHUNK, CT_TOKEN},
1731+
{"tokenoffset", TT_FUNCTION, F_TOKEN_OFFSET},
17311732
{"tokens", TT_CLASS, CT_TOKEN},
17321733
{"tolower", TT_FUNCTION, F_TO_LOWER},
17331734
{"tool", TT_PROPERTY, P_TOOL},

engine/src/newobj.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,9 @@ MCExpression *MCN_new_function(int2 which)
788788
return new MCTicks;
789789
case F_TIME:
790790
return new MCTheTime;
791-
case F_TOP_STACK:
791+
case F_TOKEN_OFFSET:
792+
return new MCTokenOffset;
793+
case F_TOP_STACK:
792794
return new MCTopStack;
793795
case F_TO_LOWER:
794796
return new MCToLower;

engine/src/parsedef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ enum Functions {
554554
F_TIME,
555555
F_TO_LOWER,
556556
F_TO_UPPER,
557+
F_TOKEN_OFFSET,
557558
F_TOP_STACK,
558559
F_TRANSPOSE,
559560
F_TRUEWORD_OFFSET,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
script "CoreStringTokenOffset"
2+
/*
3+
Copyright (C) 2016 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 TestTokenOffset
20+
local tNeedle, tHaystack
21+
put "put" && quote & "foo" & quote & "&" & quote & "bar" & quote && "into tVar" into tHaystack
22+
23+
local tToken = 1
24+
repeat for each token tNeedle in "put foo & bar into tVar"
25+
TestAssert "tokenoffset" && tNeedle && "in string", tokenOffset(tNeedle, tHaystack) is tToken
26+
add 1 to tToken
27+
end repeat
28+
end TestTokenOffset

0 commit comments

Comments
 (0)