String

extension String
  • Given a string returned by assemblySanitized, creates an instance decoding its contents.

    Declaration

    Swift

    public init?(assemblySanitized sanitized: String)
  • true iff self is suitable as an identifier in LLVM assembly.

    Complexity

    O(n) where n is the length of self.

    Declaration

    Swift

    public var isAssemblySuitable: Bool { get }
  • Returns an encoding of self sanitized for use as an identifier in LLVM assembly.

    self is returned unchanged if and only if it does not contain any dollar sign (“$”) and self.isAssemblySuitable is true. Otherwise, the returned value is the concatenation of two strings of Base64Digit separated by a unique occurrence of the dollar sign. The part on the LHS is called the payload, the other is called the instruction sequence.

    The payload contains a copy of the characters in self that are allowed in LLVM assembly identifiers, in the same order. The instruction sequence is a list of pairs (d, p) where p is a code point and d denotes the position at which p should be inserted to decode the string. Both values are encoded as instances of Base64VarUInt.

    The decoding of a sanitized payload can be described as follows:

    var offset = 0
    for (d, p) in instructions {
      offset += d
      payload.insert(p, at: d)
    }
    

    For example, let the input be the mangled string “infix$5P91Pa”. The payload is “infix” and the instruction sequence is composed of the pairs (“5”, “P9”) and (“1”, “Pa”). The first indicates that the unicode point 60 must be inserted in the payload at offset 5. The second indicates that the unicode point 61 must be inserted in the payload at offset 5 + 1.

    Declaration

    Swift

    public var assemblySanitized: String { get }