Subversion Repositories Applications.papyrus

Rev

Rev 1318 | 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
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.uuid.LightweightGenerator");
14
dojo.uuid.LightweightGenerator = new function () {
15
	var HEX_RADIX = 16;
16
	function _generateRandomEightCharacterHexString() {
17
		var random32bitNumber = Math.floor((Math.random() % 1) * Math.pow(2, 32));
18
		var eightCharacterHexString = random32bitNumber.toString(HEX_RADIX);
19
		while (eightCharacterHexString.length < 8) {
20
			eightCharacterHexString = "0" + eightCharacterHexString;
21
		}
22
		return eightCharacterHexString;
23
	}
24
	this.generate = function (returnType) {
25
		var hyphen = "-";
26
		var versionCodeForRandomlyGeneratedUuids = "4";
27
		var variantCodeForDCEUuids = "8";
28
		var a = _generateRandomEightCharacterHexString();
29
		var b = _generateRandomEightCharacterHexString();
30
		b = b.substring(0, 4) + hyphen + versionCodeForRandomlyGeneratedUuids + b.substring(5, 8);
31
		var c = _generateRandomEightCharacterHexString();
32
		c = variantCodeForDCEUuids + c.substring(1, 4) + hyphen + c.substring(4, 8);
33
		var d = _generateRandomEightCharacterHexString();
34
		var returnValue = a + hyphen + b + hyphen + c + d;
35
		returnValue = returnValue.toLowerCase();
36
		if (returnType && (returnType != String)) {
37
			returnValue = new returnType(returnValue);
38
		}
39
		return returnValue;
40
	};
41
}();
42