Qbs Manual | List of Built-in Services | Utilities Service

Qbs 1.12.2

# Utilities Service

The `Utilities` service offers miscellaneous operations.

## Available Operations

### cStringQuote

      Utilities.cStringQuote(str: string): string

Takes a string and escapes special characters in a way that the result is suitable for use as a C/C++ string literal. This function is typically used to specify values for cpp.defines.

### getHash

      Utilities.getHash(key: string): string

Calculates a 16-byte hash of the input and returns it. Rules in modules should use this function to find unique locations for output artifacts in the build directory without duplicating the whole directory structure of the respective input file (to deal with the case of two files with the same name in different subdirectories of the same product).

### rfc1034Identifier

      Utilities.rfc1034Identifier(str: string): string

Returns an RFC-1034 compliant identifier based on the given string by replacing each character that is not Latin alphanumeric or `.` with `-`.

### versionCompare

      Utilities.versionCompare(version1: string, version2: string): number

Interprets the two arguments as version numbers and returns a number that is smaller than, equal to, or greater than zero if `version1` is smaller than, equal to, or greater than `version2`, respectively.

The version strings consist of up to three numbers separated by dots.