<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flagrant Badassery &#187; ColdFusion</title>
	<atom:link href="http://blog.stevenlevithan.com/category/coldfusion/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.stevenlevithan.com</link>
	<description>A JavaScript and regular expression centric blog</description>
	<lastBuildDate>Mon, 05 Jul 2010 20:27:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>More URI-Related UDFs</title>
		<link>http://blog.stevenlevithan.com/archives/more-uri-udfs</link>
		<comments>http://blog.stevenlevithan.com/archives/more-uri-udfs#comments</comments>
		<pubDate>Sat, 03 Feb 2007 07:17:10 +0000</pubDate>
		<dc:creator>Steven Levithan</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[udf]]></category>
		<category><![CDATA[uri]]></category>

		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=11</guid>
		<description><![CDATA[To follow up my parseUri() function, here are several more UDFs I've written recently to help with URI management:


	getPageUri()
		Returns a struct containing the relative and absolute URIs of the current page. The difference between getPageUri().relative and CGI.SCRIPT_NAME is that the former will include the query string, if present.
	matchUri(testUri, [masterUri])
		Returns a Boolean indicating whether or not [...]]]></description>
			<content:encoded><![CDATA[<p>To follow up my <a href="/archives/parseuri-split-url-coldfusion">parseUri()</a> function, here are several more UDFs I've written recently to help with URI management:</p>

<ul>
	<li><strong>getPageUri()</strong><br />
		Returns a struct containing the relative and absolute URIs of the current page. The difference between <code>getPageUri().relative</code> and <code>CGI.SCRIPT_NAME</code> is that the former will include the query string, if present.</li>
	<li><strong>matchUri(testUri, [masterUri])</strong><br />
		Returns a Boolean indicating whether or not two URIs are the same, disregarding the following differences:
		<ul>
			<li>Fragments (page anchors), e.g., "#top".</li>
			<li>Inclusion of "index.cfm" in paths, e.g., "/dir/" vs. "/dir/index.cfm" (supports trailing query strings).</li>
		</ul>
		If <code>masterUri</code> is not provided, the current page is used for comparison (supports both relative and absolute URIs).</li>
	<li><strong>replaceUriQueryKey(uri, key, substring)</strong><br />
		Replaces a URI query key and its value with a supplied key=value pair. Works with relative and absolute URIs, as well as standalone query strings (with or without a leading "?"). This is also used to support the following two UDFs:</li>
	<li><strong>addUriQueryKey(uri, key, value)</strong><br />
		Removes any existing instances of the supplied key, then appends it together with the provided value to the provided URI.</li>
	<li><strong>removeUriQueryKey(uri, key)</strong><br />
	Removes one or more query keys (comma delimited) and their values from the provided URI.</li>
</ul>

<p><a class="demoLink" href="http://stevenlevithan.com/demo/uriUdfs.cfm">View the source code</a>.</p>

<p>Now that I have these at my disposal, I frequently find myself using them in combination with each other. E.g.:</p>

<pre class="code">&lt;a href="&lt;cfoutput&gt;#addUriQueryKey(
	getPageUri().relative,
	"key",
	"value"
)#&lt;/cfoutput&gt;"&gt;Link&lt;/a&gt;.
</pre>

<p>Let me know if you find any of these useful.</p>

<p>In other news, <a href="http://xkcd.com/c208.html">this</a> cracked me up.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.stevenlevithan.com/archives/more-uri-udfs/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>parseUri: Split URLs in ColdFusion</title>
		<link>http://blog.stevenlevithan.com/archives/parseuri-split-url-coldfusion</link>
		<comments>http://blog.stevenlevithan.com/archives/parseuri-split-url-coldfusion#comments</comments>
		<pubDate>Thu, 01 Feb 2007 05:40:37 +0000</pubDate>
		<dc:creator>Steven Levithan</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[parseuri]]></category>
		<category><![CDATA[udf]]></category>

		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=10</guid>
		<description><![CDATA[
Update: I've added a JavaScript implementation of the following UDF. See parseUri: Split URLs in JavaScript.


Here's a UDF I wrote recently which allows me to show off my regex skillz. parseUri() splits any well-formed URI into its components (all are optional).

The core code is already very brief, but I could replace everything within the &#60;cfloop&#62; [...]]]></description>
			<content:encoded><![CDATA[<div class="update">
<p><strong>Update:</strong> I've added a JavaScript implementation of the following UDF. See <a href="/archives/parseuri"><strong>parseUri: Split URLs in JavaScript</strong></a>.</p>
</div>

<p>Here's a UDF I wrote recently which allows me to show off my regex skillz. <code>parseUri()</code> splits any well-formed URI into its components (all are optional).</p>

<p>The core code is already very brief, but I could replace everything within the <code>&lt;cfloop&gt;</code> with one line of code if I didn't have to account for bugs in the <code>reFind()</code> function (tested in CF7). Note that all components are split with a single regex, using backreferences. My favorite part of this UDF is its robust support for splitting the directory path and filename (it supports directories with periods, and without a trailing backslash), which I haven't seen matched in other URI parsers.</p>

<p>Since the function returns a struct, you can do, e.g., <code>parseUri(uri).anchor</code>, etc. Check it out:</p>

<p><a class="demoLink" href="http://stevenlevithan.com/demo/parseuri/cf/">See the demo and get the source code</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.stevenlevithan.com/archives/parseuri-split-url-coldfusion/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>REMatch (ColdFusion)</title>
		<link>http://blog.stevenlevithan.com/archives/rematch-coldfusion</link>
		<comments>http://blog.stevenlevithan.com/archives/rematch-coldfusion#comments</comments>
		<pubDate>Thu, 01 Feb 2007 05:03:03 +0000</pubDate>
		<dc:creator>Steven Levithan</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Regular Expressions]]></category>
		<category><![CDATA[udf]]></category>

		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=9</guid>
		<description><![CDATA[Following are some UDFs I wrote recently to make using regexes in ColdFusion a bit easier. The biggest deal here is my reMatch() function.

reMatch(), in its most basic usage, is similar to JavaScript's String.prototype.match() method. Compare getting the first number in a string using reMatch() vs. built-in ColdFusion functions:


	reMatch:
		&#60;cfset num = reMatch("\d+", string) /&#62;
	reReplace:
		&#60;cfset num [...]]]></description>
			<content:encoded><![CDATA[<p>Following are some <acronym title="User-Defined Function">UDF</acronym>s I wrote recently to make using regexes in ColdFusion a bit easier. The biggest deal here is my <code>reMatch()</code> function.</p>

<p><code>reMatch()</code>, in its most basic usage, is similar to JavaScript's <code>String.prototype.match()</code> method. Compare getting the first number in a string using <code>reMatch()</code> vs. built-in ColdFusion functions:</p>

<ul>
	<li><strong>reMatch:</strong><br />
		<code>&lt;cfset num = reMatch("\d+", string) /&gt;</code></li>
	<li><strong>reReplace:</strong><br />
		<code>&lt;cfset num = reReplace(string, "\D*(\d+).*", "\1") /&gt;</code></li>
	<li><strong>reFind:</strong><br />
		<code>&lt;cfset match = reFind("\d+", string, 1, TRUE) /&gt;<br />
		&lt;cfset num = mid(string, match.pos[1], match.len[1]) /&gt;</code></li>
</ul>

<p>All of the above would return the same result, unless a number wasn't found in the string, in which case the <code>reFind()</code>-based method would throw an error since the <code>mid()</code> function would be passed a <code>start</code> value of 0. I think it's pretty clear from the above which approach is easiest to use for a situation like this, and it would be easy to envision scenarios where this functionality could more drastically improve code brevity.</p>

<p>Still, that's just the beginning of what <code>reMatch()</code> can do. Change the <code>scope</code> argument from the default of "ONE" to "ALL" (to follow the convention used by <code>reReplace()</code>, etc.), and the function will return an array of all matches. Finally, set the <code>returnLenPos</code> argument to TRUE and the function will return either a struct or array of structs (based on the value of <code>scope</code>) containing the len, pos, AND value of each match. This is very different from how the <code>returnSubExpressions</code> argument of <code>reFind()</code> works. When using <code>returnSubExpressions</code>, you get back a struct containing arrays of the len and pos (but not value) of each backreference from the first match.</p>

<p>Here's the code, with four additional UDFs (<code>reMatchNoCase()</code>, <code>match()</code>, <code>matchNoCase()</code>, and <code>reEscape()</code>) added for good measure:</p>

<p><a class="demoLink" href="http://stevenlevithan.com/demo/reMatch.cfm">See the demo and get the source code</a>.</p>

<p>Now that I've got a deeply featured match function, all I need Adobe to add to ColdFusion in the way to regex support is lookbehinds, atomic groups, possessive quantifiers, conditionals, balancing groups, etc., etc.&hellip;</p>]]></content:encoded>
			<wfw:commentRss>http://blog.stevenlevithan.com/archives/rematch-coldfusion/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Leet Translator</title>
		<link>http://blog.stevenlevithan.com/archives/leet-translator</link>
		<comments>http://blog.stevenlevithan.com/archives/leet-translator#comments</comments>
		<pubDate>Wed, 29 Mar 2006 02:47:21 +0000</pubDate>
		<dc:creator>Steven Levithan</dc:creator>
				<category><![CDATA[ColdFusion]]></category>

		<guid isPermaLink="false">http://blog.stevenlevithan.com/?p=6</guid>
		<description><![CDATA[Apparently I had two minutes to waste writing a super-simple 1337 translator in ColdFusion. I figured I might as well pass it on&#8230;

See it in action and get the source code.]]></description>
			<content:encoded><![CDATA[<p>Apparently I had two minutes to waste writing a super-simple <a href="http://en.wikipedia.org/wiki/Leet">1337</a> translator in ColdFusion. I figured I might as well pass it on&hellip;</p>

<p><strong><a href="http://stevenlevithan.com/demo/leetTranslator.cfm">See it in action and get the source code</a></strong>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.stevenlevithan.com/archives/leet-translator/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>
