protectDefaultValue function
Protect default value from incorrect symbols, keywords, etc.
Implementation
String? protectDefaultValue(
Object? name, {
String? type,
bool isEnum = false,
bool isArray = false,
bool dart = true,
}) {
final nameStr = name?.toString();
if (nameStr == null) {
return null;
}
/// Json is not supported
if (nameStr.startsWith('{') && nameStr.endsWith('}')) {
return null;
}
if (nameStr.startsWith('[') && nameStr.endsWith(']')) {
return nameStr;
}
if (isEnum) {
return protectEnumItemsNames([nameStr]).first.name;
}
if (isArray) {
return null;
}
if (type == 'string') {
final quote = dart ? "'" : '"';
return '$quote${nameStr.replaceAll(quote, dart ? r"\'" : r'\"')}$quote';
}
return nameStr;
}