Subject Re: UDF - another way?
Author Adam
Why do you want to do that?

You could probably rewrite it using the ib_udf functions, but that is
still using a UDF.

Unless you are asking about wrapping it inside a stored procedure

CREATE PROCEDURE SP_TitleCase
(
INTITLE VARCHAR(100)
)
RETURNS
(
OUTTITLE VARCHAR(100)
)
AS
BEGIN
OUTTITLE = fn_titlecase(INTITLE);
SUSPEND;
END

Then you can just say
select OUTTITLE from SP_TitleCase(' hello world !!');

and get

' Hello World !!'

(if I have read your code correctly)

Adam


--- In firebird-support@yahoogroups.com, Nick Upson <nick@u...> wrote:
> I'd rather implement this as an SP than a UDF, can anyone see a
efficient way
> to do so?
>
> char* EXPORT fn_titlecase(char* s)
> {
> char *buffer = (char *)malloc(256);
> short j = 0;
> char *pos1;
>
> while (*s == ' ') /* skip leading blanks */
> s++;
>
> *s = toupper(*s); /* uppercase first char */
>
> while (*s) /* copy the rest */
> {
> buffer[j++] = *s++;
> }
>
> buffer[j] = '\0';
>
> /* convert any character that follows a space and first char */
> for (pos1 = buffer, pos1 = strstr(pos1, " "); pos1 != NULL;
pos1 =
> strstr(pos1, " "))
> {
> pos1 = pos1 + 1;
> *pos1 = toupper(*pos1);
> }
>
> /* convert character following special strings */
>
> for (pos1 = buffer, pos1 = strstr(pos1, "-"); pos1 != NULL;
pos1 =
> strstr(pos1, "-"))
> {
> pos1 = pos1 + 1;
> *pos1 = toupper(*pos1);
> }
> for (pos1 = buffer, pos1 = strstr(pos1, "'"); pos1 != NULL;
pos1 =
> strstr(pos1, "'"))
> {
> pos1 = pos1 + 1;
> if ( (pos1 - 3) < buffer || *(pos1 - 3) == ' ') /*
only if
> preceeded by space, letter */
> *pos1 = toupper(*pos1);
> }
> for (pos1 = buffer, pos1 = strstr(pos1, "("); pos1 != NULL;
pos1 =
> strstr(pos1, "("))
> {
> pos1 = pos1 + 1;
> *pos1 = toupper(*pos1);
> }
> for (pos1 = buffer, pos1 = strstr(pos1, "Mc"); pos1 != NULL;
pos1 =
> strstr(pos1, "Mc"))
> {
> pos1 = pos1 + 2;
> *pos1 = toupper(*pos1);
> }
>
> buffer [strlen(s)-1] = '\0';
> return buffer;
> }