This commit is contained in:
AFCMS 2022-01-02 18:19:55 +01:00
parent 63b415b6bf
commit a62788b728
1 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,67 @@
--Similar to the StringParser class of mojang Brigadier library
local string = string
local SYNTAX_DOUBLE_QUOTE = "\""
local SYNTAX_SINGLE_QUOTE = "\'"
local StringParser = {}
function StringParser:init(str)
self.cursor = 1
self.str = str
end
function StringParser:get_string()
return self.str
end
function StringParser:set_cursor(cursor)
self.cursor = cursor
end
function StringParser:get_cursor()
return self.cursor
end
function StringParser:get_remaining_length()
return string.len(self.str) - self.cursor
end
function StringParser:get_total_length()
return string.len(self.str)
end
function StringParser:get_read()
return string.sub(self.str, 1, self.cursor)
end
function StringParser:get_remaining()
return string.sub(self.str, self.cursor)
end
function StringParser:can_read(length)
return (self.cursor + (length or 1)) <= string.len(self.str)
end
function StringParser:peek(offset)
return string.sub(self.cursor + (offset or 0), self.cursor + (offset or 0))
end
function StringParser:read()
local r = string.sub(self.cursor, self.cursor)
self.cursor = self.cursor + 1
return r
end
function StringParser:skip()
self.cursor = self.cursor + 1
end
function StringParser.is_allowed_number()
return false
end
function StringParser.is_quoted_string_start(char)
return char == SYNTAX_DOUBLE_QUOTE or char == SYNTAX_SINGLE_QUOTE
end