Skip to content

Commit e3022f4

Browse files
committed
add missing Uri.getQueryParameter
1 parent 717f4e6 commit e3022f4

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ You can add the library via Gradle:
2525

2626
```kotlin
2727
dependencies {
28-
implementation("dev.gitlive:firebase-java-sdk:0.3.0")
28+
implementation("dev.gitlive:firebase-java-sdk:0.3.1")
2929
}
3030
```
3131

@@ -35,7 +35,7 @@ Or Maven:
3535
<dependency>
3636
<groupId>dev.gitlive</groupId>
3737
<artifactId>firebase-java-sdk</artifactId>
38-
<version>0.3.0</version>
38+
<version>0.3.1</version>
3939
</dependency>
4040
```
4141

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=0.3.0
1+
version=0.3.1

src/main/java/android/net/Uri.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,37 @@ class Uri(private val uri: URI) {
3131
start = end + 1
3232
} while (start < query.length)
3333
return Collections.unmodifiableSet(names)
34+
}
35+
36+
fun getQueryParameter(key: String?): String? {
37+
if (key == null) {
38+
throw NullPointerException("key")
39+
}
40+
val query: String = uri.query ?: return null
41+
val length = query.length
42+
var start = 0
43+
do {
44+
val nextAmpersand = query.indexOf('&', start)
45+
val end = if (nextAmpersand != -1) nextAmpersand else length
46+
var separator = query.indexOf('=', start)
47+
if (separator > end || separator == -1) {
48+
separator = end
49+
}
50+
if (separator - start == key.length
51+
&& query.regionMatches(start, key, 0, key.length)
52+
) {
53+
if (separator == end) {
54+
return ""
55+
} else {
56+
return query.substring(separator + 1, end)
57+
}
58+
}
59+
// Move start to end of name.
60+
if (nextAmpersand != -1) {
61+
start = nextAmpersand + 1
62+
} else {
63+
break
64+
}
65+
} while (true)
66+
return null
3467
}}

0 commit comments

Comments
 (0)