Subject | UDF - another way? |
---|---|
Author | Nick Upson |
Post date | 2004-12-21T15:17:08Z |
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;
}
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;
}