Closed barsdeveloper closed 2 months ago
This is a Temporary Solution: To avoid such errors, we can prepend a custom complex character prefix (e.g., 'UNT') to these strings before parsing and remove it after serialization. This method employs specific functions to escape regex special characters, add the prefix, and remove it.
Implementation Code:
// Function to add a prefix
addUntPrefix(value) {
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // Escaping special characters in regex
}
const rules = ["A=(Expression=", "B=(Expression="];
let result = value;
rules.forEach(rule => {
const pattern = new RegExp(escapeRegExp(rule), 'g');
result = result.replace(pattern, `_UNT_${rule}`);
});
return result;
}
// Function to parse multiple objects using the prefix
readMultiple(value) {
return ObjectEntity.getMultipleObjectsGrammar().parse(this.addUntPrefix(value))
}
// Function to remove the prefix
removeUntPrefix(value) {
return value.replace(/_UNT_/g, '');
}
// Using the removal function during writing
doWrite(
entity,
insideString,
indentation = "",
wrap = this.wrap,
attributeSeparator = this.attributeSeparator,
trailingSeparator = this.trailingSeparator,
attributeValueConjunctionSign = this.attributeValueConjunctionSign,
attributeKeyPrinter = this.attributeKeyPrinter,
) {
// Omitting the specific writing logic
return this.removeUntPrefix(result)
}
Explanation: This is a temporary solution to handle specific string formats by temporarily adding a prefix before the string is parsed and removing it when needed. This approach relies on specific string formats and regex rules, and may require adjustments based on actual usage scenarios.
Error
A=(Expression="/Script/Engine.MaterialExpressionSaturate'MaterialGraphNode_237.MaterialExpressionSaturate_3'") B=(Expression="/Script/Engine.MaterialExpressionSaturate'MaterialGraphNode_201.MaterialExpressionSaturate_7'")
Originally posted by @chendongde310 in https://github.com/barsdeveloper/ueblueprint/issues/18#issuecomment-2105616336