String.lua 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. class "String"
  2. ENCODING_UTF8 = 0
  3. function String:__index__(name)
  4. if name == "contents" then
  5. retVal = Polycore.String_get_contents(self.__ptr)
  6. if Polycore.__ptr_lookup[retVal] ~= nil then
  7. return Polycore.__ptr_lookup[retVal]
  8. else
  9. Polycore.__ptr_lookup[retVal] = wstring("__skip_ptr__")
  10. Polycore.__ptr_lookup[retVal].__ptr = retVal
  11. return Polycore.__ptr_lookup[retVal]
  12. end
  13. elseif name == "s_contents" then
  14. retVal = Polycore.String_get_s_contents(self.__ptr)
  15. if Polycore.__ptr_lookup[retVal] ~= nil then
  16. return Polycore.__ptr_lookup[retVal]
  17. else
  18. Polycore.__ptr_lookup[retVal] = string("__skip_ptr__")
  19. Polycore.__ptr_lookup[retVal].__ptr = retVal
  20. return Polycore.__ptr_lookup[retVal]
  21. end
  22. end
  23. end
  24. function String:__set_callback(name,value)
  25. return false
  26. end
  27. function String:String(...)
  28. for k,v in pairs(arg) do
  29. if type(v) == "table" then
  30. if v.__ptr ~= nil then
  31. arg[k] = v.__ptr
  32. end
  33. end
  34. end
  35. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  36. self.__ptr = Polycore.String(unpack(arg))
  37. Polycore.__ptr_lookup[self.__ptr] = self
  38. end
  39. end
  40. function String:size()
  41. local retVal = Polycore.String_size(self.__ptr)
  42. return retVal
  43. end
  44. function String:length()
  45. local retVal = Polycore.String_length(self.__ptr)
  46. return retVal
  47. end
  48. function String:getSTLString()
  49. local retVal = Polycore.String_getSTLString(self.__ptr)
  50. if Polycore.__ptr_lookup[retVal] ~= nil then
  51. return Polycore.__ptr_lookup[retVal]
  52. else
  53. Polycore.__ptr_lookup[retVal] = string("__skip_ptr__")
  54. Polycore.__ptr_lookup[retVal].__ptr = retVal
  55. return Polycore.__ptr_lookup[retVal]
  56. end
  57. end
  58. function String:getSTLWString()
  59. local retVal = Polycore.String_getSTLWString(self.__ptr)
  60. if Polycore.__ptr_lookup[retVal] ~= nil then
  61. return Polycore.__ptr_lookup[retVal]
  62. else
  63. Polycore.__ptr_lookup[retVal] = wstring("__skip_ptr__")
  64. Polycore.__ptr_lookup[retVal].__ptr = retVal
  65. return Polycore.__ptr_lookup[retVal]
  66. end
  67. end
  68. function String:substr(pos, n)
  69. local retVal = Polycore.String_substr(self.__ptr, pos.__ptr, n.__ptr)
  70. return retVal
  71. end
  72. function String:rfind(str, pos)
  73. local retVal = Polycore.String_rfind(self.__ptr, str.__ptr, pos.__ptr)
  74. return retVal
  75. end
  76. function String:find(str, pos)
  77. local retVal = Polycore.String_find(self.__ptr, str.__ptr, pos.__ptr)
  78. return retVal
  79. end
  80. function String:find_last_of(str, pos)
  81. local retVal = Polycore.String_find_last_of(self.__ptr, str.__ptr, pos.__ptr)
  82. return retVal
  83. end
  84. function String:toLowerCase()
  85. local retVal = Polycore.String_toLowerCase(self.__ptr)
  86. return retVal
  87. end
  88. function String:toUpperCase()
  89. local retVal = Polycore.String_toUpperCase(self.__ptr)
  90. return retVal
  91. end
  92. function String:replace(what, withWhat)
  93. local retVal = Polycore.String_replace(self.__ptr, what.__ptr, withWhat.__ptr)
  94. return retVal
  95. end
  96. function String:NumberToString(value)
  97. local retVal = Polycore.String_NumberToString(value)
  98. return retVal
  99. end
  100. function String:c_str()
  101. local retVal = Polycore.String_c_str(self.__ptr)
  102. if Polycore.__ptr_lookup[retVal] ~= nil then
  103. return Polycore.__ptr_lookup[retVal]
  104. else
  105. Polycore.__ptr_lookup[retVal] = char("__skip_ptr__")
  106. Polycore.__ptr_lookup[retVal].__ptr = retVal
  107. return Polycore.__ptr_lookup[retVal]
  108. end
  109. end
  110. function String:wc_str()
  111. local retVal = Polycore.String_wc_str(self.__ptr)
  112. if Polycore.__ptr_lookup[retVal] ~= nil then
  113. return Polycore.__ptr_lookup[retVal]
  114. else
  115. Polycore.__ptr_lookup[retVal] = wchar_t("__skip_ptr__")
  116. Polycore.__ptr_lookup[retVal].__ptr = retVal
  117. return Polycore.__ptr_lookup[retVal]
  118. end
  119. end
  120. function String:data()
  121. local retVal = Polycore.String_data(self.__ptr)
  122. if Polycore.__ptr_lookup[retVal] ~= nil then
  123. return Polycore.__ptr_lookup[retVal]
  124. else
  125. Polycore.__ptr_lookup[retVal] = wchar_t("__skip_ptr__")
  126. Polycore.__ptr_lookup[retVal].__ptr = retVal
  127. return Polycore.__ptr_lookup[retVal]
  128. end
  129. end
  130. function String:getDataWithEncoding(encoding)
  131. local retVal = Polycore.String_getDataWithEncoding(self.__ptr, encoding)
  132. if Polycore.__ptr_lookup[retVal] ~= nil then
  133. return Polycore.__ptr_lookup[retVal]
  134. else
  135. Polycore.__ptr_lookup[retVal] = char("__skip_ptr__")
  136. Polycore.__ptr_lookup[retVal].__ptr = retVal
  137. return Polycore.__ptr_lookup[retVal]
  138. end
  139. end
  140. function String:getDataSizeWithEncoding(encoding)
  141. local retVal = Polycore.String_getDataSizeWithEncoding(self.__ptr, encoding)
  142. return retVal
  143. end
  144. function String:setDataWithEncoding(data, encoding)
  145. local retVal = Polycore.String_setDataWithEncoding(self.__ptr, data.__ptr, encoding)
  146. end
  147. function String:__delete()
  148. Polycore.__ptr_lookup[self.__ptr] = nil
  149. Polycore.delete_String(self.__ptr)
  150. end