Enfusion Script API
Loading...
Searching...
No Matches
UUID Interface Reference

Structure to store or generate UUIDs. More...

Inheritance diagram for UUID:
string

Public Member Functions

proto external bool IsNull ()
 Returns true if this UUID is Null("00000000-0000-0000-0000-000000000000" or "").
 
proto external void GetInts (out int i1, out int i2, out int i3, out int i4)
 Retrieve the internal 128 bit ID into 4 integers for advanced handling. Primary purpose is to pass them into FromInts() later.
 
- Public Member Functions inherited from string
proto external int ToAscii (int index=0)
 Gets the ASCII code of a character in the string.
 
proto external float ToFloat (float default=0.0, int offset=0, out int parsed=-1)
 Parses a float from a string.
 
proto external int ToInt (int default=0, int offset=0, out int parsed=-1)
 Parses an integer from a string.
 
proto external vector ToVector ()
 Returns a vector from a string.
 
proto external string Substring (int start, int len)
 Substring of str from start position len number of characters.
 
proto external string Trim ()
 Returns trimmed string with removed leading and trailing whitespaces.
 
proto external int TrimInPlace ()
 Removes leading and trailing whitespaces in string.
 
proto external int Length ()
 Returns length of string.
 
proto external bool IsEmpty ()
 Determines if string is empty.
 
proto external int Hash ()
 Returns hash of string.
 
proto external int IndexOf (string sample)
 Finds 'sample' in 'str'.
 
proto external int LastIndexOf (string sample)
 Finds last 'sample' in 'str'.
 
proto external int IndexOfFrom (int start, string sample)
 Finds 'sample' in 'str' from 'start' position.
 
proto external bool Contains (string sample)
 Retunrs true if sample is substring of string.
 
proto external bool ContainsAt (string sample, int pos)
 Checks whether the string contains a given substring at a given position.
 
proto external bool StartsWith (string sample)
 Checks whether the string begins with a given substring.
 
proto external bool EndsWith (string sample)
 Retunrs true if string ends with sample, otherwise return false.
 
proto external int Compare (string sample, bool caseSensitive=true)
 Compares with sample and returns an integer less than, equal to, or greater than zero if string is less than, equal to, or greater than sample.
 
proto external int Replace (string sample, string replace)
 Replace all occurrances of 'sample' in 'str' by 'replace'.
 
proto external int ToLower ()
 Changes string to lowercase.
 
proto external int ToUpper ()
 Changes string to uppercase.
 
proto external void Split (string delimiter, notnull out array< string > outTokens, bool removeEmptyEntries)
 Splits string into array of strings separated by delimiter.
 
proto external string Get (int index)
 Gets n-th character from string.
 
proto external bool IsDigitAt (int index)
 Checks whether a character at a given position is a digit.
 
proto external bool IsSpaceAt (int index)
 Checks whether a character at a given position is a whitespace.
 
proto external TypeName ToType ()
 Returns internal type representation.
 

Static Public Member Functions

static proto bool IsUUID (string uuid)
 Returns true if provided string is in valid UUID format.
 
static proto UUID GenV4 ()
 Will generate UUID of version 4 (random).
 
static proto UUID GenV8 (UUID namespaceUUID, string name)
 Will generate UUID of version 8 (custom).
 
static proto UUID FromInts (int i1, int i2, int i3, int i4)
 Combine back the 4 ints retrieved from GetInts.
 
- Static Public Member Functions inherited from string
static proto string Format (string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
 Builds a string using given format and arguments.
 
static proto string ToString (void var, bool type=false, bool name=false, bool quotes=true)
 

Static Public Attributes

static const UUID NULL_UUID = "00000000-0000-0000-0000-000000000000"
 Null UUID with initialized string. To check if UUID is null use IsNull() method.
 
static const UUID NAMESPACE_DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
 Standardized UUID namespaces by RFC.
 
static const UUID NAMESPACE_URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8"
 
static const UUID NAMESPACE_OID = "6ba7b812-9dad-11d1-80b4-00c04fd430c8"
 
static const UUID NAMESPACE_X500 = "6ba7b814-9dad-11d1-80b4-00c04fd430c8"
 
- Static Public Attributes inherited from string
static const string Empty
 

Detailed Description

Structure to store or generate UUIDs.

  • Null UUID "" is default value without initialized string.
  • Null UUID "00000000-0000-0000-0000-000000000000" is default value with initialized string.
    Note
    If string which is not in valid UUID format is stored in UUID then it is considered as Null UUID.
    Warning
    UUID in Script still operates as string so "" is not equal to "00000000-0000-0000-0000-000000000000" even when both are considered as Null. Use IsNull() method to verify if value is null instead.
  • Generated Version 4 is fully random UUID.
  • Generated Version 8 is custom variant of UUID based on first 128 bits of SHA-256 generated from namespace and name.

Based on RFC-9562 for Universally Unique IDentifiers (UUIDs). RFC 9562 Documentation

Member Function Documentation

◆ FromInts()

static proto UUID UUID.FromInts ( int i1,
int i2,
int i3,
int i4 )
static

Combine back the 4 ints retrieved from GetInts.

◆ GenV4()

static proto UUID UUID.GenV4 ( )
static

Will generate UUID of version 4 (random).

Every bit is random except those used for version and variant.

UUID uuid = UUID.GenV4();
Print(uuid);
// uuid will be random
>> uuid = "f1b7954f-5aeb-41fc-86c0-3af76b7bf30f"
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
Structure to store or generate UUIDs.
Definition UUID.c:28
static proto UUID GenV4()
Will generate UUID of version 4 (random).

◆ GenV8()

static proto UUID UUID.GenV8 ( UUID namespaceUUID,
string name )
static

Will generate UUID of version 8 (custom).

For our custom UUID we use first 128 bits from SHA-256 hash generated from bytes of namespace UUID and name. Bits for version and variant are then replaced with proper values. V8 follows example specification defined in RFC UUIDv8 Example.

Parameters
namespaceUUIDNamespace UUID used to prevent collisions or to give context to name. Use one of standardized or custom UUID.
nameString value used for hashing.
UUID uuid = UUID.GenV8(UUID.NAMESPACE_DNS, "www.example.com");
Print(uuid);
// uuid will be always same
>> uuid = "5c146b14-3c52-8afd-938a-375d0df1fbf6"
static proto UUID GenV8(UUID namespaceUUID, string name)
Will generate UUID of version 8 (custom).
static const UUID NAMESPACE_DNS
Standardized UUID namespaces by RFC.
Definition UUID.c:36

◆ GetInts()

proto external void UUID.GetInts ( out int i1,
out int i2,
out int i3,
out int i4 )

Retrieve the internal 128 bit ID into 4 integers for advanced handling. Primary purpose is to pass them into FromInts() later.

◆ IsNull()

proto external bool UUID.IsNull ( )

Returns true if this UUID is Null("00000000-0000-0000-0000-000000000000" or "").

UUID uuid1;
UUID uuid2 = "";
UUID uuid4 = "5c146b14"; // not valid UUID format will be Null
UUID uuid5 = "5c146b14-3c52-8afd-938a-375d0df1fbf6";
Print(uuid1.IsNull());
Print(uuid2.IsNull());
Print(uuid3.IsNull());
Print(uuid4.IsNull());
Print(uuid5.IsNull());
>> 1
>> 1
>> 1
>> 1
>> 0
static const UUID NULL_UUID
Null UUID with initialized string. To check if UUID is null use IsNull() method.
Definition UUID.c:30
proto external bool IsNull()
Returns true if this UUID is Null("00000000-0000-0000-0000-000000000000" or "").

◆ IsUUID()

static proto bool UUID.IsUUID ( string uuid)
static

Returns true if provided string is in valid UUID format.

bool good = UUID.IsUUID("5c146b14-3c52-8afd-938a-375d0df1fbf6");
bool bad = UUID.IsUUID("5c146b14");
Print(good);
Print(bad);
>> good = 1
>> bad = 0
static proto bool IsUUID(string uuid)
Returns true if provided string is in valid UUID format.

Member Data Documentation

◆ NAMESPACE_DNS

const UUID UUID.NAMESPACE_DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
static

Standardized UUID namespaces by RFC.

RFC Namespace

◆ NAMESPACE_OID

const UUID UUID.NAMESPACE_OID = "6ba7b812-9dad-11d1-80b4-00c04fd430c8"
static

◆ NAMESPACE_URL

const UUID UUID.NAMESPACE_URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8"
static

◆ NAMESPACE_X500

const UUID UUID.NAMESPACE_X500 = "6ba7b814-9dad-11d1-80b4-00c04fd430c8"
static

◆ NULL_UUID

const UUID UUID.NULL_UUID = "00000000-0000-0000-0000-000000000000"
static

Null UUID with initialized string. To check if UUID is null use IsNull() method.


The documentation for this interface was generated from the following file: