String.lua 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 retVal == nil then return nil end
  51. if Polycore.__ptr_lookup[retVal] ~= nil then
  52. return Polycore.__ptr_lookup[retVal]
  53. else
  54. Polycore.__ptr_lookup[retVal] = string("__skip_ptr__")
  55. Polycore.__ptr_lookup[retVal].__ptr = retVal
  56. return Polycore.__ptr_lookup[retVal]
  57. end
  58. end
  59. function String:getSTLWString()
  60. local retVal = Polycore.String_getSTLWString(self.__ptr)
  61. if retVal == nil then return nil end
  62. if Polycore.__ptr_lookup[retVal] ~= nil then
  63. return Polycore.__ptr_lookup[retVal]
  64. else
  65. Polycore.__ptr_lookup[retVal] = wstring("__skip_ptr__")
  66. Polycore.__ptr_lookup[retVal].__ptr = retVal
  67. return Polycore.__ptr_lookup[retVal]
  68. end
  69. end
  70. function String:substr(pos, n)
  71. local retVal = Polycore.String_substr(self.__ptr, pos.__ptr, n.__ptr)
  72. return retVal
  73. end
  74. function String:rfind(str, pos)
  75. local retVal = Polycore.String_rfind(self.__ptr, str.__ptr, pos.__ptr)
  76. return retVal
  77. end
  78. function String:find(str, pos)
  79. local retVal = Polycore.String_find(self.__ptr, str.__ptr, pos.__ptr)
  80. return retVal
  81. end
  82. function String:find_last_of(str, pos)
  83. local retVal = Polycore.String_find_last_of(self.__ptr, str.__ptr, pos.__ptr)
  84. return retVal
  85. end
  86. function String:toLowerCase()
  87. local retVal = Polycore.String_toLowerCase(self.__ptr)
  88. return retVal
  89. end
  90. function String:toUpperCase()
  91. local retVal = Polycore.String_toUpperCase(self.__ptr)
  92. return retVal
  93. end
  94. function String:replace(what, withWhat)
  95. local retVal = Polycore.String_replace(self.__ptr, what.__ptr, withWhat.__ptr)
  96. return retVal
  97. end
  98. function String:NumberToString(value)
  99. local retVal = Polycore.String_NumberToString(value)
  100. return retVal
  101. end
  102. function String:c_str()
  103. local retVal = Polycore.String_c_str(self.__ptr)
  104. if retVal == nil then return nil end
  105. if Polycore.__ptr_lookup[retVal] ~= nil then
  106. return Polycore.__ptr_lookup[retVal]
  107. else
  108. Polycore.__ptr_lookup[retVal] = char("__skip_ptr__")
  109. Polycore.__ptr_lookup[retVal].__ptr = retVal
  110. return Polycore.__ptr_lookup[retVal]
  111. end
  112. end
  113. function String:wc_str()
  114. local retVal = Polycore.String_wc_str(self.__ptr)
  115. if retVal == nil then return nil end
  116. if Polycore.__ptr_lookup[retVal] ~= nil then
  117. return Polycore.__ptr_lookup[retVal]
  118. else
  119. Polycore.__ptr_lookup[retVal] = wchar_t("__skip_ptr__")
  120. Polycore.__ptr_lookup[retVal].__ptr = retVal
  121. return Polycore.__ptr_lookup[retVal]
  122. end
  123. end
  124. function String:data()
  125. local retVal = Polycore.String_data(self.__ptr)
  126. if retVal == nil then return nil end
  127. if Polycore.__ptr_lookup[retVal] ~= nil then
  128. return Polycore.__ptr_lookup[retVal]
  129. else
  130. Polycore.__ptr_lookup[retVal] = wchar_t("__skip_ptr__")
  131. Polycore.__ptr_lookup[retVal].__ptr = retVal
  132. return Polycore.__ptr_lookup[retVal]
  133. end
  134. end
  135. function String:getDataWithEncoding(encoding)
  136. local retVal = Polycore.String_getDataWithEncoding(self.__ptr, encoding)
  137. if retVal == nil then return nil end
  138. if Polycore.__ptr_lookup[retVal] ~= nil then
  139. return Polycore.__ptr_lookup[retVal]
  140. else
  141. Polycore.__ptr_lookup[retVal] = char("__skip_ptr__")
  142. Polycore.__ptr_lookup[retVal].__ptr = retVal
  143. return Polycore.__ptr_lookup[retVal]
  144. end
  145. end
  146. function String:getDataSizeWithEncoding(encoding)
  147. local retVal = Polycore.String_getDataSizeWithEncoding(self.__ptr, encoding)
  148. return retVal
  149. end
  150. function String:setDataWithEncoding(data, encoding)
  151. local retVal = Polycore.String_setDataWithEncoding(self.__ptr, data.__ptr, encoding)
  152. end
  153. function String:__delete()
  154. Polycore.__ptr_lookup[self.__ptr] = nil
  155. Polycore.delete_String(self.__ptr)
  156. end