Tools.hx 741 B

123456789101112131415161718192021222324252627282930313233343536
  1. package python;
  2. class Tools {
  3. public static function substring( s:String, startIndex : Int, ?endIndex : Int ) : String {
  4. if (startIndex < 0) startIndex = 0;
  5. if (endIndex == null) {
  6. return untyped __python__("s[startIndex:]");
  7. } else {
  8. if (endIndex < 0) endIndex = 0;
  9. if (endIndex < startIndex) {
  10. return untyped __python__("s[endIndex:startIndex]");
  11. } else {
  12. return untyped __python__("s[startIndex:endIndex]");
  13. }
  14. }
  15. }
  16. public static function substr( s:String, startIndex : Int, ?len : Int ) : String {
  17. if (len == null) {
  18. return untyped __python__("s[startIndex:]");
  19. } else {
  20. if (len == 0) return "";
  21. return untyped __python__("s[startIndex:startIndex+len]");
  22. }
  23. }
  24. }