-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support automatic SVG detection using the source contents. (#654)
- Loading branch information
1 parent
3274083
commit 446b3a3
Showing
4 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,21 @@ | ||
@file:JvmName("-SvgExtensions") | ||
|
||
package coil.util | ||
|
||
import okio.BufferedSource | ||
import okio.ByteString | ||
|
||
internal fun BufferedSource.indexOf(bytes: ByteString, fromIndex: Long, toIndex: Long): Long { | ||
require(bytes.size > 0) { "bytes is empty" } | ||
|
||
val firstByte = bytes[0] | ||
var currentIndex = fromIndex | ||
while (currentIndex < toIndex) { | ||
currentIndex = indexOf(firstByte, currentIndex) | ||
if (currentIndex == -1L || rangeEquals(currentIndex, bytes)) { | ||
return currentIndex | ||
} | ||
currentIndex++ | ||
} | ||
return -1 | ||
} |