Last active
          May 5, 2024 04:37 
        
      - 
      
 - 
        
Save martinloesethjensen/f272fa448fc5be67d12b59ad9480ef95 to your computer and use it in GitHub Desktop.  
    Kotlin string extension to apply https prefix to string.
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | /** | |
| * Adds https prefix if link does not have prefix. It will also change old prefix http to https. | |
| * @return link/url with https prefix | |
| */ | |
| fun String.toHttpsPrefix(): String? = if (isNotEmpty() && !startsWith("https://") && !startsWith("http://")) { | |
| "https://$this" | |
| } else if (startsWith("http://")) { | |
| replace("http://", "https://") | |
| } else this | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
You can also specify
thison the function calls:this.isNotEmpty()