parse method - Uuid class - uuid library - Dart API
Description: API docs for the parse method from the Uuid class, for the Dart programming language.

# parse method Null safety

List<int> parse(

1. String uuid,
2. {List<int>? buffer,
3. int offset = 0,
4. bool validate = true,
5. ValidationMode validationMode = ValidationMode.strictRFC4122}

)

Parses the provided `uuid` into a list of byte values as a List. Can optionally be provided a `buffer` to write into and a positional `offset` for where to start inputting into the buffer. Throws FormatException if the UUID is invalid. Optionally you can set `validate` to false to disable validation of the UUID before parsing.

## Implementation

    static List<int> parse(
      String uuid, {
      List<int>? buffer,
      int offset = 0,
      bool validate = true,
      ValidationMode validationMode = ValidationMode.strictRFC4122,
    }) {
      if (validate) {
        isValidOrThrow(fromString: uuid, validationMode: validationMode);
      }
      var i = offset, ii = 0;

      // Create a 16 item buffer if one hasn't been provided.
      buffer = (buffer != null) ? buffer : Uint8List(16);

      // Convert to lowercase and replace all hex with bytes then
      // string.replaceAll() does a lot of work that I don't need, and a manual
      // regex gives me more control.
      final regex = RegExp('[0-9a-f]{2}');
      for (Match match in regex.allMatches(uuid.toLowerCase())) {
        if (ii < 16) {
          var hex = uuid.toLowerCase().substring(match.start, match.end);
          buffer[i + ii++] = int.parse(hex, radix: 16);
        }
      }

      // Zero out any left over bytes if the string was too short.
      while (ii < 16) {
        buffer[i + ii++] = 0;
      }

      return buffer;
    }