File tree 3 files changed +34
-19
lines changed
main/java/at/bitfire/icsdroid
test/kotlin/at/bitfire/icsdroid
3 files changed +34
-19
lines changed Original file line number Diff line number Diff line change @@ -32,4 +32,23 @@ object UriUtils {
32
32
33
33
return false
34
34
}
35
+
36
+ /* *
37
+ * Strips the URL from a string. For example, the following string:
38
+ * ```
39
+ * "This is a URL: https://example.com"
40
+ * ```
41
+ * will return:
42
+ * ```
43
+ * "https://example.com"
44
+ * ```
45
+ * _Quotes are not included_
46
+ * @return The URL found in the string
47
+ * @throws IllegalArgumentException if no URL is found in the string
48
+ */
49
+ fun String.stripUrl (): String? {
50
+ return " ([a-zA-Z]+)://(\\ w+)(.\\ w+)*[\\ w.&?=*]*" .toRegex()
51
+ .find(this )
52
+ ?.value
53
+ }
35
54
}
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import androidx.compose.ui.platform.LocalContext
21
21
import at.bitfire.icsdroid.Constants
22
22
import at.bitfire.icsdroid.HttpClient
23
23
import at.bitfire.icsdroid.R
24
+ import at.bitfire.icsdroid.UriUtils.stripUrl
24
25
import at.bitfire.icsdroid.calendar.LocalCalendar
25
26
import at.bitfire.icsdroid.model.CreateSubscriptionModel
26
27
import at.bitfire.icsdroid.model.CredentialsModel
@@ -148,23 +149,4 @@ class AddCalendarActivity : AppCompatActivity() {
148
149
HttpClient .setForeground(true )
149
150
}
150
151
151
- /* *
152
- * Strips the URL from a string. For example, the following string:
153
- * ```
154
- * "This is a URL: https://example.com"
155
- * ```
156
- * will return:
157
- * ```
158
- * "https://example.com"
159
- * ```
160
- * _Quotes are not included_
161
- * @return The URL found in the string
162
- * @throws IllegalArgumentException if no URL is found in the string
163
- */
164
- private fun String.stripUrl (): String? {
165
- return " ([a-zA-Z]+)://(\\ w+)(.\\ w+)*[/\\ w*]*" .toRegex()
166
- .find(this )
167
- ?.value
168
- }
169
-
170
152
}
Original file line number Diff line number Diff line change
1
+ package at.bitfire.icsdroid
2
+
3
+ import at.bitfire.icsdroid.UriUtils.stripUrl
4
+ import org.junit.Assert.assertEquals
5
+ import org.junit.Test
6
+
7
+ class UrlUtilsTest {
8
+ @Test
9
+ fun testStripUrl () {
10
+ val url = " This is a URL: https://example.com/more/and/more?query=true.&par_am=test.more"
11
+ val strippedUrl = url.stripUrl()
12
+ assertEquals(" https://example.com/more/and/more?query=true.&par_am=test.more" , strippedUrl)
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments