src/libmetha/str.c
char *
lm_strtourl(const char* str)
{
    int extra_size;
    const char *prefix;
    char *out;
    char *s = (char*)str;

    while (isalnum(*s))
        s++;

    if (*s == ':')
        return strdup(str); /* protocol is already set */

    if (*str == '/' || (*str == '.' && *(str+1) == '/')) {
        extra_size = 7;
        prefix = "file://";
    } else if (strncasecmp(str, "ftp.", 4) == 0) {
        extra_size = 6;
        prefix = "ftp://";
    } else {
        extra_size = 7;
        prefix = "http://";
    }

    if (!(out = malloc(strlen(str)+1+extra_size)))
        return 0;

    sprintf(out, "%s%s", prefix, str);

    return out;
}
/** 
 * This function does not actually convert the string to
 * a standards-compliant URL, but it only adds a protocol
 * infront of the given URL, guessing which protocol 
 * depending on how the string looks. Expected input is 
 * something like "www.google.com/x/" or "ftp.x.com".
 **/
This function does not actually convert the string to
a standards-compliant URL, but it only adds a protocol
infront of the given URL, guessing which protocol
depending on how the string looks.
This function does not actually convert the string to a standards - compliant URL but it only adds a protocol infront of the given URL guessing which protocol depending on how the string looks .
char *
lm_strtourl(const char* str)
{
    int extra_size;
    const char *prefix;
    char *out;
    char *s = (char*)str;
    while (isalnum(*s))
        s++;
    if (*s == ':')
        return strdup(str); 
    if (*str == '/' || (*str == '.' && *(str+1) == '/')) {
        extra_size = 7;
        prefix = "file://";
    } else if (strncasecmp(str, "ftp.", 4) == 0) {
        extra_size = 6;
        prefix = "ftp://";
    } else {
        extra_size = 7;
        prefix = "http://";
    }
    if (!(out = malloc(strlen(str)+1+extra_size)))
        return 0;
    sprintf(out, "%s%s", prefix, str);
    return out;
}
char * lm_strtourl ( const char * str ) { int extra_size ; const char * prefix ; char * out ; char * s = ( char * ) str ; while ( isalnum ( * s ) ) s ++ ; if ( * s == ' ' ) return strdup ( str ) ; if ( * str == ' ' || ( * str == ' ' && * ( str + 1 ) == ' ' ) ) { extra_size = 7 ; prefix = " " ; } else if ( strncasecmp ( str , " " , 4 ) == 0 ) { extra_size = 6 ; prefix = " " ; } else { extra_size = 7 ; prefix = " " ; } if ( ! ( out = malloc ( strlen ( str ) + 1 + extra_size ) ) ) return 0 ; sprintf ( out , " " , prefix , str ) ; return out ; }
This function does not actually convert the string to
 a standards-compliant URL, but it only adds a protocol
 infront of the given URL, guessing which protocol
 depending on how the string looks.
This function does not actually convert the string to a standards - compliant URL but it only adds a protocol infront of the given URL guessing which protocol depending on how the string looks .
/* protocol is already set */