Skip to content

Commit

Permalink
Merge pull request #9 from LikeTheSalad/release/2.3.0
Browse files Browse the repository at this point in the history
Release/2.3.1
  • Loading branch information
LikeTheSalad authored Aug 4, 2024
2 parents f38fac5 + 15e21de commit 4267efd
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Change Log
==========

Version 2.3.1
---

* Keeping string resources intact when extracting them from xml files.

Version 2.3.0
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"items":[{"attributes":{"plain|name|":"android_generated","plain|translatable|":"false"},"value":"This string was generated using Androids build plugin","scope":"main:main","type":"string"},{"attributes":{"plain|name|":"app_name"},"value":"Strings playground","scope":"main:main","type":"string"},{"attributes":{"plain|name|":"welcome_message"},"value":"Welcome to the app","scope":"main:main","type":"string"}]}
{"items":[{"attributes":{"plain|name|":"android_generated","plain|translatable|":"false"},"value":"\"This string was generated using Androids build plugin\"","scope":"main:main","type":"string"},{"attributes":{"plain|name|":"app_name"},"value":"Strings playground","scope":"main:main","type":"string"},{"attributes":{"plain|name|":"welcome_message"},"value":"Welcome to the app","scope":"main:main","type":"string"}]}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kotlin.code.style=official
kotlin.version=1.9.22
group=com.likethesalad.tools.resources
version=2.3.0
version=2.3.1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class StringXmlResourceExtractor : XmlResourceExtractor<StringAndroidResource>()

private fun parseNodeToStringAndroidResource(node: Node, scope: Resource.Scope): StringAndroidResource {
val attributesMap = mutableMapOf<AttributeKey, String>()
val value = trimQuotes(getNodeText(node))
val value = getNodeText(node)
val attributesNodes = node.attributes
for (index in 0 until attributesNodes.length) {
val attr = attributesNodes.item(index)
Expand All @@ -60,10 +60,6 @@ class StringXmlResourceExtractor : XmlResourceExtractor<StringAndroidResource>()
return XmlUtils.getContents(node)
}

private fun trimQuotes(text: String): String {
return text.replace(Regex("(?<!\\\\)\""), "")
}

private fun getStringNodeList(document: AndroidXmlResDocument): NodeList {
return document.getElementsByXPath(STRING_RESOURCE_PATH)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
<string name="string_1">Some string</string>
<string name="string_2" translatable="false">Some not translatable string</string>
<string name="string_3">"Some quoted string"</string>
<string name="string_6">\"Some escaped quoted string\"</string>
<string name="string_4">Some partially quoted "string"</string>
<string name="string_5">Some partially quoted escaped \"string\"</string>
<integer name="number_1">1</integer>
<bool name="bool_1">true</bool>
<string name="string_6">\"Some escaped quoted string\"</string>
<string name="string_7">Just one more string</string>
<string name="string_8">Some string with <b>tags</b></string>
<string name="string_9">Some string with <a href="http://localhost">a link</a></string>
<string name="string_10">Some string with <font color="#000000">font color</font></string>
<integer name="number_1">1</integer>
<bool name="bool_1">true</bool>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ class StringXmlResourceExtractorTest {

Truth.assertThat(result).containsExactly(
StringAndroidResource("string_1", "Some string", scope),
StringAndroidResource("string_6", "\\\"Some escaped quoted string\\\"", scope),
StringAndroidResource("string_4", "Some partially quoted string", scope),
StringAndroidResource("string_3", "\"Some quoted string\"", scope),
StringAndroidResource("string_4", "Some partially quoted \"string\"", scope),
StringAndroidResource("string_5", "Some partially quoted escaped \\\"string\\\"", scope),
StringAndroidResource("string_6", "\\\"Some escaped quoted string\\\"", scope),
StringAndroidResource("string_7", "Just one more string", scope),
StringAndroidResource("string_8", "Some string with <b>tags</b>", scope),
StringAndroidResource("string_3", "Some quoted string", scope),
StringAndroidResource("string_9", "Some string with <a href=\"http://localhost\">a link</a>", scope),
StringAndroidResource("string_10", "Some string with <font color=\"#000000\">font color</font>", scope),
StringAndroidResource(
mapOf(plain("name") to "string_2", plain("translatable") to "false"),
"Some not translatable string",
Expand Down

0 comments on commit 4267efd

Please sign in to comment.