Guest User

Untitled

a guest
Mar 25th, 2011
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Joe.cfc */
  2.  
  3. component{
  4.     public struct function letterinator(msg){
  5.         var s = {};
  6.         var nospaces = replace(trim(arguments.msg), ' ', '', 'all');
  7.         var arr = listToArray(nospaces,"");
  8.         var i = '';
  9.         var el = '';
  10.    
  11.         for(i=1; i<=arrayLen(arr); i++){
  12.             el = arr[i];
  13.             if(structKeyExists(s, el)){
  14.                 s[el]++;
  15.             }
  16.             else{
  17.                 s[el] = 1;
  18.             }
  19.         }
  20.         return s;
  21.     }
  22.    
  23.     public function slotinator(msg,width){
  24.         var m = arguments.msg;
  25.         var isComplete = false;
  26.         var row = '';
  27.         var ret = [];
  28.  
  29.         while(!isComplete){
  30.             row = fullLeft(trim(m), width);
  31.             if(len(row)){
  32.                 arrayAppend(ret,row);
  33.                 m = replaceNoCase(m,row,"");
  34.             }          
  35.             else{
  36.                 isComplete = true;
  37.             }
  38.         }
  39.  
  40.         return ret;
  41.     }
  42.    
  43.     public struct function getSignInfo(msg, width){
  44.         var s = {};
  45.         s.letters = letterinator(arguments.msg);
  46.         s.words = slotinator(arguments.msg, arguments.width);
  47.         return s;
  48.     }
  49.  
  50.     /**
  51.     * An enhanced version of left() that doesn't cut words off in the middle.
  52.     * Minor edits by Rob Brooks-Bilson ([email protected]) and Raymond Camden ([email protected]@camdenfamily.com)
  53.     *
  54.     * Updates for version 2 include fixes where count was very short, and when count+1 was a space. Done by RCamden.
  55.     *
  56.     * @param str      String to be checked.
  57.     * @param count      Number of characters from the left to return.
  58.     * @return Returns a string.
  59.     * @author Marc Esher ([email protected]@[email protected])
  60.     * @version 2, April 16, 2002
  61.     */
  62.    
  63.     /**
  64.     * An enhanced version of left() that doesn't cut words off in the middle.
  65.     * Minor edits by Rob Brooks-Bilson (&#114;&#98;&#105;&#108;&#115;&#64;&#97;&#109;&#107;&#111;&#114;&#46;&#99;&#111;&#109;) and Raymond Camden (&#114;&#98;&#105;&#108;&#115;&#64;&#97;&#109;&#107;&#111;&#114;&#46;&#99;&#111;&#109;&#114;&#97;&#121;&#64;&#99;&#97;&#109;&#100;&#101;&#110;&#102;&#97;&#109;&#105;&#108;&#121;&#46;&#99;&#111;&#109;)
  66.     *
  67.     * Updates for version 2 include fixes where count was very short, and when count+1 was a space. Done by RCamden.
  68.     *
  69.     * @param str      String to be checked.
  70.     * @param count      Number of characters from the left to return.
  71.     * @return Returns a string.
  72.     * @author Marc Esher (&#114;&#98;&#105;&#108;&#115;&#64;&#97;&#109;&#107;&#111;&#114;&#46;&#99;&#111;&#109;&#114;&#97;&#121;&#64;&#99;&#97;&#109;&#100;&#101;&#110;&#102;&#97;&#109;&#105;&#108;&#121;&#46;&#99;&#111;&#109;&#106;&#111;&#110;&#110;&#121;&#99;&#97;&#116;&#116;&#116;&#64;&#97;&#111;&#108;&#46;&#99;&#111;&#109;)
  73.     * @version 2, April 16, 2002
  74.     */
  75.     function fullLeft(str, count) {
  76.         if (not refind("[[:space:]]", str) or (count gte len(str)))
  77.             return Left(str, count);
  78.         else if(reFind("[[:space:]]",mid(str,count+1,1))) {
  79.              return left(str,count);
  80.         } else {
  81.             if(count-refind("[[:space:]]", reverse(mid(str,1,count)))) return Left(str, (count-refind("[[:space:]]", reverse(mid(str,1,count)))));
  82.             else return(left(str,1));
  83.         }
  84.     }
  85. }
  86.  
  87. /*index.cfm*/
  88.  
  89. <cfscript>
  90. joe = new Joe();
  91. msg = 'Free Carwash For Every American Car!  Today Only!!';
  92. slots = 15;
  93. writeDump(joe.getSignInfo(msg,slots));
  94. </cfscript>
Advertisement
Add Comment
Please, Sign In to add comment