Skip to content

Instantly share code, notes, and snippets.

@me2beats
Created June 24, 2021 17:07
Show Gist options
  • Save me2beats/0967b96347581037f5dc1518c6f782ee to your computer and use it in GitHub Desktop.
Save me2beats/0967b96347581037f5dc1518c6f782ee to your computer and use it in GitHub Desktop.
code utils
# not tested!!
extends Object
class_name CodeUtils
static func code_line_split(s:String)->PoolStringArray:
var res: PoolStringArray
var regex: = RegEx.new()
regex.compile("\\w+|\\W")
var found:Array = regex.search_all(s)
for i in found:
res.append(i.get_string())
return res
static func code_line_split1(s:String)->PoolStringArray:
var res: PoolStringArray
var regex: = RegEx.new()
regex.compile("\\w+|\\s+|\\W")
var found:Array = regex.search_all(s)
for i in found:
res.append(i.get_string())
return res
static func get_words_and_punct(text:String)->PoolStringArray:
var res: = PoolStringArray()
res = code_line_split1(text)
# for i in range(res.size()-1, -1, -1):
# var stripped = res[i].lstrip(" ")
#
# if stripped:
# res[i] = stripped
# else:
# res.remove(i)
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment