You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
656 B
33 lines
656 B
@tool
|
|
extends Object
|
|
|
|
class_name LanguageToolUtils
|
|
|
|
static func offset_to_row_column(offset:int, text:String)->Vector2i:
|
|
var row:int = 0
|
|
var column:int = 0
|
|
|
|
if offset > text.length():
|
|
return Vector2i(-1,-1)
|
|
|
|
for i in offset:
|
|
if text[i] == "\n":
|
|
row+=1
|
|
column = 0
|
|
else:
|
|
column+=1
|
|
return Vector2i(row, column)
|
|
|
|
static func row_column_to_offset(row:int, column:int, text:String) -> int:
|
|
var current_row:int = 0
|
|
var current_column:int = 0
|
|
for i in text.length():
|
|
if current_row == row and current_column == column:
|
|
return i
|
|
if text[i] == "\n":
|
|
current_row += 1
|
|
current_column = 0
|
|
else:
|
|
current_column += 1
|
|
return -1
|