tryParseSymbolOffset function

PCOffset? tryParseSymbolOffset(
  1. String s, {
  2. bool forceHexadecimal = false,
  3. StackTraceHeader? header,
})

Parses strings of the format

Unless forceHexadecimal is true, an integer offset without a "0x" prefix or any hexadecimal digits will be parsed as decimal.

Returns null if the string is not of the expected format.

Implementation

PCOffset? tryParseSymbolOffset(String s,
    {bool forceHexadecimal = false, StackTraceHeader? header}) {
  final match = _symbolOffsetRE.firstMatch(s);
  if (match == null) return null;
  final symbolString = match.namedGroup('symbol')!;
  final offsetString = match.namedGroup('offset')!;
  int? offset;
  if (!forceHexadecimal && !offsetString.startsWith('0x')) {
    offset = int.tryParse(offsetString);
  }
  if (offset == null) {
    final digits = offsetString.startsWith('0x')
        ? offsetString.substring(2)
        : offsetString;
    offset = int.tryParse(digits, radix: 16);
  }
  if (offset == null) return null;
  switch (symbolString) {
    case constants.vmSymbolName:
      return PCOffset(offset, InstructionsSection.vm,
          os: header?.os,
          architecture: header?.architecture,
          compressedPointers: header?.compressedPointers,
          usingSimulator: header?.usingSimulator);
    case constants.isolateSymbolName:
      return PCOffset(offset, InstructionsSection.isolate,
          os: header?.os,
          architecture: header?.architecture,
          compressedPointers: header?.compressedPointers,
          usingSimulator: header?.usingSimulator);
    default:
      break;
  }
  return null;
}