naming convention

Discussion in 'C++' started by angie, Apr 2, 2008.

  1. angie

    angie Guest

    how can i validate a field for a valid URL?? is ther any naming
    conventions for it?
    angie, Apr 2, 2008
    #1
    1. Advertising

  2. angie a écrit :
    > how can i validate a field for a valid URL?? is ther any naming
    > conventions for it?


    Same as for your question about identifying the IP address.
    You can check again a regex (there are many already done out there).
    A good starting point is:
    http://regexlib.com/DisplayPatterns.aspx?cattabindex=1&categoryId=2

    Michael
    Michael DOUBEZ, Apr 2, 2008
    #2
    1. Advertising

  3. angie

    James Kanze Guest

    On Apr 2, 2:46 pm, Michael DOUBEZ <> wrote:
    > angie a écrit :


    > > how can i validate a field for a valid URL?? is ther any naming
    > > conventions for it?


    > Same as for your question about identifying the IP address.
    > You can check again a regex (there are many already done out there).
    > A good starting point is:http://regexlib.com/DisplayPatterns.aspx?cattabindex=1&categoryId=2


    Except that a regular expression which accepts all syntactically
    valid URL's, and rejects all syntactically invalid ones, is far
    from trivial; the one you cite, for example, will reject a lot
    of legal URL's ("news://comp.lang.c%2B%2B", for example:), and
    accept a few illegal ones (e.g. "www."). I pretty sure it can
    be done with a regular expression, but it will take a bit of
    work to get it right. (Note too that different types of URL's
    may have slightly different syntax. If the protocol is
    "mailto", for example, a '@' is required at one point, whereas
    if it is "http", one may not appear unless quoted somehow (e.g.
    "%40").

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Apr 3, 2008
    #3
  4. James Kanze a écrit :
    > On Apr 2, 2:46 pm, Michael DOUBEZ <> wrote:
    >> angie a écrit :

    >
    >>> how can i validate a field for a valid URL?? is ther any naming
    >>> conventions for it?

    >
    >> Same as for your question about identifying the IP address.
    >> You can check again a regex (there are many already done out there).
    >> A good starting point is:http://regexlib.com/DisplayPatterns.aspx?cattabindex=1&categoryId=2

    >
    > Except that a regular expression which accepts all syntactically
    > valid URL's, and rejects all syntactically invalid ones, is far
    > from trivial; the one you cite, for example, will reject a lot
    > of legal URL's ("news://comp.lang.c%2B%2B", for example:), and
    > accept a few illegal ones (e.g. "www."). I pretty sure it can
    > be done with a regular expression, but it will take a bit of
    > work to get it right.


    Yes. That is why I provided the link to a regex library instead of
    giving a specific regex. The site indicate what URI are accepted or
    rejected depending on the regex used.

    > (Note too that different types of URL's
    > may have slightly different syntax. If the protocol is
    > "mailto", for example, a '@' is required at one point, whereas
    > if it is "http", one may not appear unless quoted somehow (e.g.
    > "%40").


    Or ftp that uses @ to separate the username/password from the actual
    address:
    ftp://john_dow::245/path/to/data

    Perhaps Boost.Spirit would be more fitting for capturing more complex
    URI. At least It would be more manageable.

    Michael
    Michael DOUBEZ, Apr 3, 2008
    #4
  5. angie

    James Kanze Guest

    On Apr 3, 12:59 pm, Michael DOUBEZ <> wrote:
    > James Kanze a écrit :
    > > On Apr 2, 2:46 pm, Michael DOUBEZ <> wrote:
    > >> angie a écrit :


    > >>> how can i validate a field for a valid URL?? is ther any naming
    > >>> conventions for it?


    > >> Same as for your question about identifying the IP address.
    > >> You can check again a regex (there are many already done out there).
    > >> A good starting point is:http://regexlib.com/DisplayPatterns.aspx?cattabindex=1&categoryId=2


    > > Except that a regular expression which accepts all syntactically
    > > valid URL's, and rejects all syntactically invalid ones, is far
    > > from trivial; the one you cite, for example, will reject a lot
    > > of legal URL's ("news://comp.lang.c%2B%2B", for example:), and
    > > accept a few illegal ones (e.g. "www."). I pretty sure it can
    > > be done with a regular expression, but it will take a bit of
    > > work to get it right.


    > Yes. That is why I provided the link to a regex library
    > instead of giving a specific regex. The site indicate what URI
    > are accepted or rejected depending on the regex used.


    If the goal is to use a regular expression library, boost::regex
    is clearly indicated, except in very special cases. I say this
    as someone who has made available a regular expression
    library---use Boost's, instead of mine, except in special cases.
    (I'm still maintaining mine, but mainly in view of supporting a
    few special cases, especially generating the regular expression
    as compilable static data, which Boost doesn't support.)

    > > (Note too that different types of URL's may have slightly
    > > different syntax. If the protocol is "mailto", for example,
    > > a '@' is required at one point, whereas if it is "http", one
    > > may not appear unless quoted somehow (e.g. "%40").


    > Or ftp that uses @ to separate the username/password from the actual
    > address:
    > ftp://john_dow::245/path/to/data


    > Perhaps Boost.Spirit would be more fitting for capturing more
    > complex URI. At least It would be more manageable.


    In a sense, there is no solution, because the actual syntax
    depends on the protocol, and protocols can be added at any time.
    Typically, of course, you don't care: if you can't handle the
    protocol (and you can't handle those you don't know about), then
    the URL is illegal, as far as you're concerned. So I'd say use
    std::find to get the position of the first ':', consider
    everything up to that to be the protocol, and use a regular
    expression to handle the rest, depending on the protocol.

    Just be aware that you have to read the standard concerning the
    protocol very carefully, and that the regular expression might
    not be that obvious, but needs to be very carefully thought out.
    With things like "([[:alnum:]...]|%[:xdigit:][:xdigit:])+",
    instead of simply "[:alnum:]+".


    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Apr 3, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick

    Which c# naming convention?

    Rick, Jan 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,760
    Paul Glavich
    Jan 19, 2004
  2. dm1608
    Replies:
    6
    Views:
    8,489
  3. Buck Turgidson

    JSP Method Naming Convention

    Buck Turgidson, Mar 2, 2004, in forum: Java
    Replies:
    1
    Views:
    1,733
    P.Hill
    Mar 2, 2004
  4. harry
    Replies:
    2
    Views:
    1,165
    harry
    Dec 8, 2004
  5. Roedy Green

    Naming Convention(s)

    Roedy Green, Sep 3, 2005, in forum: Java
    Replies:
    24
    Views:
    951
    Dale King
    Sep 12, 2005
Loading...

Share This Page