I have this function to generate slugs in Coldfusion:
<cffunction name="generateSlug" output="false" returnType="string">
<cfargument name="str">
<cfargument name="spacer" default="-">
<cfset var ret = "" />
<cfset str = lCase(trim(str)) />
<cfset str = reReplace(str, "[àáâãäå]", "a", "all") />
<cfset str = reReplace(str, "[èéêë]", "e", "all") />
<cfset str = reReplace(str, "[ìíîï]", "i", "all") />
<cfset str = reReplace(str, "[òóôö]", "o", "all") />
<cfset str = reReplace(str, "[ùúûü]", "u", "all") />
<cfset str = reReplace(str, "[ñ]", "n", "all") />
<cfset str = reReplace(str, "[^a-z0-9-]", "#spacer#", "all") />
<cfset ret = reReplace(str, "#spacer#+", "#spacer#", "all") />
<cfif left(ret, 1) eq "#spacer#">
<cfset ret = right(ret, len(ret)-1) />
</cfif>
<cfif right(ret, 1) eq "#spacer#">
<cfset ret = left(ret, len(ret)-1) />
</cfif>
<cfreturn ret />
</cffunction>
and then i am calling it using this:
<cfset stringToBeSlugged = "This is a string abcde àáâãäå èéêë ìíîï òóôö ùúûü ñ año ñññññññññññññ" />
<cfset slug = generateSlug(stringToBeSlugged) />
<cfoutput>#slug#</cfoutput>
But this is output me this slug:
this-is-a-string-abcde-a-a-a-a-a-a-e-e-e-e-i-i-i-i-o-o-o-o-u-u-u-u-n-a-no-n-n-n-n-n-n-n-n-n-n-n-n-n
it seems that all the accented characters are correctly replaced but this function is inserting a '-' after replacing them. Why?
Where is the error?
PD: i am expecting this output:
this-is-a-string-abcde-aaaaaa-eeee-iiii-oooo-uuuu-n-ano-nnnnnnnnnnnnn
Thanks.