forked from GNUsocial/gnu-social
		
	[FORMATTING] Add utilities to remove affixes from strings
This commit is contained in:
		@@ -237,16 +237,16 @@ abstract class Common
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * If $secure is true, only allow https URLs to pass
 | 
					     * If $ensure_secure is true, only allow https URLs to pass
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function isValidHttpUrl(string $url, bool $ensure_secure = false)
 | 
					    public static function isValidHttpUrl(string $url, bool $ensure_secure = false)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (empty($url)) {
 | 
					        if (empty($url)) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // (if false, we use '?' in 'https?' to say the 's' is optional)
 | 
					        // (if false, we use '?' in 'https?' to say the 's' is optional)
 | 
				
			||||||
        $regex = $secure ? '/^https$/' : '/^https?$/';
 | 
					        $regex = $ensure_secure ? '/^https$/' : '/^https?$/';
 | 
				
			||||||
        return filter_var($url, FILTER_VALIDATE_URL)
 | 
					        return filter_var($url, FILTER_VALIDATE_URL)
 | 
				
			||||||
            && preg_match($regex, parse_url($url, PHP_URL_SCHEME));
 | 
					            && preg_match($regex, parse_url($url, PHP_URL_SCHEME));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -133,6 +133,16 @@ abstract class Formatting
 | 
				
			|||||||
            });
 | 
					            });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static function removePrefix(string $haystack, string $needle)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return substr($haystack, strlen($needle));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static function removeSuffix(string $haystack, string $needle)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return substr($haystack, -strlen($needle));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static function camelCaseToSnakeCase(string $str): string
 | 
					    public static function camelCaseToSnakeCase(string $str): string
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $str));
 | 
					        return strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $str));
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user