String.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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.prototype.__get_contents = function() {
  11. var retVal = new string()
  12. retVal.__ptr = Polycode.String__get_contents(this.__ptr)
  13. return retVal
  14. }
  15. String.prototype.__set_contents = function(val) {
  16. Polycode.String__set_contents(this.__ptr, val.__ptr)
  17. }
  18. String.prototype.__get_w_contents = function() {
  19. var retVal = new wstring()
  20. retVal.__ptr = Polycode.String__get_w_contents(this.__ptr)
  21. return retVal
  22. }
  23. String.prototype.__set_w_contents = function(val) {
  24. Polycode.String__set_w_contents(this.__ptr, val.__ptr)
  25. }
  26. Duktape.fin(String.prototype, function (x) {
  27. if (x === String.prototype) {
  28. return;
  29. }
  30. Polycode.String__delete(x.__ptr)
  31. })
  32. String.prototype.size = function() {
  33. var retVal = new size_t()
  34. retVal.__ptr = Polycode.String_size(this.__ptr)
  35. return retVal
  36. }
  37. String.prototype.length = function() {
  38. var retVal = new size_t()
  39. retVal.__ptr = Polycode.String_length(this.__ptr)
  40. return retVal
  41. }
  42. String.prototype.substr = function(pos,n) {
  43. return Polycode.String_substr(this.__ptr, pos, n)
  44. }
  45. String.prototype.rfind = function(str,pos) {
  46. var retVal = new size_t()
  47. retVal.__ptr = Polycode.String_rfind(this.__ptr, str, pos)
  48. return retVal
  49. }
  50. String.prototype.find = function(str,pos) {
  51. var retVal = new size_t()
  52. retVal.__ptr = Polycode.String_find(this.__ptr, str, pos)
  53. return retVal
  54. }
  55. String.prototype.find_last_of = function(str,pos) {
  56. var retVal = new size_t()
  57. retVal.__ptr = Polycode.String_find_last_of(this.__ptr, str, pos)
  58. return retVal
  59. }
  60. String.prototype.find_first_of = function(str,pos) {
  61. var retVal = new size_t()
  62. retVal.__ptr = Polycode.String_find_first_of(this.__ptr, str, pos)
  63. return retVal
  64. }
  65. String.prototype.find_first_not_of = function(str,pos) {
  66. var retVal = new size_t()
  67. retVal.__ptr = Polycode.String_find_first_not_of(this.__ptr, str, pos)
  68. return retVal
  69. }
  70. String.prototype.toLowerCase = function() {
  71. return Polycode.String_toLowerCase(this.__ptr)
  72. }
  73. String.prototype.toUpperCase = function() {
  74. return Polycode.String_toUpperCase(this.__ptr)
  75. }
  76. String.prototype.split = function(delim) {
  77. Polycode.String_split(this.__ptr, delim)
  78. }
  79. String.prototype.replace = function(what,withWhat) {
  80. return Polycode.String_replace(this.__ptr, what, withWhat)
  81. }
  82. String.prototype.NumberToString = function(value,precision) {
  83. return Polycode.String_NumberToString(value, precision)
  84. }
  85. String.prototype.toNumber = function() {
  86. return Polycode.String_toNumber(this.__ptr)
  87. }
  88. String.prototype.toInteger = function() {
  89. return Polycode.String_toInteger(this.__ptr)
  90. }
  91. String.prototype.IntToString = function(value) {
  92. return Polycode.String_IntToString(value)
  93. }
  94. String.prototype.c_str = function() {
  95. var retVal = new char()
  96. retVal.__ptr = Polycode.String_c_str(this.__ptr)
  97. return retVal
  98. }
  99. String.prototype.getDataWithEncoding = function(encoding) {
  100. var retVal = new char()
  101. retVal.__ptr = Polycode.String_getDataWithEncoding(this.__ptr, encoding)
  102. return retVal
  103. }
  104. String.prototype.getWDataWithEncoding = function(encoding) {
  105. var retVal = new wchar_t()
  106. retVal.__ptr = Polycode.String_getWDataWithEncoding(this.__ptr, encoding)
  107. return retVal
  108. }
  109. String.prototype.append = function(c) {
  110. Polycode.String_append(this.__ptr, c)
  111. }
  112. String.prototype.getDataSizeWithEncoding = function(encoding) {
  113. var retVal = new size_t()
  114. retVal.__ptr = Polycode.String_getDataSizeWithEncoding(this.__ptr, encoding)
  115. return retVal
  116. }
  117. String.prototype.setDataWithEncoding = function(data,encoding) {
  118. Polycode.String_setDataWithEncoding(this.__ptr, data.__ptr, encoding)
  119. }
  120. String.prototype.isNumber = function() {
  121. return Polycode.String_isNumber(this.__ptr)
  122. }
  123. String.prototype.isInteger = function() {
  124. return Polycode.String_isInteger(this.__ptr)
  125. }