parseFieldsInGeneralPurpose static method

String? parseFieldsInGeneralPurpose(
  1. String rawInformation
)

Implementation

static String? parseFieldsInGeneralPurpose(String rawInformation) {
  if (rawInformation.isEmpty) {
    return null;
  }

  // Processing 2-digit AIs

  if (rawInformation.length < 2) {
    throw NotFoundException.instance;
  }
  final firstTwoDigits = rawInformation.substring(0, 2);
  final twoDigitDataLength = _twoDigitDataLength[firstTwoDigits];
  if (twoDigitDataLength != null) {
    if (twoDigitDataLength.variable) {
      return _processVariableAI(2, twoDigitDataLength.length, rawInformation);
    }
    return _processFixedAI(2, twoDigitDataLength.length, rawInformation);
  }

  if (rawInformation.length < 3) {
    throw NotFoundException.instance;
  }

  final firstThreeDigits = rawInformation.substring(0, 3);
  final threeDigitDataLength = _threeDigitDataLength[firstThreeDigits];
  if (threeDigitDataLength != null) {
    if (threeDigitDataLength.variable) {
      return _processVariableAI(
        3,
        threeDigitDataLength.length,
        rawInformation,
      );
    }
    return _processFixedAI(3, threeDigitDataLength.length, rawInformation);
  }

  if (rawInformation.length < 4) {
    throw NotFoundException.instance;
  }

  final threeDigitPlusDigitDataLength =
      _threeDigitPlusDigitDataLength[firstThreeDigits];
  if (threeDigitPlusDigitDataLength != null) {
    if (threeDigitPlusDigitDataLength.variable) {
      return _processVariableAI(
        4,
        threeDigitPlusDigitDataLength.length,
        rawInformation,
      );
    }
    return _processFixedAI(
      4,
      threeDigitPlusDigitDataLength.length,
      rawInformation,
    );
  }

  final firstFourDigits = rawInformation.substring(0, 4);
  final firstFourDigitLength = _fourDigitDataLength[firstFourDigits];
  if (firstFourDigitLength != null) {
    if (firstFourDigitLength.variable) {
      return _processVariableAI(
        4,
        firstFourDigitLength.length,
        rawInformation,
      );
    }
    return _processFixedAI(4, firstFourDigitLength.length, rawInformation);
  }

  throw NotFoundException.instance;
}