43 lines
1022 B
MySQL
43 lines
1022 B
MySQL
|
DELIMITER $$
|
||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`capitalizeFirst`(vString VARCHAR(255))
|
||
|
RETURNS varchar(255) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
|
||
|
DETERMINISTIC
|
||
|
NO SQL
|
||
|
BEGIN
|
||
|
/**
|
||
|
* Pass the first letter of every word in a string to uppercase.
|
||
|
*
|
||
|
* @param vString String to tranform
|
||
|
* @return Transformed string
|
||
|
*/
|
||
|
DECLARE vNewString VARCHAR(255) DEFAULT '';
|
||
|
DECLARE vI INT DEFAULT 1;
|
||
|
DECLARE vSpaceIni, vWordIni INT;
|
||
|
DECLARE vLen INT DEFAULT CHAR_LENGTH(vString);
|
||
|
|
||
|
WHILE vI < vLen
|
||
|
DO
|
||
|
SET vSpaceIni = vI;
|
||
|
|
||
|
WHILE MID(vString, vI, 1) REGEXP '[[:space:]]' DO
|
||
|
SET vI = vI + 1;
|
||
|
END WHILE;
|
||
|
|
||
|
SET vWordIni = vI;
|
||
|
SET vI = vWordIni + 1;
|
||
|
|
||
|
WHILE vI <= vLen AND MID(vString, vI, 1) NOT REGEXP '[[:space:]]' DO
|
||
|
SET vI = vI + 1;
|
||
|
END WHILE;
|
||
|
|
||
|
SET vNewString = CONCAT(vNewString
|
||
|
,MID(vString, vSpaceIni, vWordIni - vSpaceIni)
|
||
|
,UPPER(MID(vString, vWordIni, 1))
|
||
|
,MID(vString, vWordIni + 1, vI - vWordIni - 1)
|
||
|
);
|
||
|
END WHILE;
|
||
|
|
||
|
RETURN vNewString;
|
||
|
END$$
|
||
|
DELIMITER ;
|