String.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. class "String"
  2. String.ENCODING_UTF8 = 0
  3. function String:__getvar(name)
  4. if name == "contents" then
  5. local retVal = Polycode.String_get_contents(self.__ptr)
  6. if retVal == nil then return nil end
  7. local __c = _G["string"]("__skip_ptr__")
  8. __c.__ptr = retVal
  9. return __c
  10. elseif name == "w_contents" then
  11. local retVal = Polycode.String_get_w_contents(self.__ptr)
  12. if retVal == nil then return nil end
  13. local __c = _G["wstring"]("__skip_ptr__")
  14. __c.__ptr = retVal
  15. return __c
  16. end
  17. end
  18. function String:__setvar(name,value)
  19. if name == "contents" then
  20. Polycode.String_set_contents(self.__ptr, value.__ptr)
  21. return true
  22. elseif name == "w_contents" then
  23. Polycode.String_set_w_contents(self.__ptr, value.__ptr)
  24. return true
  25. end
  26. return false
  27. end
  28. function String:String(...)
  29. local arg = {...}
  30. for k,v in pairs(arg) do
  31. if type(v) == "table" then
  32. if v.__ptr ~= nil then
  33. arg[k] = v.__ptr
  34. end
  35. end
  36. end
  37. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  38. self.__ptr = Polycode.String(unpack(arg))
  39. end
  40. end
  41. function String:size()
  42. local retVal = Polycode.String_size(self.__ptr)
  43. if retVal == nil then return nil end
  44. local __c = _G["size_t"]("__skip_ptr__")
  45. __c.__ptr = retVal
  46. return __c
  47. end
  48. function String:length()
  49. local retVal = Polycode.String_length(self.__ptr)
  50. if retVal == nil then return nil end
  51. local __c = _G["size_t"]("__skip_ptr__")
  52. __c.__ptr = retVal
  53. return __c
  54. end
  55. function String:substr(pos, n)
  56. local retVal = Polycode.String_substr(self.__ptr, pos.__ptr, n.__ptr)
  57. return retVal
  58. end
  59. function String:rfind(str, pos)
  60. local retVal = Polycode.String_rfind(self.__ptr, str, pos.__ptr)
  61. if retVal == nil then return nil end
  62. local __c = _G["size_t"]("__skip_ptr__")
  63. __c.__ptr = retVal
  64. return __c
  65. end
  66. function String:find(str, pos)
  67. local retVal = Polycode.String_find(self.__ptr, str, pos.__ptr)
  68. if retVal == nil then return nil end
  69. local __c = _G["size_t"]("__skip_ptr__")
  70. __c.__ptr = retVal
  71. return __c
  72. end
  73. function String:find_last_of(str, pos)
  74. local retVal = Polycode.String_find_last_of(self.__ptr, str, pos.__ptr)
  75. if retVal == nil then return nil end
  76. local __c = _G["size_t"]("__skip_ptr__")
  77. __c.__ptr = retVal
  78. return __c
  79. end
  80. function String:find_first_of(str, pos)
  81. local retVal = Polycode.String_find_first_of(self.__ptr, str, pos.__ptr)
  82. if retVal == nil then return nil end
  83. local __c = _G["size_t"]("__skip_ptr__")
  84. __c.__ptr = retVal
  85. return __c
  86. end
  87. function String:toLowerCase()
  88. local retVal = Polycode.String_toLowerCase(self.__ptr)
  89. return retVal
  90. end
  91. function String:toUpperCase()
  92. local retVal = Polycode.String_toUpperCase(self.__ptr)
  93. return retVal
  94. end
  95. function String:split(delim)
  96. local retVal = Polycode.String_split(self.__ptr, delim)
  97. if retVal == nil then return nil end
  98. for i=1,count(retVal) do
  99. local __c = _G["String"]("__skip_ptr__")
  100. __c.__ptr = retVal[i]
  101. retVal[i] = __c
  102. end
  103. return retVal
  104. end
  105. function String:replace(what, withWhat)
  106. local retVal = Polycode.String_replace(self.__ptr, what, withWhat)
  107. return retVal
  108. end
  109. function String:NumberToString(value, precision)
  110. local retVal = Polycode.String_NumberToString(self.__ptr, value, precision)
  111. return retVal
  112. end
  113. function String:toNumber()
  114. local retVal = Polycode.String_toNumber(self.__ptr)
  115. return retVal
  116. end
  117. function String:toInteger()
  118. local retVal = Polycode.String_toInteger(self.__ptr)
  119. return retVal
  120. end
  121. function String:IntToString(value)
  122. local retVal = Polycode.String_IntToString(self.__ptr, value)
  123. return retVal
  124. end
  125. function String:c_str()
  126. local retVal = Polycode.String_c_str(self.__ptr)
  127. if retVal == nil then return nil end
  128. local __c = _G["char"]("__skip_ptr__")
  129. __c.__ptr = retVal
  130. return __c
  131. end
  132. function String:getDataWithEncoding(encoding)
  133. local retVal = Polycode.String_getDataWithEncoding(self.__ptr, encoding)
  134. if retVal == nil then return nil end
  135. local __c = _G["char"]("__skip_ptr__")
  136. __c.__ptr = retVal
  137. return __c
  138. end
  139. function String:getWDataWithEncoding(encoding)
  140. local retVal = Polycode.String_getWDataWithEncoding(self.__ptr, encoding)
  141. if retVal == nil then return nil end
  142. local __c = _G["wchar_t"]("__skip_ptr__")
  143. __c.__ptr = retVal
  144. return __c
  145. end
  146. function String:append(c)
  147. local retVal = Polycode.String_append(self.__ptr, c.__ptr)
  148. end
  149. function String:getDataSizeWithEncoding(encoding)
  150. local retVal = Polycode.String_getDataSizeWithEncoding(self.__ptr, encoding)
  151. if retVal == nil then return nil end
  152. local __c = _G["size_t"]("__skip_ptr__")
  153. __c.__ptr = retVal
  154. return __c
  155. end
  156. function String:setDataWithEncoding(data, encoding)
  157. local retVal = Polycode.String_setDataWithEncoding(self.__ptr, data.__ptr, encoding)
  158. end
  159. function String:isNumber()
  160. local retVal = Polycode.String_isNumber(self.__ptr)
  161. return retVal
  162. end
  163. function String:__delete()
  164. if self then Polycode.delete_String(self.__ptr) end
  165. end