mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Luaj: Use substring.m_bytes, not substring.getBytes() [#735]
This commit is contained in:
parent
35f2027b20
commit
398a1c854a
@ -1,6 +1,6 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
@ -13,13 +13,15 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.objects.strings.char_sources; import gplx.*; import gplx.objects.*; import gplx.objects.strings.*;
|
||||
package gplx.objects.strings.char_sources;
|
||||
|
||||
public interface Char_source {
|
||||
String Src();
|
||||
int Get_data(int pos);
|
||||
int Len_in_data();
|
||||
|
||||
String Substring(int bgn, int end);
|
||||
byte[] SubstringAsBry(int bgn, int end);
|
||||
int Index_of(Char_source find, int bgn);
|
||||
boolean Eq(int lhs_bgn, Char_source rhs, int rhs_bgn, int rhs_end);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
Copyright (C) 2012-2020 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
@ -13,10 +13,11 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.objects.strings.unicodes; import gplx.*; import gplx.objects.*; import gplx.objects.strings.*;
|
||||
import gplx.objects.errs.*;
|
||||
import gplx.objects.brys.*;
|
||||
import gplx.objects.strings.char_sources.*;
|
||||
package gplx.objects.strings.unicodes;
|
||||
|
||||
import gplx.objects.errs.Err_;
|
||||
import gplx.objects.strings.String_;
|
||||
import gplx.objects.strings.char_sources.Char_source;
|
||||
|
||||
public interface Ustring extends Char_source {
|
||||
int Len_in_chars();
|
||||
@ -32,6 +33,14 @@ class Ustring_single implements Ustring { // 1 char == 1 codepoint
|
||||
public int Len_in_chars() {return src_len;} private final int src_len;
|
||||
public int Len_in_data() {return src_len;}
|
||||
public String Substring(int bgn, int end) {return src.substring(bgn, end);}
|
||||
public byte[] SubstringAsBry(int bgn, int end) {
|
||||
String rv = src.substring(bgn, end);
|
||||
try {
|
||||
return rv.getBytes("UTF-8");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("failed to get bytes; src=" + src);
|
||||
}
|
||||
}
|
||||
public int Index_of(Char_source find, int bgn) {return src.indexOf(find.Src(), bgn);}
|
||||
public boolean Eq(int lhs_bgn, Char_source rhs, int rhs_bgn, int rhs_end) {
|
||||
if (src_len < lhs_bgn + rhs_end || rhs.Len_in_data() < rhs_bgn + rhs_end)
|
||||
@ -90,6 +99,14 @@ class Ustring_codepoints implements Ustring {
|
||||
}
|
||||
return new String(rv);
|
||||
}
|
||||
public byte[] SubstringAsBry(int bgn, int end) {
|
||||
String rv = src.substring(bgn, end);
|
||||
try {
|
||||
return rv.getBytes("UTF-8");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("failed to get bytes; src=" + src);
|
||||
}
|
||||
}
|
||||
public int Index_of(Char_source find, int bgn) {
|
||||
int find_len = find.Len_in_data();
|
||||
int codes_len = codes.length;
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user