parseArgColor method
Color?
parseArgColor(
{ - required bool optional,
})
Implementation
Color? parseArgColor({required bool optional}) {
currArgParsingContext.newArgument(optional: optional);
final i = currArgParsingContext.currArgNum;
final consumeSpaces =
(i > 0 && !optional) || (i == 0 && !optional && this.mode == Mode.math);
if (consumeSpaces) {
this.consumeSpaces();
}
// final res = this.parseColorGroup(optional: optional);
final res = this._parseStringGroup('color', optional: optional);
if (res == null) {
_assertOptionalBeforeReturn(null, optional: optional);
return null;
}
final match3 = _parseColorRegex3.firstMatch(res.text);
if (match3 != null) {
final color = colorByName[match3[0]!.toLowerCase()];
if (color != null) {
return color;
}
}
final match2 = _parseColorRegex2.firstMatch(res.text);
if (match2 != null) {
return Color.fromARGB(
0xff,
int.parse(match2[1]!, radix: 16),
int.parse(match2[2]!, radix: 16),
int.parse(match2[3]!, radix: 16),
);
}
final match1 = _parseColorRegex1.firstMatch(res.text);
if (match1 != null) {
return Color.fromARGB(
0xff,
int.parse(match1[1]! * 2, radix: 16),
int.parse(match1[2]! * 2, radix: 16),
int.parse(match1[3]! * 2, radix: 16),
);
}
throw ParseException("Invalid color: '${res.text}'");
}