/* Auto-detect UUID format
352892
static private function detectFormat($src) {
    if (is_string($src))
      return self::FMT_STRING;
    else if (is_array($src)) {
      $len = count($src);
      if ($len == 1 || ($len % 2) == 0)
        return $len;
      else
        return (-1);
    }
    else
      return self::FMT_BINARY;
  }
127619
function UUIDcreatePart (length) {
    var uuidpart = '';
    for (var i = 0; i < length; i++) {
        var uuidchar = parseInt((Math.random() * 256), 10).toString(16);
        if (uuidchar.length === 1) {
            uuidchar = '0' + uuidchar;
        }
        uuidpart += uuidchar;
    }
    return uuidpart;
}
805515
function arrayToUUID(array, offset)
			{
				var k=0;
				var string = '';
				var UUID_format = [4, 2, 2, 2, 6];
				for (var l=0; l<UUID_format.length; l++)
				{
					if (l != 0)
					{
						string += '-';
					}
					for (var j=0; j<UUID_format[l]; j++, k++)
					{
						string += evothings.util.toHexString(array[offset+k], 1);
					}
				}
				return string;
			}
247038
def uuid(self, type, val):
        """"""
        picker = lambda x: x.get('uuid', x)
        return self._get((type, val), picker)
310373
function validUUID(uuid) {
    // xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx where x is a hexadecimal digit and
    // y is 8,9, A, or B
    var uuidRegex = /^[0-9a-f]{8}\-[0-9a-f]{4}\-4[0-9a-f]{3}\-[89ab][0-9a-f]{3}\-[0-9a-f]{12}$/i,
        result;

    result = uuidRegex.exec(uuid);

    return result !== null;
}
480346
public static UUID fromString(String name) {
		String[] components = name.split("-");
		if (components.length != 5) {
			throw new IllegalArgumentException("Invalid UUID string: " + name);
		}
		for (int i = 0; i < 5; i++) {
			components[i] = "0x" + components[i];
		}

		long mostSigBits = Long.decode(components[0]).longValue();
		mostSigBits <<= 16;
		mostSigBits |= Long.decode(components[1]).longValue();
		mostSigBits <<= 16;
		mostSigBits |= Long.decode(components[2]).longValue();

		long leastSigBits = Long.decode(components[3]).longValue();
		leastSigBits <<= 48;
		leastSigBits |= Long.decode(components[4]).longValue();

		return new UUID(mostSigBits, leastSigBits);
	}
494025
def is_uuid4(instr):
  
  v = instr.strip().replace('-','').lower()
  if len(v) != 32: return False
  if not re.match('^[0-9a-f]+$',v): return False
  if v[12] != '4': return False
  if not re.match('[89ab]',v[16]): return False
  return True
622900
def get_uuid(obj):
    """"""
    # TODO: deprecate null uuid ret val
    from uuid import UUID
    try:
        uuid = obj.attrs['uuid']
    except KeyError:
        return UUID(int=0)
    # convert to unicode for python 3
    try:
        uuid = uuid.decode('ascii')
    except (LookupError, AttributeError):
        pass
    return UUID(uuid)
392564
static String serialize(UUID uuid) {

        StringBuilder sb = new StringBuilder();

        // Get UUID type version
        ByteBuffer bb = UUIDType.instance.decompose(uuid);
        int version = (bb.get(bb.position() + 6) >> 4) & 0x0f;

        // Add version at the beginning
        sb.append(ByteBufferUtils.toHex((byte) version));

        // If it's a time based UUID, add the UNIX timestamp
        if (version == 1) {
            long timestamp = uuid.timestamp();
            String timestampHex = ByteBufferUtils.toHex(Longs.toByteArray(timestamp));
            sb.append(timestampHex);
        }

        // Add the UUID itself
        sb.append(ByteBufferUtils.toHex(bb));
        return sb.toString();
    }
794904
function uuid() {
    var i, random;
    var uuid = '';

    for (i = 0; i < 32; i++) {
        random = Math.random() * 16 | 0;
        if (i === 8 || i === 12 || i === 16 || i === 20) {
            uuid += '-';
        }
        uuid += (i === 12 ? 4 : (i === 16 ? (random & 3 | 8) : random)).toString(16);
    }

    return uuid;
}
284557
public static String getUUID() {
        UUID id = UUID.randomUUID();
        ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
        bb.putLong(id.getMostSignificantBits());
        bb.putLong(id.getLeastSignificantBits());
        return Base64.encodeBase64URLSafeString(bb.array());
    }
67358
def uuid_object(title="Reference", description="Select an object", default=None, display=True):
    """"""

    uuid = {
        'pattern': '^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{'
                   '4}-['
                   'a-fA-F0-9]{4}-[a-fA-F0-9]{12}$',
        'type': 'string',
        'title': title,
        'description': description,
    }

    if not display:
        uuid['x-schema-form'] = {
            'condition': "false"
        }

    if default is not None:
        uuid['default'] = default

    return uuid
973248
public static UUID attemptUUIDParse(BufferedString str) {
    Long lo = attemptUUIDParseLow(str);
    Long hi = attemptUUIDParseHigh(str);
    return (str.getOffset() == -1) ? null : buildUUID(lo, hi);
  }
177026
static protected function uuid()
		{
			// Use the random or the server name (if present) in the generation of UUID
			$base = md5(uniqid(rand(), true));

			// Mark as "random" UUID, set version
			$byte = hexdec( substr ($base, 12, 2));
			$byte = $byte & hexdec('0F');
			$byte = $byte | hexdec('40');
			$base = substr_replace($base, strtoupper (dechex ($byte)), 12, 2);

			// Set the variant
			$byte = hexdec (substr ($base, 16, 2));
			$byte = $byte & hexdec('3F');
			$byte = $byte | hexdec('80');
			$base = substr_replace($base, strtoupper (dechex ($byte)), 16, 2);

			// Format
			return strtolower(sprintf('%s-%s-%s-%s-%s', substr($base, 0, 8),	substr($base, 8, 4), substr($base, 12, 4), substr($base, 16, 4), substr($base, 20, 12)));
		}
148025
private function uuid(): string
    {
        return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
            mt_rand(0, 0xffff), mt_rand(0, 0xffff),
            mt_rand(0, 0xffff),
            mt_rand(0, 0x0fff) | 0x4000,
            mt_rand(0, 0x3fff) | 0x8000,
            mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
        );
    }
844295
def valid_uuid(value):
    

    try:
        uuid.UUID(value, version=4)
        return True
    except (TypeError, ValueError, AttributeError):
        return False
672046
function KdbxUuid(ab) {
    if (ab === undefined) {
        ab = new ArrayBuffer(UuidLength);
    }
    if (typeof ab === 'string') {
        ab = ByteUtils.base64ToBytes(ab);
    }
    this.id = ab.byteLength === 16 ? ByteUtils.bytesToBase64(ab) : undefined;
    this.empty = true;
    if (ab) {
        var bytes = new Uint8Array(ab);
        for (var i = 0, len = bytes.length; i < len; i++) {
            if (bytes[i] !== 0) {
                this.empty = false;
                return;
            }
        }
    }
}