String.lua 3.5 KB

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