Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Keith Gaughan http://talideon.com/

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Clean magic quoting in ColdFusion 5 and later

I'm updating my weblog software and needed some code to properly convert typewriter quotes to proper typographer's quotes.

<cfscript>
function magicQuote(txt) {
    // Left quotes
    txt = REReplace(txt, "(^|[ " & Chr(9) & Chr(10) & Chr(13) & "'])""", "\1&##8220;", "ALL");
    txt = REReplace(txt, "(^|[ " & Chr(9) & Chr(10) & Chr(13) & "]|&##8220;)'",  "\1&##8216;", "ALL");

    // Right quotes
    txt = Replace(txt, """",        "&##8221;",  "ALL");
    txt = Replace(txt, "'&##8220;", "'&##8221;", "ALL");
    txt = Replace(txt, "'",         "&##8217;",  "ALL");

    return txt;
}
</cfscript>

ColdFusion 5 has problems with \s, and the character class is a workaround for this.

Removing duplicates from lists

A request for this came up on the CF-Talk list recently. Here's what I came up with.
<!--- The list with want to clean up --->
<cfset lst = "a,list,with,a,few,duplicates">
<!--- Use a struct to build a set of the list elements --->
<cfset set = StructNew()>
<cfloop index="elem" list="#lst#">
    <cfset set[elem] = "">
</cfloop>
<!--- Convert the set back to a list --->
<cfset lst = StructKeyList(set)>

This sort of this should be familiar to all you perlmongers out there.
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS