String.lua 3.7 KB

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