REBOL3 tracker
  0.9.12 beta
Ticket #0002136 User: anonymous

Project:

Previous Next
rss
TypeWish Statuspending Date15-Mar-2014 09:18
Versionr3 master CategoryMezzanine Submitted byBrianH
PlatformAll Severityminor Prioritynormal

Summary Have SUFFIX? not include the query or fragment of URLs
Description If a URL has a query or fragment, SUFFIX? isn't valid. This makes it hard to load scripts or images from sites that do analytics. SUFFIX? should ignore that stuff, for URLs only. It shouldn't be much slower in the non-URL case, and would be more valid for URLs.

Initial implementation below. If it can be optimized more later, let's do that.

Requested by Graham Chiu in SO chat.
Example code
; Version with fairly normal, understandable control flow
suffix?: func [
    "Return the file suffix of a filename or url. Else, NONE."
    path [file! url! string!]
    /local end
][
    either all [
        url? path end: find path make bitset! "?#"
    ][
        all [
            path: find/reverse end #"."
            not find/part path #"/" end
            to file! copy/part path end
        ]
    ][
        all [
            path: find/last path #"."
            not find path #"/"
            to file! path
        ]
    ]
]


; Version with more optimized, harder-to-understand control flow (just mentioned for amusement's sake)
suffix?: func [
    "Return the file suffix of a filename or url. Else, NONE."
    path [file! url! string!]
    /local end
][
    all either/only all [
        url? path end: find path make bitset! "?#"
    ][
        path: find/reverse end #"."
        not find/part path #"/" end
        to file! copy/part path end
    ][
        path: find/last path #"."
        not find path #"/"
        to file! path
    ]
]

Assigned ton/a Fixed in- Last Update2-Mar-2015 11:24


Comments
(0004576)
BrianH
2-Mar-2015 11:24

PR: https://github.com/rebol/rebol/pull/211

Date User Field Action Change
2-Mar-2015 11:24 BrianH Status Modified reviewed => pending
2-Mar-2015 11:24 BrianH Comment : 0004576 Added -
26-Jan-2015 07:42 abolka Status Modified submitted => reviewed
15-Mar-2014 17:46 BrianH Description Modified -
15-Mar-2014 09:47 BrianH Code Modified -
15-Mar-2014 09:33 BrianH Code Modified -
15-Mar-2014 09:27 BrianH Code Modified -
15-Mar-2014 09:27 BrianH Description Modified -
15-Mar-2014 09:18 BrianH Ticket Added -