Api v2
This commit is contained in:
12
Sources/OpenFoodFactsSDK/Extensions/String+Cases.swift
Normal file
12
Sources/OpenFoodFactsSDK/Extensions/String+Cases.swift
Normal file
@@ -0,0 +1,12 @@
|
||||
import Foundation
|
||||
|
||||
extension String {
|
||||
public func camelCaseToSnakeCase() -> String {
|
||||
let pattern = "([a-z0-9])([A-Z])"
|
||||
let regex = try! NSRegularExpression(pattern: pattern, options: [])
|
||||
let range = NSRange(location: 0, length: self.count)
|
||||
return regex.stringByReplacingMatches(
|
||||
in: self, options: [], range: range, withTemplate: "$1_$2"
|
||||
).lowercased()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user