1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package python.internal;
- import python.lib.Builtin;
- @:keep
- @:native("HxString")
- class StringImpl {
- public static function split (s:String, d:String) {
- return if (d == "") Builtin.list(s) else Macros.callField(s, "split", d);
- }
- public static function charCodeAt(s:String, index:Int) {
- return if (s == null || s.length == 0 || index < 0 || index >= s.length) null else untyped ord(untyped __python_array_get__(s, index));
- }
- public static inline function charAt(s:String, index:Int) {
- return if (index < 0 || index >= s.length) "" else untyped __python_array_get__(s,index);
- }
- public static inline function lastIndexOf(s:String, str:String, ?startIndex:Int):Int {
- if (startIndex == null) {
- return (untyped s.rfind)(str, 0, s.length);
- } else {
- var i = (untyped s.rfind)(str, 0, startIndex+1);
- var startLeft = i == -1 ? Math.max(0,startIndex+1-str.length) : i+1;
- var check = (untyped s.find)(str, startLeft, s.length);
- if (check > i && check <= startIndex) {
- return check;
- } else {
- return i;
- }
- }
- }
- public static function toUpperCase (s:String) {
- return Macros.callField(s, "upper");
- }
- public static function toLowerCase (s:String) {
- return Macros.callField(s, "lower");
- }
- public static function indexOf (s:String, str:String, ?startIndex:Int) {
- if (startIndex == null)
- return Macros.callField(s, "find", str);
- else
- return Macros.callField(s, "find", str, startIndex);
- }
- public static function substr (s:String, pos:Int, ?len:Int) {
- return python.Tools.substr(s, pos, len);
- }
- public static function toString (s:String) {
- return s;
- }
- public static function get_length (s:String) {
- return python.lib.Builtin.len(s);
- }
- public static function substring (s:String, startIndex:Int, ?endIndex:Int) {
- return python.Tools.substring(s, startIndex, endIndex);
- }
- public static inline function fromCharCode( code : Int ) : String {
- #if doc_gen
- return "";
- #else
- var c = code;
- return (untyped (''.join)(Builtin.map(Builtin.chr, cast [c])):String); // TODO: check cast
- #end
- }
- }
|