Recently Written · git

sbm-android

sbm bookmarks for Android: fuzzy search, share to add, sync with bm and the browser add-on

git clone https://github.com/equwal/sbm-android

Log | Files | Refs


app/src/main/java/com/equwal/sbm/Preview.kt (647 bytes)

1 package com.equwal.sbm
2 
3 /**
4  * The live preview: the page of a bookmark, shown under the search. This
5  * file has no Android code, so the tests run on any JVM.
6  */
7 object Preview {
8     private val web = Regex("^(?i)https?://([^/?#\\s]+)(.*)$")
9 
10     /**
11      * The address that the preview loads for the URL of a bookmark, or null
12      * when the page cannot show. Only web pages show. An http page loads with
13      * https, because the app allows no cleartext traffic.
14      */
15     fun address(url: String): String? {
16         val m = web.matchEntire(url.trim()) ?: return null
17         return "https://" + m.groupValues[1] + m.groupValues[2]
18     }
19 }