File tree Expand file tree Collapse file tree 1 file changed +1
-27
lines changed
WooCommerce/Classes/Extensions Expand file tree Collapse file tree 1 file changed +1
-27
lines changed Original file line number Diff line number Diff line change @@ -91,33 +91,7 @@ extension String {
9191 /// Insert a . before and after any non number
9292 ///
9393 func insertDotsBeforeAndAfterAnyNonNumber( inString: String ) -> String {
94- guard inString. count > 1 else {
95- return inString
96- }
97-
98- /// Initialize our output with the first character of the input string
99- var outString = String ( inString [ inString. index ( inString. startIndex, offsetBy: 0 ) ] )
100-
101- /// Loop over the remaining characters in the string, inserting . as needed
102- for index in 1 ... inString. count - 1 {
103- let characterAtIndex = inString [ inString. index ( inString. startIndex, offsetBy: index) ]
104- let characterBefore = inString [ inString. index ( inString. startIndex, offsetBy: index - 1 ) ]
105-
106- let characterAtIndexIsNumberOrDot = characterAtIndex. isNumber || characterAtIndex == " . "
107- let characterBeforeIsNumberOrDot = characterBefore. isNumber || characterBefore == " . "
108-
109- if !characterAtIndexIsNumberOrDot && characterBefore. isNumber {
110- outString += " . "
111- }
112-
113- if characterAtIndex. isNumber && !characterBeforeIsNumberOrDot {
114- outString += " . "
115- }
116-
117- outString += String ( characterAtIndex)
118- }
119-
120- return outString
94+ inString. replacingOccurrences ( of: " ([^0-9.]+) " , with: " .$1. " , options: . regularExpression)
12195 }
12296
12397 /// Score and compare two string components
You can’t perform that action at this time.
0 commit comments