String.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. function String() {
  2. Object.defineProperties(this, {
  3. 'contents': { enumerable: true, configurable: true, get: String.prototype.__get_contents, set: String.prototype.__set_contents},
  4. 'w_contents': { enumerable: true, configurable: true, get: String.prototype.__get_w_contents, set: String.prototype.__set_w_contents}
  5. })
  6. }
  7. String.prototype.__get_contents = function() {
  8. var retVal = new string()
  9. retVal.__ptr = Polycode.String__get_contents(this.__ptr)
  10. return retVal
  11. }
  12. String.prototype.__set_contents = function(val) {
  13. Polycode.String__set_contents(this.__ptr, val.__ptr)
  14. }
  15. String.prototype.__get_w_contents = function() {
  16. var retVal = new wstring()
  17. retVal.__ptr = Polycode.String__get_w_contents(this.__ptr)
  18. return retVal
  19. }
  20. String.prototype.__set_w_contents = function(val) {
  21. Polycode.String__set_w_contents(this.__ptr, val.__ptr)
  22. }
  23. Duktape.fin(String.prototype, function (x) {
  24. if (x === String.prototype) {
  25. return;
  26. }
  27. Polycode.String__delete(x.__ptr)
  28. })
  29. String.prototype.size = function() {
  30. var retVal = new size_t()
  31. retVal.__ptr = Polycode.String_size(this.__ptr)
  32. return retVal
  33. }
  34. String.prototype.length = function() {
  35. var retVal = new size_t()
  36. retVal.__ptr = Polycode.String_length(this.__ptr)
  37. return retVal
  38. }
  39. String.prototype.substr = function(pos,n) {
  40. return Polycode.String_substr(this.__ptr, pos,n)
  41. }
  42. String.prototype.rfind = function(str,pos) {
  43. var retVal = new size_t()
  44. retVal.__ptr = Polycode.String_rfind(this.__ptr, str,pos)
  45. return retVal
  46. }
  47. String.prototype.find = function(str,pos) {
  48. var retVal = new size_t()
  49. retVal.__ptr = Polycode.String_find(this.__ptr, str,pos)
  50. return retVal
  51. }
  52. String.prototype.find_last_of = function(str,pos) {
  53. var retVal = new size_t()
  54. retVal.__ptr = Polycode.String_find_last_of(this.__ptr, str,pos)
  55. return retVal
  56. }
  57. String.prototype.find_first_of = function(str,pos) {
  58. var retVal = new size_t()
  59. retVal.__ptr = Polycode.String_find_first_of(this.__ptr, str,pos)
  60. return retVal
  61. }
  62. String.prototype.toLowerCase = function() {
  63. return Polycode.String_toLowerCase(this.__ptr)
  64. }
  65. String.prototype.toUpperCase = function() {
  66. return Polycode.String_toUpperCase(this.__ptr)
  67. }
  68. String.prototype.split = function(delim) {
  69. Polycode.String_split(this.__ptr, delim)
  70. }
  71. String.prototype.replace = function(what,withWhat) {
  72. return Polycode.String_replace(this.__ptr, what,withWhat)
  73. }
  74. String.prototype.toNumber = function() {
  75. return Polycode.String_toNumber(this.__ptr)
  76. }
  77. String.prototype.toInteger = function() {
  78. return Polycode.String_toInteger(this.__ptr)
  79. }
  80. String.prototype.c_str = function() {
  81. var retVal = new char()
  82. retVal.__ptr = Polycode.String_c_str(this.__ptr)
  83. return retVal
  84. }
  85. String.prototype.getDataWithEncoding = function(encoding) {
  86. var retVal = new char()
  87. retVal.__ptr = Polycode.String_getDataWithEncoding(this.__ptr, encoding)
  88. return retVal
  89. }
  90. String.prototype.getWDataWithEncoding = function(encoding) {
  91. var retVal = new wchar_t()
  92. retVal.__ptr = Polycode.String_getWDataWithEncoding(this.__ptr, encoding)
  93. return retVal
  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()
  100. retVal.__ptr = Polycode.String_getDataSizeWithEncoding(this.__ptr, encoding)
  101. return retVal
  102. }
  103. String.prototype.setDataWithEncoding = function(data,encoding) {
  104. Polycode.String_setDataWithEncoding(this.__ptr, data,encoding)
  105. }
  106. String.prototype.isNumber = function() {
  107. return Polycode.String_isNumber(this.__ptr)
  108. }