Deprecate LSL String functions#74
Conversation
| HTTPRequest: (URL: string, Parameters: list, Body: string) -> uuid, | ||
| HTTPResponse: (HTTPRequestID: uuid, Status: number, Body: string) -> (), | ||
| Hash: (value: string) -> number, | ||
| InsertString: (TargetVariable: string, Position: number, SourceVariable: string) -> string, |
There was a problem hiding this comment.
I thought of deprecating ll.InsertString in favor of string interpolation, but, I don't think it's a good replacement
|
Cannot be deprecated, they support Unicode while Luau does not. |
| TextBox: (AvatarID: uuid, Text: string, Channel: number) -> (), | ||
| ToLower: (Text: string) -> string, | ||
| ToUpper: (Text: string) -> string, | ||
| ToLower: @[deprecated {use='string.lower'}](Text: string) -> string, |
There was a problem hiding this comment.
ll.ToLower()is useful with accents:
print(string.lower("CAFÉ")) -- > cafÉ
print(ll.ToLower("CAFÉ")) -- > caféThere was a problem hiding this comment.
print(string.lower("ДдAa")) -- Ддaa
print(ll.ToLower("ДдAa")) -- ддaa
Sounds like maybe string.lower should be deprecated instead
There was a problem hiding this comment.
- reverted deprecation, and made a new PR: Deprecate string.lower in favor of ll.ToLower #77
| ToLower: (Text: string) -> string, | ||
| ToUpper: (Text: string) -> string, | ||
| ToLower: @[deprecated {use='string.lower'}](Text: string) -> string, | ||
| ToUpper: @[deprecated {use='string.upper'}](Text: string) -> string, |
There was a problem hiding this comment.
ll.ToUpper()is useful with accents:
print(string.upper("café")) -- > CAFé
print(ll.ToUpper("café")) -- > CAFÉThere was a problem hiding this comment.
- reverted deprecation, and made a new PR: Deprecate string.lower in favor of ll.ToLower #77
| ToLower: (Text: string) -> string, | ||
| ToUpper: (Text: string) -> string, | ||
| ToLower: @[deprecated {use='string.lower'}](Text: string) -> string, | ||
| ToUpper: @[deprecated {use='string.upper'}](Text: string) -> string, |
There was a problem hiding this comment.
print(string.upper("ДдAa")) -- ДдAA
print(ll.ToUpper("ДдAa")) -- ДДAA
sounds like maybe string.upper should be deprecated instead
There was a problem hiding this comment.
- reverted deprecation, and made a new PR: Deprecate string.lower in favor of ll.ToLower #77
|
I think that most of the LL string functions are useful when working with extended characters. The advantage of the SLua string library is that is faster (because they don't need to look at what kind of characters are in the string). The best is to use ones or the others depending on what strings we have. |
|
Here's code: print("Дд")
print("Luau Lower: " .. string.lower("Дд"))
print("Luau Upper: " .. string.upper("Дд"))
print("SL Lower: " .. ll.ToLower("Дд"))
print("SL Upper: " .. ll.ToUpper("Дд"))
print("Luau Ord: " .. string.byte("Д"))
print("SL Ord: " .. ll.Ord("Д", 1))
local x = pcall(function() return string.char(1044) end)
print("Luau Char: " .. tostring(x))
print("SL Char: " .. ll.Char(1044))and the output: |
| CastRay: (Start: vector, End: vector, Options: list) -> {any}, | ||
| Ceil: (Value: number) -> number, | ||
| Char: (value: number) -> string, | ||
| Char: @[deprecated {reason="Use 'utf8.char' or 'string.char' instead."}](value: number) -> string, |
There was a problem hiding this comment.
I can't find an issue with char:
print("Luau Char: " .. utf8.char(1044)) -- Д
print("SL Char: " .. ll.Char(1044)) -- Д
There was a problem hiding this comment.
It would be good to do a full spectrum check, as per the caveats I added on the wiki page for llChar
There was a problem hiding this comment.
wrote a verification script:
for i = 0, 0x10FFFF do
--for i = 0, 0x10 do
--for i = 0xFFEE, 0x10FFFF do
--for i = 0xD800, 0xFFFF do
if 0xD800 <= i and i < 0xE000 then
-- surrogate pairs
local luau_char = utf8.char(i)
local utf8_raw = string.char(
bit32.bor(0xE0, bit32.rshift(i, 12)),
bit32.bor(0x80, bit32.band(0x3F, bit32.rshift(i, 6))),
bit32.bor(0x80, bit32.band(0x3F, i))
)
assert(luau_char == utf8_raw)--, string.format('utf8.char(0x%x) incorrect', i))
local luau_ord_valid, luau_ord = pcall(utf8.codepoint, luau_char)
assert(not luau_ord_valid)--, string.format('"utf8.codepoint("\\u{%x}") did not error', i))
assert(luau_ord == "invalid UTF-8 code")
-- lsl silliness --
assert(ll.Char(i) == '\u{FFFD}')--, string.format('ll.Char(0x%x) incorrect', i))
assert(ll.Ord(luau_char, 1) == 0x3F)--, string.format('ll.Ord("\\u{%x}", 1) incorrect', i))
else
local lsl_char = ll.Char(i)
local luau_char = utf8.char(i)
local lsl_ord = ll.Ord(luau_char, 1)
local luau_ord = utf8.codepoint(luau_char)
assert(luau_ord == i)--, string.format('utf8.codepoint("%s") = 0x%x ~= 0x%x', luau_char, luau_ord, i))
if 0xFFFE <= i and i <= 0xFFFF then -- lsl silliness --
assert(lsl_char == '\u{FFFD}')--, string.format('ll.Char(0x%x) incorrect', i))
elseif i == 0 then -- lsl silliness --
assert(lsl_char == '')--, string.format('ll.Char(0x%x) incorrect', i))
else
assert(lsl_char == luau_char)--, string.format('ll.Char(0x%x) = "%s" ~= utf8.char(0x%x) = "%s"', i, lsl_char, i, luau_char))
end
if 0xFFFE == i then -- lsl silliness --
assert(lsl_ord == 0x3F)--, string.format('ll.Ord("\\u{%x}", 1) incorrect', i))
else
assert(lsl_ord == i)--, string.format('ll.Ord("%s") = 0x%x ~= 0x%x', luau_char, lsl_ord, i))
end
end
end
print("done")
- Added the new caveat about
llOrd(<surrogate>)returning0x3Fto the wiki: https://wiki.secondlife.com/wiki/LlOrd - Noted what
utf8.chardoes on the wiki: https://wiki.secondlife.com/wiki/LlChar
ccdcd0a to
a6a367e
Compare
a6a367e to
4d36e81
Compare
|
I think it's worth thinking about the string functions and what their futures are, but it's pretty clear the internationalization situation is very hairy, even with the presence of the Until then, the existing |
These have almost-direct replacements, but you need to switch from codepoint indices to byte offset indices:
ll.GetSubString->string.subll.SubStringIndex->string.findll.Ord->utf8.codepointll.Char->utf8.charThese have indirect replacements, and you need to switch from codepoint indices to byte offset indices:
ll.DeleteSubString->string.subll.InsertString->string.subll.ReplaceSubStringcan be usually be replaced withstring.gsub:"%"I didn't deprecate:
ll.ParseString2Listll.ParseStringKeepNulls->string.splitll.CSV2List->string.splitll.List2CSV->table.concatMoved to #76 (MERGED):
ll.Base64ToInteger->llbase64.decodell.Base64ToString->llbase64.decodell.StringToBase64->llbase64.encodell.StringLength->utf8.lenMoved to #77:
ll.ToUpperll.ToLower