Std.hx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C)2005-2012 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. #if !(core_api || cross)
  23. #error "Please don't add haxe/std to your classpath, instead set HAXE_STD_PATH env var"
  24. #end
  25. /**
  26. The Std class provides standard methods for manipulating basic types.
  27. **/
  28. extern class Std {
  29. /**
  30. Tells if a value v is of the type t. Returns false if v or t are null.
  31. **/
  32. public static function is( v : Dynamic, t : Dynamic ) : Bool;
  33. /**
  34. Converts any value to a String.
  35. If s is of String, Int, Float or Bool, its value is returned.
  36. If s is an instance of a class and that class or one of its parent classes has
  37. a toString() method, that method is called. If no such method is present, the result
  38. is unspecified.
  39. If s is an enum constructor without argument, the constructor's name is returned. If
  40. arguments exists, the constructor's name followed by the String representations of
  41. the arguments is returned.
  42. If s is a structure, the field names along with their values are returned. The field order
  43. and the operator separating field names and values are unspecified.
  44. If s is null, "null" is returned.
  45. **/
  46. public static function string( s : Dynamic ) : String;
  47. /**
  48. Converts a Float to an Int, rounded towards 0.
  49. If x is outside of the signed Int32 range, or is NaN, NEGATIVE_INFINITY or POSITIVE_INFINITY, the result is unspecified.
  50. **/
  51. public static function int( x : Float ) : Int;
  52. /**
  53. Converts a String to an Int.
  54. Leading whitespaces are ignored.
  55. If x starts with 0x or 0X, hexadecimal notation is recognized where the following digits may
  56. contain 0-9 and A-F.
  57. Otherwise x is read as decimal number with 0-9 being allowed characters. x may also start with
  58. a - to denote a negative value.
  59. In decimal mode, parsing continues until an invalid character is detected, in which case the
  60. result up to that point is returned. For hexadecimal notation, the effect of invalid characters
  61. is unspecified.
  62. Leading 0s that are not part of the 0x/0X hexadecimal notation are ignored, which means octal
  63. notation is not supported.
  64. If the input cannot be recognized, the result is null.
  65. **/
  66. public static function parseInt( x : String ) : Null<Int>;
  67. /**
  68. Converts a String to a Float.
  69. The parsing rules for parseInt() apply here as well, with the exception of invalid input
  70. resulting in a NaN value instead of null.
  71. Additionally, decimal notation may contain a single . to denote the start of the fractions.
  72. **/
  73. public static function parseFloat( x : String ) : Float;
  74. /**
  75. Return a random integer between 0 included and x excluded.
  76. If x is <= 1, the result is always 0.
  77. **/
  78. public static function random( x : Int ) : Int;
  79. }