Skip to content

Commit 4267efd

Browse files
authored
Merge pull request #9 from LikeTheSalad/release/2.3.0
Release/2.3.1
2 parents f38fac5 + 15e21de commit 4267efd

File tree

6 files changed

+18
-13
lines changed

6 files changed

+18
-13
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Change Log
22
==========
33

4+
Version 2.3.1
5+
---
6+
7+
* Keeping string resources intact when extracting them from xml files.
8+
49
Version 2.3.0
510
---
611

Original file line numberDiff line numberDiff line change
@@ -1 +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"}]}
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"}]}

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
kotlin.code.style=official
22
kotlin.version=1.9.22
33
group=com.likethesalad.tools.resources
4-
version=2.3.0
4+
version=2.3.1

string-android-resource-locator/src/main/java/com/likethesalad/android/string/resources/locator/extractor/StringXmlResourceExtractor.kt

+1-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class StringXmlResourceExtractor : XmlResourceExtractor<StringAndroidResource>()
4141

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

63-
private fun trimQuotes(text: String): String {
64-
return text.replace(Regex("(?<!\\\\)\""), "")
65-
}
66-
6763
private fun getStringNodeList(document: AndroidXmlResDocument): NodeList {
6864
return document.getElementsByXPath(STRING_RESOURCE_PATH)
6965
}

string-android-resource-locator/src/test/dummy/androidStrings/strings.xml

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
<string name="string_1">Some string</string>
33
<string name="string_2" translatable="false">Some not translatable string</string>
44
<string name="string_3">"Some quoted string"</string>
5-
<string name="string_6">\"Some escaped quoted string\"</string>
65
<string name="string_4">Some partially quoted "string"</string>
76
<string name="string_5">Some partially quoted escaped \"string\"</string>
8-
<integer name="number_1">1</integer>
9-
<bool name="bool_1">true</bool>
7+
<string name="string_6">\"Some escaped quoted string\"</string>
108
<string name="string_7">Just one more string</string>
119
<string name="string_8">Some string with <b>tags</b></string>
10+
<string name="string_9">Some string with <a href="http://localhost">a link</a></string>
11+
<string name="string_10">Some string with <font color="#000000">font color</font></string>
12+
<integer name="number_1">1</integer>
13+
<bool name="bool_1">true</bool>
1214
</resources>

string-android-resource-locator/src/test/java/com/likethesalad/android/string/resources/locator/extractor/StringXmlResourceExtractorTest.kt

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ class StringXmlResourceExtractorTest {
2323

2424
Truth.assertThat(result).containsExactly(
2525
StringAndroidResource("string_1", "Some string", scope),
26-
StringAndroidResource("string_6", "\\\"Some escaped quoted string\\\"", scope),
27-
StringAndroidResource("string_4", "Some partially quoted string", scope),
26+
StringAndroidResource("string_3", "\"Some quoted string\"", scope),
27+
StringAndroidResource("string_4", "Some partially quoted \"string\"", scope),
2828
StringAndroidResource("string_5", "Some partially quoted escaped \\\"string\\\"", scope),
29+
StringAndroidResource("string_6", "\\\"Some escaped quoted string\\\"", scope),
2930
StringAndroidResource("string_7", "Just one more string", scope),
3031
StringAndroidResource("string_8", "Some string with <b>tags</b>", scope),
31-
StringAndroidResource("string_3", "Some quoted string", scope),
32+
StringAndroidResource("string_9", "Some string with <a href=\"http://localhost\">a link</a>", scope),
33+
StringAndroidResource("string_10", "Some string with <font color=\"#000000\">font color</font>", scope),
3234
StringAndroidResource(
3335
mapOf(plain("name") to "string_2", plain("translatable") to "false"),
3436
"Some not translatable string",

0 commit comments

Comments
 (0)