I wrote a Swift wrapper around the C LibSass library and have some trouble with passing a non-empty String to a C method.
The LibSass library provides a method to set a custom indent value. Because this method expects a const char*
I know that I can just pass my Swift String to this method and Swift will convert it. Because it is the indent, this String just contains white spaces or \t
, but when I check the value of the getter for the indent, I receive just an empty String. I test this value as follows:
XCTAssertEqual( sassOptions.indent, "\t" )
Where sassOptions.indent
returns the indent that should be set.
The indent property is set with func setIndent(_: String)
that calls the following LibSass method:
void sass_option_set_indent(struct Sass_Options* options, const char* indent)
The expected options
argument is stored as an internal property and given to the C method inside the setIndent(_:String)
Swift function.
I installed the LibSass library with Homebrew (brew install --HEAD libsass
) and linked the library to my project with this dependency. Everything else is working as I expected.
Does anybody know whether Swift converts a String, that just contains white spaces, to an empty String and how to avoid this behaviour?
My setIndent function:
public func setIndent( _ indent: String ) {
sass_option_set_indent( self.options, indent )
}
See also the GitHub repository for the whole code and tests.