Created LanguageTool Plugin
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
@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
|
||||
Reference in New Issue
Block a user