Fix bug 3495802 to return correct offset of substrings from string.find()
This commit is contained in:
@@ -822,6 +822,7 @@ and LuaForge:
|
|||||||
<tr valign="top"><td> <b>3.0-alpha3</b></td><td><ul>
|
<tr valign="top"><td> <b>3.0-alpha3</b></td><td><ul>
|
||||||
<li>Fix bug 3597515 memory leak due to string caching by simplifying caching logic.</li>
|
<li>Fix bug 3597515 memory leak due to string caching by simplifying caching logic.</li>
|
||||||
<li>Fix bug 3565008 so that short substrings are backed by short arrays.</li>
|
<li>Fix bug 3565008 so that short substrings are backed by short arrays.</li>
|
||||||
|
<li>Fix bug 3495802 to return correct offset of substrings from string.find().</li>
|
||||||
|
|
||||||
</ul></td></tr>
|
</ul></td></tr>
|
||||||
</table></td></tr></table>
|
</table></td></tr></table>
|
||||||
|
|||||||
@@ -516,9 +516,9 @@ public class LuaString extends LuaValue {
|
|||||||
*/
|
*/
|
||||||
public int indexOf( LuaString s, int start ) {
|
public int indexOf( LuaString s, int start ) {
|
||||||
final int slen = s.length();
|
final int slen = s.length();
|
||||||
final int limit = m_offset + m_length - slen;
|
final int limit = m_length - slen;
|
||||||
for ( int i = m_offset + start; i <= limit; ++i ) {
|
for ( int i = start; i <= limit; ++i ) {
|
||||||
if ( equals( m_bytes, i, s.m_bytes, s.m_offset, slen ) ) {
|
if ( equals( m_bytes, m_offset + i, s.m_bytes, s.m_offset, slen ) ) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -560,5 +560,14 @@ public class FragmentsTest extends TestSuite {
|
|||||||
runFragment( LuaValue.varargsOf(LuaValue.FALSE, LuaValue.NIL),
|
runFragment( LuaValue.varargsOf(LuaValue.FALSE, LuaValue.NIL),
|
||||||
"return pcall(error)\n");
|
"return pcall(error)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void testFindWithOffset() {
|
||||||
|
runFragment(LuaValue.varargsOf(LuaValue.valueOf(8), LuaValue.valueOf(5)),
|
||||||
|
"string = \"abcdef:ghi\"\n" +
|
||||||
|
"substring = string:sub(3)\n" +
|
||||||
|
"idx = substring:find(\":\")\n" +
|
||||||
|
"return #substring, idx\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user