SassString

Swift
public final class SassString: SassValue

A Sass string value.

Strings may be quoted.

SassString indexes

Sass models strings as a sequence of unicode scalars, not Swift’s primary view as a sequence of extended grapheme clusters. So any string index you receive through Sass applies to the unicode scalar view of the string.

Further, Sass models 1 as the index of the first scalar in the string, and count as the index of the last. This class offers a scalarIndexFrom(sassIndex:) method to wrap up both parts of this conversion, but offers only sympathy to users having to deal with the results.

SassString conforms to SequenceSequence via SassValue. This sequence is a singleton sequence containing the string value, not a sequence of scalars.


Topics

Initializers

init(String, isQuoted: Bool)

Initialize a new string. You should quote strings unless there’s a good reason not to.

Declaration
Swift
public init(_ string: String, isQuoted: Bool = true)

Properties

var string: String

The value of the string. Does not include any quotes.

Declaration
Swift
public let string: String

var isQuoted: Bool

Whether the string is quoted “ or raw.

Declaration
Swift
public let isQuoted: Bool

var sassLength: Int

The length of the string according to Sass.

The number of unicode scalars in the string.

Declaration
Swift
public var sassLength: Int { get }

Methods

func scalarIndexFrom(sassIndex: SassValue) -> String.UnicodeScalarIndex

Interpret a Sass string index.

Declaration
Swift
public func scalarIndexFrom(sassIndex: SassValue) throws
    -> String.UnicodeScalarIndex
Parameters
index

A Sass value intended to be used as a string index. This must be an integer between 1 and sassLength inclusive, or negative with the same magnitude to index from the end.

Throws

SassFunctionError if sassIndex is not an integer or out of range.

Misc

static func ==(lhs: SassString, rhs: SassString) -> Bool

Two SassStrings are equal if they have the same text, whether or not either is quoted.

Declaration
Swift
public static func == (lhs: SassString, rhs: SassString) -> Bool

func accept<V, R>(visitor: V) -> R

Take part in the SassValueVisitor protocol.

Declaration
Swift
public override func accept<V, R>(visitor: V) throws -> R
where V: SassValueVisitor, R == V.ReturnType

var description: String

A short description of the value.

Declaration
Swift
public override var description: String { get }

func hash(into: inout Hasher)

Hash the string’s text.

Declaration
Swift
public override func hash(into hasher: inout Hasher)