-
Notifications
You must be signed in to change notification settings - Fork 21
ADFA-3910 | Fix single placeholder dropdown array generation in strings file #1274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jatezzz
merged 3 commits into
stage
from
fix/ADFA-3910-dropdown-placeholder-string-xml-experimental
May 6, 2026
+191
−82
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...o-xml/src/main/java/org/appdevforall/codeonthego/computervision/domain/WidgetTagParser.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| package org.appdevforall.codeonthego.computervision.domain | ||
|
|
||
| /** | ||
| * Parses and normalizes raw OCR text into standardized Android widget tags. | ||
| * Handles common OCR misreads and formatting inconsistencies. | ||
| */ | ||
| internal object WidgetTagParser { | ||
| private val tagRegex = Regex("^(?i)(B|P|D|T|C|R|SW|S)-[A-Z0-9_]+$") | ||
| private val tagExtractRegex = Regex("^(?i)(SW|S\\s*8|8\\s*W|[BPDTCRS8]\\s*W?)[^a-zA-Z0-9]*([A-Z0-9_\\-]+)(?:\\s+(.+))?$") | ||
|
|
||
| /** | ||
| * Checks if the given text represents a valid, normalized widget tag. | ||
| */ | ||
| fun isTag(text: String): Boolean = normalizeTagText(text).matches(tagRegex) | ||
|
|
||
| /** | ||
| * Normalizes raw OCR text into a standard tag format (e.g., "Prefix-Token"). | ||
| */ | ||
| fun normalizeTagText(text: String): String { | ||
| val trimmed = text.trim().trimEnd('.', ',', ';', ':', '_', '|') | ||
| val match = tagExtractRegex.find(trimmed) ?: return trimmed.uppercase() | ||
|
jatezzz marked this conversation as resolved.
|
||
|
|
||
| val prefix = normalizePrefix(match.groupValues[1]) | ||
| val token = normalizeTagToken(match.groupValues[2].trim('-')) | ||
|
|
||
| return "$prefix-$token" | ||
| } | ||
|
|
||
| /** | ||
| * Extracts a normalized widget tag and any remaining trailing text from a raw string. | ||
| * @return A Pair containing the [normalized tag, trailing text], or null if no valid tag is found. | ||
| */ | ||
| fun extractTag(text: String): Pair<String, String?>? { | ||
| val trimmed = text.trim().trimEnd('.', ',', ';', ':', '_', '|') | ||
| val match = tagExtractRegex.find(trimmed) ?: return null | ||
|
|
||
| val prefix = normalizePrefix(match.groupValues[1]) | ||
| val token = normalizeTagToken(match.groupValues[2].trim('-')) | ||
| val tag = "$prefix-$token" | ||
| val trailingText = match.groupValues[3].takeIf { it.isNotBlank() } | ||
|
|
||
| return (tag to trailingText).takeIf { isTag(tag) } | ||
| } | ||
|
|
||
| /** | ||
| * Normalizes the prefix using Regex to handle common OCR misreads (e.g., '8' as 'B'). | ||
| */ | ||
| private fun normalizePrefix(rawPrefix: String): String { | ||
| return rawPrefix.uppercase() | ||
| .replace(Regex("\\s+"), "") | ||
| .replace(Regex("^8$"), "B") | ||
| .replace(Regex("^(8W|S8)$"), "SW") | ||
| } | ||
|
|
||
| /** | ||
| * Extracts the numeric or alphanumeric identifier part of the tag (the part after the hyphen). | ||
| */ | ||
| fun extractOrdinal(tag: String): Int? = tag.substringAfter('-', "").toIntOrNull() | ||
|
|
||
| /** | ||
| * Cleans up the token suffix. If the token consists entirely of numbers or OCR artifacts, | ||
| * it converts those artifacts back to digits. | ||
| */ | ||
| private fun normalizeTagToken(rawToken: String): String { | ||
| if (rawToken.isBlank()) return rawToken | ||
|
|
||
| val uppercaseToken = rawToken.uppercase().replace('-', '_') | ||
| return if (uppercaseToken.all(::isNumericLikeOcrChar)) { | ||
| normalizeOcrDigits(uppercaseToken) | ||
| } else { | ||
| uppercaseToken.replace(Regex("[^A-Z0-9_]"), "_") | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Replaces characters that are commonly misread by OCR with their intended numeric values. | ||
| */ | ||
| private fun normalizeOcrDigits(raw: String): String = | ||
| raw.replace('I', '1') | ||
| .replace('L', '1') | ||
| .replace('!', '1') | ||
| .replace('O', '0') | ||
| .replace('Z', '2') | ||
| .replace('S', '5') | ||
| .replace('B', '6') | ||
|
|
||
| /** | ||
| * Determines whether a character is a digit or a letter frequently confused with a digit by OCR. | ||
| */ | ||
| private fun isNumericLikeOcrChar(char: Char): Boolean { | ||
| return char.isDigit() || char in setOf('O', 'I', 'L', 'Z', 'S', 'B', '!') | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.