adaptData method

  1. @visibleForTesting
String adaptData(
  1. String data, [
  2. bool text = false
])

Update the string to insert FNC1

Implementation

@visibleForTesting
String adaptData(String data, [bool text = false]) {
  if (isGS1) {
    // Add FNC1 at parenthesis boundaries
    final result = StringBuffer();
    var start = 0;
    for (final match in RegExp(r'\(.+?\)').allMatches(data)) {
      result.write(data.substring(start, match.start));
      result.write(BarcodeMaps.code128FNC1String);
      result.write(data.substring(match.start + 1, match.end - 1));
      if (text) {
        result.write(' ');
      }
      start = match.end;
    }
    result.write(data.substring(start));
    data = result.toString();
  }

  if (escapes) {
    final result = StringBuffer();
    var start = 0;
    for (final match in RegExp(r'{\d}').allMatches(data)) {
      result.write(data.substring(start, match.start));
      switch (match.group(0)) {
        case '{1}':
          result.write(BarcodeMaps.code128FNC1String);
          break;
        case '{2}':
          result.write(BarcodeMaps.code128FNC2String);
          break;
        case '{3}':
          result.write(BarcodeMaps.code128FNC3String);
          break;
        case '{4}':
          result.write(BarcodeMaps.code128FNC4String);
          break;
        default:
          result.write(match.group(0));
      }
      // result.write(data.substring(match.start + 1, match.end - 1));
      start = match.end;
    }
    result.write(data.substring(start));
    data = result.toString();
  }

  return data;
}