String.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. function String() {
  2. if(arguments[0] != "__skip_ptr__") {
  3. this.__ptr = Polycode.String()
  4. }
  5. Object.defineProperties(this, {
  6. 'contents': { enumerable: true, configurable: true, get: String.prototype.__get_contents, set: String.prototype.__set_contents},
  7. 'w_contents': { enumerable: true, configurable: true, get: String.prototype.__get_w_contents, set: String.prototype.__set_w_contents}
  8. })
  9. }
  10. String.ENCODING_UTF8 = 0
  11. String.prototype.__get_contents = function() {
  12. var retVal = new string("__skip_ptr__")
  13. retVal.__ptr = Polycode.String__get_contents(this.__ptr)
  14. return retVal
  15. }
  16. String.prototype.__set_contents = function(val) {
  17. Polycode.String__set_contents(this.__ptr, val.__ptr)
  18. }
  19. String.prototype.__get_w_contents = function() {
  20. var retVal = new wstring("__skip_ptr__")
  21. retVal.__ptr = Polycode.String__get_w_contents(this.__ptr)
  22. return retVal
  23. }
  24. String.prototype.__set_w_contents = function(val) {
  25. Polycode.String__set_w_contents(this.__ptr, val.__ptr)
  26. }
  27. Duktape.fin(String.prototype, function (x) {
  28. if (x === String.prototype) {
  29. return;
  30. }
  31. Polycode.String__delete(x.__ptr)
  32. })
  33. String.prototype.size = function() {
  34. var retVal = new size_t("__skip_ptr__")
  35. retVal.__ptr = Polycode.String_size(this.__ptr)
  36. return retVal
  37. }
  38. String.prototype.length = function() {
  39. var retVal = new size_t("__skip_ptr__")
  40. retVal.__ptr = Polycode.String_length(this.__ptr)
  41. return retVal
  42. }
  43. String.prototype.substr = function(pos,n) {
  44. return Polycode.String_substr(this.__ptr, pos, n)
  45. }
  46. String.prototype.rfind = function(str,pos) {
  47. var retVal = new size_t("__skip_ptr__")
  48. retVal.__ptr = Polycode.String_rfind(this.__ptr, str, pos)
  49. return retVal
  50. }
  51. String.prototype.find = function(str,pos) {
  52. var retVal = new size_t("__skip_ptr__")
  53. retVal.__ptr = Polycode.String_find(this.__ptr, str, pos)
  54. return retVal
  55. }
  56. String.prototype.find_last_of = function(str,pos) {
  57. var retVal = new size_t("__skip_ptr__")
  58. retVal.__ptr = Polycode.String_find_last_of(this.__ptr, str, pos)
  59. return retVal
  60. }
  61. String.prototype.find_first_of = function(str,pos) {
  62. var retVal = new size_t("__skip_ptr__")
  63. retVal.__ptr = Polycode.String_find_first_of(this.__ptr, str, pos)
  64. return retVal
  65. }
  66. String.prototype.find_first_not_of = function(str,pos) {
  67. var retVal = new size_t("__skip_ptr__")
  68. retVal.__ptr = Polycode.String_find_first_not_of(this.__ptr, str, pos)
  69. return retVal
  70. }
  71. String.prototype.toLowerCase = function() {
  72. return Polycode.String_toLowerCase(this.__ptr)
  73. }
  74. String.prototype.toUpperCase = function() {
  75. return Polycode.String_toUpperCase(this.__ptr)
  76. }
  77. String.prototype.split = function(delim) {
  78. Polycode.String_split(this.__ptr, delim)
  79. }
  80. String.prototype.replace = function(what,withWhat) {
  81. return Polycode.String_replace(this.__ptr, what, withWhat)
  82. }
  83. String.prototype.NumberToString = function(value,precision) {
  84. return Polycode.String_NumberToString(value, precision)
  85. }
  86. String.prototype.toNumber = function() {
  87. return Polycode.String_toNumber(this.__ptr)
  88. }
  89. String.prototype.toInteger = function() {
  90. return Polycode.String_toInteger(this.__ptr)
  91. }
  92. String.prototype.IntToString = function(value) {
  93. return Polycode.String_IntToString(value)
  94. }
  95. String.prototype.append = function(c) {
  96. Polycode.String_append(this.__ptr, c)
  97. }
  98. String.prototype.getDataSizeWithEncoding = function(encoding) {
  99. var retVal = new size_t("__skip_ptr__")
  100. retVal.__ptr = Polycode.String_getDataSizeWithEncoding(this.__ptr, encoding)
  101. return retVal
  102. }
  103. String.prototype.isNumber = function() {
  104. return Polycode.String_isNumber(this.__ptr)
  105. }
  106. String.prototype.isInteger = function() {
  107. return Polycode.String_isInteger(this.__ptr)
  108. }