Skip to content

Commit a6d55bf

Browse files
committed
fix #524: Convert strings to lowercase in string contains
Closes #524
1 parent 9cb6c15 commit a6d55bf

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/engine/virtualmachine_p.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,14 @@ unsigned int *VirtualMachinePrivate::run(unsigned int *pos, bool reset)
764764
DISPATCH();
765765

766766
OP(STR_CONTAINS) :
767-
REPLACE_RET_VALUE(READ_REG(0, 2)->toUtf16().find(READ_REG(1, 2)->toUtf16()) != std::u16string::npos, 2);
768-
FREE_REGS(1);
767+
{
768+
std::u16string string1 = READ_REG(0, 2)->toUtf16();
769+
std::u16string string2 = READ_REG(1, 2)->toUtf16();
770+
std::transform(string1.begin(), string1.end(), string1.begin(), ::tolower);
771+
std::transform(string2.begin(), string2.end(), string2.begin(), ::tolower);
772+
REPLACE_RET_VALUE(string1.find(string2) != std::u16string::npos, 2);
773+
FREE_REGS(1);
774+
}
769775
DISPATCH();
770776

771777
OP(EXEC) :

test/virtual_machine/virtual_machine_test.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,25 +1359,28 @@ TEST(VirtualMachineTest, OP_STR_LENGTH)
13591359
TEST(VirtualMachineTest, OP_STR_CONTAINS)
13601360
{
13611361
static unsigned int bytecode[] = {
1362-
OP_START, OP_CONST, 0, OP_CONST, 1, OP_STR_CONTAINS, OP_CONST, 0, OP_CONST, 2, OP_STR_CONTAINS, OP_CONST, 0, OP_CONST, 3,
1363-
OP_STR_CONTAINS, OP_CONST, 0, OP_CONST, 4, OP_STR_CONTAINS, OP_CONST, 0, OP_CONST, 5, OP_STR_CONTAINS, OP_CONST, 0, OP_CONST, 6,
1364-
OP_STR_CONTAINS, OP_CONST, 0, OP_CONST, 7, OP_STR_CONTAINS, OP_CONST, 4, OP_CONST, 4, OP_STR_CONTAINS, OP_HALT
1362+
OP_START, OP_CONST, 0, OP_CONST, 1, OP_STR_CONTAINS, OP_CONST, 0, OP_CONST, 2, OP_STR_CONTAINS, OP_CONST, 0, OP_CONST, 3, OP_STR_CONTAINS, OP_CONST, 0, OP_CONST, 4,
1363+
OP_STR_CONTAINS, OP_CONST, 0, OP_CONST, 5, OP_STR_CONTAINS, OP_CONST, 0, OP_CONST, 6, OP_STR_CONTAINS, OP_CONST, 0, OP_CONST, 7, OP_STR_CONTAINS, OP_CONST, 4, OP_CONST, 4,
1364+
OP_STR_CONTAINS, OP_CONST, 0, OP_CONST, 8, OP_STR_CONTAINS, OP_CONST, 0, OP_CONST, 9, OP_STR_CONTAINS, OP_CONST, 0, OP_CONST, 10, OP_STR_CONTAINS, OP_HALT
13651365
};
1366-
static Value constValues[] = { "abcd efg hijý abcĎĐ", "ĎĐ", "a", "test", "", " ", " ", "k" };
1366+
static Value constValues[] = { "abcd efg hijý abcĎĐ", "ĎĐ", "a", "test", "", " ", " ", "k", "ab", "aB", "AB" };
13671367

13681368
VirtualMachine vm;
13691369
vm.setBytecode(bytecode);
13701370
vm.setConstValues(constValues);
13711371
vm.run();
1372-
ASSERT_EQ(vm.registerCount(), 8);
1373-
ASSERT_EQ(vm.getInput(0, 8)->toBool(), true);
1374-
ASSERT_EQ(vm.getInput(1, 8)->toBool(), true);
1375-
ASSERT_EQ(vm.getInput(2, 8)->toBool(), false);
1376-
ASSERT_EQ(vm.getInput(3, 8)->toBool(), true);
1377-
ASSERT_EQ(vm.getInput(4, 8)->toBool(), true);
1378-
ASSERT_EQ(vm.getInput(5, 8)->toBool(), true);
1379-
ASSERT_EQ(vm.getInput(6, 8)->toBool(), false);
1380-
ASSERT_EQ(vm.getInput(7, 8)->toBool(), true);
1372+
ASSERT_EQ(vm.registerCount(), 11);
1373+
ASSERT_EQ(vm.getInput(0, 11)->toBool(), true);
1374+
ASSERT_EQ(vm.getInput(1, 11)->toBool(), true);
1375+
ASSERT_EQ(vm.getInput(2, 11)->toBool(), false);
1376+
ASSERT_EQ(vm.getInput(3, 11)->toBool(), true);
1377+
ASSERT_EQ(vm.getInput(4, 11)->toBool(), true);
1378+
ASSERT_EQ(vm.getInput(5, 11)->toBool(), true);
1379+
ASSERT_EQ(vm.getInput(6, 11)->toBool(), false);
1380+
ASSERT_EQ(vm.getInput(7, 11)->toBool(), true);
1381+
ASSERT_EQ(vm.getInput(8, 11)->toBool(), true);
1382+
ASSERT_EQ(vm.getInput(9, 11)->toBool(), true);
1383+
ASSERT_EQ(vm.getInput(10, 11)->toBool(), true);
13811384
}
13821385

13831386
unsigned int testFunction1(VirtualMachine *vm)

0 commit comments

Comments
 (0)