parse method
Attempts to parse the raw Result's contents as a particular type of information (email, URL, etc.) and return a ParsedResult encapsulating the result of parsing.
@param theResult the raw Result to parse @return ParsedResult encapsulating the parsing result
Implementation
@override
WifiParsedResult? parse(Result result) {
String rawText = ResultParser.getMassagedText(result);
if (!rawText.startsWith('WIFI:')) {
return null;
}
rawText = rawText.substring('WIFI:'.length);
final ssid = matchSinglePrefixedField('S:', rawText, ';', false);
if (ssid == null || ssid.isEmpty) {
return null;
}
final pass = matchSinglePrefixedField('P:', rawText, ';', false);
String? type = matchSinglePrefixedField('T:', rawText, ';', false);
type ??= 'nopass';
// Unfortunately, in the past, H: was not just used for bool 'hidden', but 'phase 2 method'.
// To try to retain backwards compatibility, we set one or the other based on whether the string
// is 'true' or 'false':
bool hidden = false;
String? phase2Method =
matchSinglePrefixedField('PH2:', rawText, ';', false);
final hValue = matchSinglePrefixedField('H:', rawText, ';', false);
if (hValue != null) {
// If PH2 was specified separately, or if the value is clearly bool, interpret it as 'hidden'
if (phase2Method != null ||
'true' == hValue.toLowerCase() ||
'false' == hValue.toLowerCase()) {
hidden = 'true' == hValue.toLowerCase();
} else {
phase2Method = hValue;
}
}
final identity = matchSinglePrefixedField('I:', rawText, ';', false);
final anonymousIdentity =
matchSinglePrefixedField('A:', rawText, ';', false);
final eapMethod = matchSinglePrefixedField('E:', rawText, ';', false);
return WifiParsedResult(
type,
ssid,
pass,
hidden,
identity,
anonymousIdentity,
eapMethod,
phase2Method,
);
}