Revision 14355
Added by Aaron Marcuse-Kubitza over 10 years ago
trunk/schemas/util.sql | ||
---|---|---|
4758 | 4758 |
|
4759 | 4759 |
|
4760 | 4760 |
-- |
4761 |
-- Name: remove_prefix(text, text, boolean); Type: FUNCTION; Schema: util; Owner: - |
|
4761 |
-- Name: remove_prefix(text, text, boolean, boolean); Type: FUNCTION; Schema: util; Owner: -
|
|
4762 | 4762 |
-- |
4763 | 4763 |
|
4764 |
CREATE FUNCTION remove_prefix(prefix text, str text, require boolean DEFAULT true) RETURNS text |
|
4764 |
CREATE FUNCTION remove_prefix(prefix text, str text, require boolean DEFAULT true, case_sensitive boolean DEFAULT true) RETURNS text
|
|
4765 | 4765 |
LANGUAGE sql IMMUTABLE STRICT |
4766 | 4766 |
AS $$ |
4767 | 4767 |
-- must be declared STRICT to handle NULL properly |
4768 | 4768 |
SELECT CASE |
4769 |
WHEN util.starts_with(prefix, str) THEN |
|
4769 |
WHEN util.starts_with(prefix, str, case_sensitive) THEN
|
|
4770 | 4770 |
substring(str from 1+length(prefix)) |
4771 | 4771 |
WHEN NOT require THEN str |
4772 | 4772 |
ELSE |
... | ... | |
4777 | 4777 |
|
4778 | 4778 |
|
4779 | 4779 |
-- |
4780 |
-- Name: remove_suffix(text, text, boolean); Type: FUNCTION; Schema: util; Owner: - |
|
4780 |
-- Name: remove_suffix(text, text, boolean, boolean); Type: FUNCTION; Schema: util; Owner: -
|
|
4781 | 4781 |
-- |
4782 | 4782 |
|
4783 |
CREATE FUNCTION remove_suffix(suffix text, str text, require boolean DEFAULT true) RETURNS text |
|
4783 |
CREATE FUNCTION remove_suffix(suffix text, str text, require boolean DEFAULT true, case_sensitive boolean DEFAULT true) RETURNS text
|
|
4784 | 4784 |
LANGUAGE sql IMMUTABLE STRICT |
4785 | 4785 |
AS $$ |
4786 | 4786 |
-- must be declared STRICT to handle NULL properly |
4787 | 4787 |
SELECT CASE |
4788 |
WHEN util.ends_with(suffix, str) THEN |
|
4788 |
WHEN util.ends_with(suffix, str, case_sensitive) THEN
|
|
4789 | 4789 |
substring(str from 1 for length(str)-length(suffix)) |
4790 | 4790 |
WHEN NOT require THEN str |
4791 | 4791 |
ELSE |
Also available in: Unified diff
schemas/util.sql: remove_prefix(), remove_suffix(): support case-insensitive matching