@@ -4,11 +4,10 @@ import android.graphics.Path
44import java.util.*
55
66private val VALID_METHODS : Set <String > = setOf (" M" , " L" , " H" , " V" , " C" , " S" , " Q" , " R" , " A" , " Z" , " m" , " l" , " h" , " v" , " c" , " s" , " q" , " r" , " a" , " z" )
7- private val regex = " ([a-zA-Z])" .toRegex()
87
98class SVGAPath (originValue : String ) {
109
11- private val replacedValue: String = originValue.replace(regex, " |||$1 " ) .replace(" ," , " " )
10+ private val replacedValue: String = if ( originValue.contains( " , " )) originValue .replace(" ," , " " ) else originValue
1211
1312 private var cachedPath: Path ? = null
1413
@@ -18,13 +17,17 @@ class SVGAPath(originValue: String) {
1817 return
1918 }
2019 val cachedPath = Path ()
21- val segments = StringTokenizer (this .replacedValue, " |||" )
20+ val segments = StringTokenizer (this .replacedValue, " MLHVCSQRAZmlhvcsqraz" , true )
21+ var currentMethod = " "
2222 while (segments.hasMoreTokens()) {
2323 val segment = segments.nextToken()
2424 if (segment.isEmpty()) { continue }
25- val firstLetter = segment.substring(0 , 1 )
26- if (VALID_METHODS .contains(firstLetter)) {
27- operate(cachedPath, firstLetter, StringTokenizer (segment.substring(1 ).trim(), " " ))
25+ if (VALID_METHODS .contains(segment)) {
26+ currentMethod = segment
27+ if (currentMethod == " Z" || currentMethod == " z" ) { operate(cachedPath, currentMethod, StringTokenizer (" " , " " )) }
28+ }
29+ else {
30+ operate(cachedPath, currentMethod, StringTokenizer (segment, " " ))
2831 }
2932 }
3033 this .cachedPath = cachedPath
@@ -42,6 +45,7 @@ class SVGAPath(originValue: String) {
4245 var index = 0
4346 while (args.hasMoreTokens()) {
4447 val s = args.nextToken()
48+ if (s.isEmpty()) {continue }
4549 if (index == 0 ) { x0 = s.toFloat() }
4650 if (index == 1 ) { y0 = s.toFloat() }
4751 if (index == 2 ) { x1 = s.toFloat() }
0 commit comments