Closed
Description
Environment
- Xcode version: 13.1
- iOS version: 15.0.2
- Devices affected: all
- Maps SDK Version: 10.1.0
Observed behavior and steps to reproduce
Setting
let deLocale = Locale(identifier: "de")
do {
try style.localizeLabels(into: deLocale)
results in all name_* of every layer to be overridden with name_de
Expected behavior
Only the primary localized language should be overridden.
Notes / preliminary analysis
Style+Localization::updateExpression applies to all occurrences in range
Fix
Add
/// Updates string once using the first occurrence of a regex
/// - Parameters:
/// - replacement: New string to replace the matched pattern
/// - regex: The regex pattern that will be matched for replacement
internal mutating func updateOnceExpression(replacement: String, regex: NSRegularExpression) {
var range = NSRange(location: 0, length: self.count)
range = regex.rangeOfFirstMatch(in: self, options: [], range: range)
if (range.lowerBound == NSNotFound) {
return
}
self = regex.stringByReplacingMatches(in: self,
options: [],
range: range,
withTemplate: replacement)
}
and replace
stringExpression.updateExpression(replacement: replacement, regex: expressionCoalesce)
with
stringExpression.updateOnceExpression(replacement: replacement, regex: expressionCoalesce)