Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,51 +101,12 @@ protected void evaluate(TaggedValuePointable[] args, IPointable result) throws S
// TODO use the third value as collation

// Only need to run comparisons if they both have a non empty string.
if (stringp1.getUTF8Length() > 0 && stringp2.getUTF8Length() > 0) {
int c2 = charIterator2.next();
while (true) {
int c1 = charIterator1.next();
if (c1 == c2) {
int offset1 = charIterator1.getByteOffset();

// Check substring.
if (checkSubString(charIterator1, charIterator2)) {
booleanResult[1] = 1;
break;
}

// Reset for strings for continuation.
charIterator2.reset();
c2 = charIterator2.next();
charIterator1.setByteOffset(offset1);
}
if (c1 == ICharacterIterator.EOS_CHAR) {
// End of string and no match found.
break;
}
}
} else if (stringp2.getUTF8Length() == 0) {
if (stringp1.contains(stringp2, false)) {
booleanResult[1] = 1;
}

result.set(booleanResult, 0, 2);
}

private boolean checkSubString(ICharacterIterator charIterator1, ICharacterIterator charIterator2) {
while (true) {
int c1 = charIterator1.next();
int c2 = charIterator2.next();
if (c2 == ICharacterIterator.EOS_CHAR) {
// End of string.
return true;
}
if (c1 != c2) {
// No match found.
break;
}
}
return false;
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ protected void evaluate(TaggedValuePointable[] args, IPointable result) throws S
}
tvp2.getValue(stringp2);
}
int stringLength1 = stringp1.getStringLength();
int stringLength2 = stringp2.getStringLength();
charIterator1.reset();
charIterator2.reset();

Expand All @@ -105,34 +103,8 @@ protected void evaluate(TaggedValuePointable[] args, IPointable result) throws S
}
// TODO use the third value as collation

int stringCharOffset = stringLength1 - stringLength2;

// Only check if stringp2 can fit into stringp1.
if (stringCharOffset >= 0) {
// Only need to run comparisons if they both have a non empty string.
if (stringLength1 > 0 && stringLength2 > 0) {
// Move string one's cursor for comparison
for (; stringCharOffset > 0; --stringCharOffset) {
charIterator1.next();
}
int c1;
int c2;
while (true) {
c1 = charIterator1.next();
c2 = charIterator2.next();
if (c1 != c2) {
// Characters do not match
break;
}
if (c1 == ICharacterIterator.EOS_CHAR && c2 == ICharacterIterator.EOS_CHAR) {
// Checked the full length of search string.
booleanResult[1] = 1;
break;
}
}
} else if (stringLength2 == 0) {
booleanResult[1] = 1;
}
if (stringp1.endsWith(stringp2, false)) {
booleanResult[1] = 1;
}

result.set(booleanResult, 0, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,7 @@ protected void evaluate(TaggedValuePointable[] args, IPointable result) throws S
// TODO use the third value as collation

// Only need to run comparisons if they both have a non empty string.
if (stringp1.getUTF8Length() > 0 && stringp2.getUTF8Length() > 0) {
int c1;
int c2;
while (true) {
c1 = charIterator1.next();
c2 = charIterator2.next();
if (ICharacterIterator.EOS_CHAR == c2) {
// Checked the full length of search string.
booleanResult[1] = 1;
break;
}
if (c1 != c2) {
// Characters do not match
break;
}
}
} else if (stringp2.getUTF8Length() == 0) {
if (stringp1.startsWith(stringp2, false)) {
booleanResult[1] = 1;
}

Expand Down