mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-09-28 14:30:51 +00:00
Scribunto: Adjust index position correctly for ucs-2 strings [#506]
This commit is contained in:
parent
0bfacb2ea5
commit
e3dce04680
@ -82,16 +82,13 @@ public class Scrib_lib_ustring implements Scrib_lib {
|
||||
if (plain) {
|
||||
// find pos by literal match
|
||||
Ustring find_ucs = Ustring_.New_codepoints(find_str);
|
||||
int pos = String_.FindFwd(text_str, find_str, bgn_as_codes);
|
||||
int pos = text_ucs.Index_of(find_ucs, bgn_as_codes);
|
||||
|
||||
// if nothing found, return empty
|
||||
if (pos == String_.Find_none)
|
||||
return rslt.Init_ary_empty();
|
||||
// else, convert char_idx to code_idx
|
||||
else
|
||||
pos = text_ucs.Map_char_to_data(pos);
|
||||
|
||||
// bgn: convert pos from bytes back to codes; also adjust for base1
|
||||
// bgn: adjust for base1
|
||||
int bgn = pos + Base1;
|
||||
|
||||
// end: add find.Len_in_codes and adjust end for PHP/LUA
|
||||
|
@ -28,6 +28,9 @@ public class Scrib_lib_ustring__find__tst {
|
||||
fxt.Test__find("abcd" , "" , 2, Bool_.Y, "2;1"); // empty find should return values; EX:w:Fool's_mate; DATE:2014-03-04
|
||||
fxt.Test__find("a€b" , "€" , 1, Bool_.Y, "2;2"); // find is bytes=3
|
||||
}
|
||||
@Test public void Plain_u8() {
|
||||
fxt.Test__find("𤭢-a-" , "-" , 3, Bool_.Y, "4;4"); // starts at cp=3 which should be a, not 1st dash; ISSUE#:506; DATE:2019-06-30
|
||||
}
|
||||
@Test public void Bgn__negative() {
|
||||
fxt.Test__find("abab" , "b" , -1, Bool_.Y, "4;4"); // search from back of String
|
||||
fxt.Test__find("abab" , "b" , -9, Bool_.Y, "2;2"); // do not throw error if negative index > text.length; ISSUE#:366; DATE:2019-02-23
|
||||
|
Loading…
Reference in New Issue
Block a user