Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Joe.cfc */
- component{
- public struct function letterinator(msg){
- var s = {};
- var nospaces = replace(trim(arguments.msg), ' ', '', 'all');
- var arr = listToArray(nospaces,"");
- var i = '';
- var el = '';
- for(i=1; i<=arrayLen(arr); i++){
- el = arr[i];
- if(structKeyExists(s, el)){
- s[el]++;
- }
- else{
- s[el] = 1;
- }
- }
- return s;
- }
- public function slotinator(msg,width){
- var m = arguments.msg;
- var isComplete = false;
- var row = '';
- var ret = [];
- while(!isComplete){
- row = fullLeft(trim(m), width);
- if(len(row)){
- arrayAppend(ret,row);
- m = replaceNoCase(m,row,"");
- }
- else{
- isComplete = true;
- }
- }
- return ret;
- }
- public struct function getSignInfo(msg, width){
- var s = {};
- s.letters = letterinator(arguments.msg);
- s.words = slotinator(arguments.msg, arguments.width);
- return s;
- }
- /**
- * An enhanced version of left() that doesn't cut words off in the middle.
- * Minor edits by Rob Brooks-Bilson ([email protected]) and Raymond Camden ([email protected]@camdenfamily.com)
- *
- * Updates for version 2 include fixes where count was very short, and when count+1 was a space. Done by RCamden.
- *
- * @param str String to be checked.
- * @param count Number of characters from the left to return.
- * @return Returns a string.
- * @author Marc Esher ([email protected]@[email protected])
- * @version 2, April 16, 2002
- */
- /**
- * An enhanced version of left() that doesn't cut words off in the middle.
- * Minor edits by Rob Brooks-Bilson (rbils@amkor.com) and Raymond Camden (rbils@amkor.comray@camdenfamily.com)
- *
- * Updates for version 2 include fixes where count was very short, and when count+1 was a space. Done by RCamden.
- *
- * @param str String to be checked.
- * @param count Number of characters from the left to return.
- * @return Returns a string.
- * @author Marc Esher (rbils@amkor.comray@camdenfamily.comjonnycattt@aol.com)
- * @version 2, April 16, 2002
- */
- function fullLeft(str, count) {
- if (not refind("[[:space:]]", str) or (count gte len(str)))
- return Left(str, count);
- else if(reFind("[[:space:]]",mid(str,count+1,1))) {
- return left(str,count);
- } else {
- if(count-refind("[[:space:]]", reverse(mid(str,1,count)))) return Left(str, (count-refind("[[:space:]]", reverse(mid(str,1,count)))));
- else return(left(str,1));
- }
- }
- }
- /*index.cfm*/
- <cfscript>
- joe = new Joe();
- msg = 'Free Carwash For Every American Car! Today Only!!';
- slots = 15;
- writeDump(joe.getSignInfo(msg,slots));
- </cfscript>
Advertisement
Add Comment
Please, Sign In to add comment