2

damn sorry devs , i know you ppl are here for relaxation , but please help me out.
i am creating a browser and wanna have an edittext which works something like this :

>>user enters 'fb' , there should be a google search for fb(i.e load the string "https://www.google.com/search?q=fb")

>> user enters fb.com , webview should open it directly (i.e load the string "https://www.fb.com" )
>> some nerdy user enters http://www.fb.com or https://www.fb.com , it should load that

I know the function to make it load, what i don't know is how to modify that string to show such behaviors .
The webview is dumb enough to not behave like tht by default. although it feels good having such a raw and tool in hand, but hell, its a fucking google's webview! , why can't they just throw in some built in ways to show their search results by default when user enters a malformed url ?? that would be a great source of branding --__--

Comments
  • 1
    you can check by regex if it's a valid url, if not pass it to the search, chrome additionally checks it against known tlds and tries to resolve it, if there is
  • 0
    @JoshBent which regx are you referring to? i have heard that there are 1000s of domains with even supported characters like $ and '(' / ')' . is it something from the Patterns library?

    And its not an implicit intent to chrome but being handled in a webview.... and i don't know why, its not even adding an https:// by default if passed a link
  • 0
    @JoshBent and since it isn't adding the http/ https/ file:/// uri in the start, i want a pattern matcher for that too :''(
  • 1
    @singh029 lol that's really motivating but i can't X(
  • 2
    Regex it! If there's no spaces, and the input doesn't contain some of the known characters and a dot before a few characters at the end, its probably a domain name. If you are considering it as a domain, just show a drop down saying search this before user hits go. This is not perfect but mostly how chrome handles the entered url.
  • 0
    Regex is your best friend. First, you can find a pattern that can match with domains. After, OR it with normal strings and you will eventually succeed with trial and error. You can use here to test your patterns.

    https://regex101.com

    Here are some strings to test by.

    http:/devrant.com
    http:///devrant.com
    htt://devrant.con
    http://ww.devrant.com
    http://devrant .com
    http://www2.devrant.com
    youtu.be
    dev.rant
    goo.gl
  • 0
    thank you so much guys ❤️❤️ ! will definitely try and reply (not with the lappy now, aboy needs sleep😅) . some other people also recommended me to check regex. i guess i got to learn it ^_^

    meanwhile , checkout my attempt for a browser(would appreciate PRs!) :

    https://github.com/chaostools/...
Add Comment