klyn.code.CodeTokenizer.renameIdentifier
method
public renameIdentifier(source as String, oldName as String, newName as String) as String
Description

Renames every occurrence of code identifier oldName to newName in source while leaving comments, string/character/regex literals, and line endings untouched.

Parameters
ParameterDescription
sourceFull source code text.
oldNameIdentifier name to replace.
newNameReplacement identifier name.
Returns

Updated source text.

Example
import klyn.code.klyn

t = KlynTokenizer()
updated = t.renameIdentifier("count = count + 1 # count in comment", "count", "total")
assert updated == "total = total + 1 # count in comment"