String.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. class "String"
  2. String.ENCODING_UTF8 = 0
  3. function String:__getvar(name)
  4. if name == "contents" then
  5. local retVal = Polycore.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 = Polycore.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. Polycore.String_set_contents(self.__ptr, value.__ptr)
  21. return true
  22. elseif name == "w_contents" then
  23. Polycore.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 = Polycore.String(unpack(arg))
  39. end
  40. end
  41. function String:size()
  42. local retVal = Polycore.String_size(self.__ptr)
  43. return retVal
  44. end
  45. function String:length()
  46. local retVal = Polycore.String_length(self.__ptr)
  47. return retVal
  48. end
  49. function String:substr(pos, n)
  50. local retVal = Polycore.String_substr(self.__ptr, pos.__ptr, n.__ptr)
  51. return retVal
  52. end
  53. function String:rfind(str, pos)
  54. local retVal = Polycore.String_rfind(self.__ptr, str, pos.__ptr)
  55. return retVal
  56. end
  57. function String:find(str, pos)
  58. local retVal = Polycore.String_find(self.__ptr, str, pos.__ptr)
  59. return retVal
  60. end
  61. function String:find_last_of(str, pos)
  62. local retVal = Polycore.String_find_last_of(self.__ptr, str, pos.__ptr)
  63. return retVal
  64. end
  65. function String:find_first_of(str, pos)
  66. local retVal = Polycore.String_find_first_of(self.__ptr, str, pos.__ptr)
  67. return retVal
  68. end
  69. function String:toLowerCase()
  70. local retVal = Polycore.String_toLowerCase(self.__ptr)
  71. return retVal
  72. end
  73. function String:toUpperCase()
  74. local retVal = Polycore.String_toUpperCase(self.__ptr)
  75. return retVal
  76. end
  77. function String:split(delim)
  78. local retVal = Polycore.String_split(self.__ptr, delim)
  79. if retVal == nil then return nil end
  80. local __c = _G["std::vector<String>"]("__skip_ptr__")
  81. __c.__ptr = retVal
  82. return __c
  83. end
  84. function String:replace(what, withWhat)
  85. local retVal = Polycore.String_replace(self.__ptr, what, withWhat)
  86. return retVal
  87. end
  88. function String.NumberToString(value, precision)
  89. local retVal = Polycore.String_NumberToString(value, precision)
  90. return retVal
  91. end
  92. function String:toNumber()
  93. local retVal = Polycore.String_toNumber(self.__ptr)
  94. return retVal
  95. end
  96. function String:toInteger()
  97. local retVal = Polycore.String_toInteger(self.__ptr)
  98. return retVal
  99. end
  100. function String.IntToString(value)
  101. local retVal = Polycore.String_IntToString(value)
  102. return retVal
  103. end
  104. function String:c_str()
  105. local retVal = Polycore.String_c_str(self.__ptr)
  106. if retVal == nil then return nil end
  107. local __c = _G["char"]("__skip_ptr__")
  108. __c.__ptr = retVal
  109. return __c
  110. end
  111. function String:getDataWithEncoding(encoding)
  112. local retVal = Polycore.String_getDataWithEncoding(self.__ptr, encoding)
  113. if retVal == nil then return nil end
  114. local __c = _G["char"]("__skip_ptr__")
  115. __c.__ptr = retVal
  116. return __c
  117. end
  118. function String:getWDataWithEncoding(encoding)
  119. local retVal = Polycore.String_getWDataWithEncoding(self.__ptr, encoding)
  120. if retVal == nil then return nil end
  121. local __c = _G["wchar_t"]("__skip_ptr__")
  122. __c.__ptr = retVal
  123. return __c
  124. end
  125. function String:append(c)
  126. local retVal = Polycore.String_append(self.__ptr, c.__ptr)
  127. end
  128. function String:getDataSizeWithEncoding(encoding)
  129. local retVal = Polycore.String_getDataSizeWithEncoding(self.__ptr, encoding)
  130. return retVal
  131. end
  132. function String:setDataWithEncoding(data, encoding)
  133. local retVal = Polycore.String_setDataWithEncoding(self.__ptr, data.__ptr, encoding)
  134. end
  135. function String:isNumber()
  136. local retVal = Polycore.String_isNumber(self.__ptr)
  137. return retVal
  138. end
  139. function String:__delete()
  140. if self then Polycore.delete_String(self.__ptr) end
  141. end