@@ -26,8 +26,8 @@ object FuzzyAttributeParser {
2626 TEXT (" android:text" , listOf (" text" )),
2727 HINT (" android:hint" , listOf (" hint" )),
2828 BACKGROUND (" android:background" , listOf (" background" , " bg" ), ValueType .COLOR ),
29- BACKGROUND_TINT (" app:backgroundTint" , listOf (" backgroundtint" , " background_tint" ), ValueType .COLOR ),
30- SRC (" android:src" , listOf (" src" , " scr" ), ValueType .DRAWABLE ),
29+ BACKGROUND_TINT (" app:backgroundTint" , listOf (" backgroundtint" , " background_tint" , " bg_tint " ), ValueType .COLOR ),
30+ SRC (" android:src" , listOf (" src" , " scr" , " sre " , " 5rc " ), ValueType .DRAWABLE ),
3131 CONTENT_DESCRIPTION (" android:contentDescription" , listOf (" contentdescription" , " content_description" )),
3232
3333 TEXT_SIZE (" android:textSize" , listOf (" textsize" , " text_size" ), ValueType .SP_DIMENSION ),
@@ -74,7 +74,7 @@ object FuzzyAttributeParser {
7474 LAYOUT_MARGIN_RIGHT (" android:layout_marginRight" , listOf (" layout_marginright" , " layout_margin_right" , " margin_right" ), ValueType .DIMENSION ),
7575
7676 LAYOUT_WEIGHT (" android:layout_weight" , listOf (" layout_weight" , " weight" ), ValueType .FLOAT ),
77- LAYOUT_GRAVITY (" android:layout_gravity" , listOf (" layout_gravity" )),
77+ LAYOUT_GRAVITY (" android:layout_gravity" , listOf (" layout_gravity" , " layaut_gravity " )),
7878 GRAVITY (" android:gravity" , listOf (" gravity" )),
7979 ORIENTATION (" android:orientation" , listOf (" orientation" )),
8080
@@ -150,6 +150,7 @@ object FuzzyAttributeParser {
150150 private val ocrLetterZToTwoRegex = Regex (" [zZ]" )
151151 private val ocrLetterSToFiveRegex = Regex (" [sS]" )
152152 private val ocrLetterBToSixRegex = Regex (" [bB]" )
153+ private val ocrDenoiseRegex = Regex (" inm|rn|wm|nm" )
153154
154155 private val matchKeywords = setOf (" match" , " parent" )
155156 private val wrapKeywords = setOf (" wrap" , " content" , " wrapcan" )
@@ -419,7 +420,7 @@ object FuzzyAttributeParser {
419420 .replace(Regex (" op$" ), " dp" )
420421 .replace(Regex (" olp$" ), " dp" )
421422
422- val numericString = fixedUnit.replace(Regex ( " [a-z]+$ " ) , " " )
423+ val numericString = fixedUnit.replace(" _ " , " " )
423424 val numericPart = extractOcrNumber(numericString)
424425
425426 if (numericPart != null ) return " ${numericPart} dp"
@@ -432,7 +433,7 @@ object FuzzyAttributeParser {
432433 .replace(" " , " " )
433434 .replace(Regex (" 5p$" ), " sp" )
434435
435- val numericString = fixedUnit.replace(Regex ( " [a-z]+$ " ) , " " )
436+ val numericString = fixedUnit.replace(" _ " , " " )
436437 val numericPart = extractOcrNumber(numericString)
437438
438439 if (numericPart != null ) return " ${numericPart} sp"
@@ -457,22 +458,30 @@ object FuzzyAttributeParser {
457458 }
458459
459460 private fun cleanId (value : String ): String {
460- return value.lowercase()
461+ return denoiseOcrIdentifier( value.lowercase() )
461462 .replace(nonAlphanumericRegex, " _" )
462463 .replace(multipleUnderscoresRegex, " _" )
463464 .trimEnd(' _' )
464465 .trimStart(' _' )
465466 }
466467
467- private fun denoiseOcrIdentifier (value : String ): String =
468- value.replace(" rn" , " m" )
469- .replace(" wm" , " m" )
468+ private fun denoiseOcrIdentifier (value : String ): String {
469+ return value.replace(ocrDenoiseRegex) { matchResult ->
470+ when (matchResult.value) {
471+ " inm" -> " im"
472+ else -> " m"
473+ }
474+ }
475+ }
470476
471477 private fun cleanDrawable (value : String ): String {
472478 if (value.startsWith(" @drawable/" )) return value
473- val cleaned = value.replace(Regex (" [^a-zA-Z0-9_.]" ), " " )
474- .substringBeforeLast(' .' )
475- .lowercase()
479+
480+ var cleaned = value.lowercase()
481+ .replace(Regex (" \\ .(png|jpg|jpeg|webp|xml|svg)$" ), " " )
482+
483+ cleaned = cleaned.replace(Regex (" [^a-z0-9_]" ), " " )
484+
476485 return " @drawable/${denoiseOcrIdentifier(cleaned)} "
477486 }
478487
0 commit comments