UDF: countHtmlLineBreaks() – return the number of BR tags in a string

Whenever I end up creating some fairly generic little UDF, I usually try to put up here in case some random person somewhere happens to find them useful. Inevitably, I always get *that guy* who gives me grief for doing so and tells me how I should have done it better or how I should have used Xyz() udf instead, but what the heck… here is another one.

I had a need this morning to be able to set the height of a div that contained an unordered list of strings based on the text it contained. I created an algorithm that was basically Ceiling(Len(string)/CharactersPerLine) for each item in the list and then determined the pixel height based on number of lines, but run into an issue where the text could contain tags. I needed a method for counting BR tags, and it should be able to find BR tags with any number of spaces and with or without a closing slash. This is what I came up with.

function countHtmlLineBreaks(String)	{
	var Count = 0;
	while (ReFindNoCase("<s*brs*/?s*>",arguments.String))	{
		Count = Count + 1;
		arguments.String = ReReplaceNoCase(String,"<s*brs*/?s*>","","one");
	return Count;

Josh Adams on Blue Dragon 7 at the DFWCFUG

Last night we were happy to have Josh Adams join us here in Dallas to present the soon-to-be-released Blue Dragon 7.0.  For those who may not have heard of Blue Dragon, it is an alternative engine to ColdFusion for processing CFML code on your webserver.   Josh is a good evangelist for New Atlanta and did a nice job presenting their product.

There are some really compelling features in BD, especially combined with .Net (yes, I just said something nice about .Net).  Their implementation of CFTHREAD is very cool.  He gave an example of a stock quote webservice that takes 2 seconds.  He modified the code to make four stock quote requests which upped the request time right at 8 seconds.   He then modified it once more wrapping each request with a CFTHREAD tag, with CFREJOIN tag below which is used as a stopping point in the original thread where the code will wait until the child threads have completed their work.  By specifying name attributes with the threads and using the CFRETURN tag within them, he was then able to return values from those threads into the original thread and output onto the page.  By taking this approach, the 4 stock quotes where brought back down to 2 seconds total by running them asynchronously. You don’t have to use a lot of imagination to see how helpful this could be!

A very cool .Net/MSSQL2005 only feature that they offer is a CachedUntilChanged attribute for CFQUERY.  It basically works like this.  When a query is made, the SQL Server will basically watch that recordset for any changes.  If any changes are made to it, the server will report back to the .Net/BD server.  In the mean time, as duplicate queries are made, the original recordset will be returned without ever making the trip to the SQL Server.  This is about as close to perfect query caching as you can get.  If only there was a similar solution for J2EE/MySQL solutions!  The downside to this in my opinion is that we might begin to see implementation-specific sets of code with disparities between not only different CFML processing engines, but even within the different versions of the engines.  I personally am not sure how good this will be for the language as a whole, but time will tell.

Another BD feature that he demonstrated last night was an answer to the heated debate in the ColdFusion community over interfaces.  With BD7, you can specify attributes to create abstract classes and interfaces.  He gave an example using a child class that used a “implements” attribute in CFCOMPONENT in addition to using the “extends” attribute.  I think their solution is quite sound as it doesn’t require anyone to use it, nor does it somehow make the language unnecessarily complex, yet it does provide some additional functionality for those who wish to use it.    Next debate:  Method overloading. :)

If you wish to play with BD7, there is a downloadable version of the release candidate on their website.  It is free of restrictions for 30 days, then effectively becomes a developer edition limiting the amount of IP addresses that can connect to it.

Thanks to Josh Adams for putting our CFUG on his schedule.