====== pears.URLSafe ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create function "pears"."URLSafe"(
/* Application Maintained Function / Procedure - DO NOT EDIT*/
in "OldString" long varchar )
returns long varchar
begin
-- Partial solution. £ is the only multi-byte utf-8 char handled. If possible use the Delphi or jobrunner httpsafe implementations
declare "NewString" long varchar;
declare "StringLength" smallint;
declare "CurrentChar" char(10);
declare "CurrentPos" smallint;
declare "AsciiVal" smallint;
declare "SafeChars" char(250);
if "OldString" is null then return(null)
end if;
set "stringlength" = "length"("OldString");
set "CurrentPos" = 1;
set "NewString" = '';
set "SafeChars" = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*''()';
"process": loop
set "CurrentChar" = "substr"("OldString","CurrentPos",1);
if "CurrentChar" = '£' then
set "CurrentChar" = '%C2%A3'
else if "charindex"("CurrentChar","SafeChars") = 0 then
set "CurrentChar" = "ucase"("string"('%',"right"("IntToHex"("ascii"("CurrentChar")),2)))
end if end if;
set "NewString" = "NewString" || "CurrentChar";
set "CurrentPos" = "CurrentPos"+1;
if "CurrentPos" > "StringLength" then leave "process"
end if
end loop "process";
return("NewString")
end