Skip to content

Commit

Permalink
[LLVM] Add llvm::StringRef -> String initializer
Browse files Browse the repository at this point in the history
This allows conveniently getting a Swift String from an LLVM StringRef.
  • Loading branch information
egorzhdan committed Oct 19, 2022
1 parent a132e1c commit 5484308
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/LLVM/LLVM_Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
@_exported import LLVM_Utils // Clang module

extension String {
public init(_ stringRef: llvm.StringRef) {
self.init(cxxString: stringRef.str())
}

public func withStringRef<Result>(_ body: (llvm.StringRef) -> Result) -> Result {
var str = self
return str.withUTF8 { buffer in
Expand Down

0 comments on commit 5484308

Please sign in to comment.