Subversion Repositories Applications.papyrus

Rev

Rev 1371 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
11
dojo.provide("dojo.uuid.LightweightGenerator");
12
dojo.uuid.LightweightGenerator = new function () {
13
	var HEX_RADIX = 16;
14
	function _generateRandomEightCharacterHexString() {
15
		var random32bitNumber = Math.floor((Math.random() % 1) * Math.pow(2, 32));
16
		var eightCharacterHexString = random32bitNumber.toString(HEX_RADIX);
17
		while (eightCharacterHexString.length < 8) {
18
			eightCharacterHexString = "0" + eightCharacterHexString;
19
		}
20
		return eightCharacterHexString;
21
	}
22
	this.generate = function (returnType) {
23
		var hyphen = "-";
24
		var versionCodeForRandomlyGeneratedUuids = "4";
25
		var variantCodeForDCEUuids = "8";
26
		var a = _generateRandomEightCharacterHexString();
27
		var b = _generateRandomEightCharacterHexString();
28
		b = b.substring(0, 4) + hyphen + versionCodeForRandomlyGeneratedUuids + b.substring(5, 8);
29
		var c = _generateRandomEightCharacterHexString();
30
		c = variantCodeForDCEUuids + c.substring(1, 4) + hyphen + c.substring(4, 8);
31
		var d = _generateRandomEightCharacterHexString();
32
		var returnValue = a + hyphen + b + hyphen + c + d;
33
		returnValue = returnValue.toLowerCase();
34
		if (returnType && (returnType != String)) {
35
			returnValue = new returnType(returnValue);
36
		}
37
		return returnValue;
38
	};
39
}();
40