80 Character String Truncation

Tintin++ String manipulation leaves something to be desired.

Here's a function that I find useful for displaying messages to the screen etc. It takes an input string and outputs an array of lines, truncating each one at the last space before the 80 character limit (or at character 80, if there are no spaces).

E.G.

#FORALL {@fTrunc80{Some Text that I would like to be truncated to 80 characters}}
{
  #SHOWME &0;
};
#function {fTrunc80}
{
  #VAR {vCharCount} {0};
  #VAR {vCurrLine} {$gvNull};
  #VAR {vCurrWord} {$gvNull};
  #LIST {result} {clr};
  #PARSE {%0}
  {
    #MATH {vCharCount} {$vCharCount + 1};
    #IF {"&0" == " "} 
    {
      #IF {"$vCurrLine" == "$gvNull"}
      {
        #VAR {vCurrLine} {$vCurrWord};
      }
      {
        #VAR {vCurrLine} {$vCurrLine $vCurrWord};
      };
      #VAR {vCurrWord} {$gvNull};
    }
    {
      #VAR {vCurrWord} {${vCurrWord}&0};
    };
    #IF {$vCharCount > 80} 
    {
      #IF {"$vCurrLine" == "$gvNull"}
      {
        #VAR {vCurrLine} {$vCurrWord};
        #VAR {vCurrWord} {$gvNull};
      };
      #LIST {result} {ins} {-1} {$vCurrLine};
      #VAR {vCurrLine} {$gvNull};
      #VAR {vCharCount} {0};
    };
  };
  #VAR {vCurrLine} {$vCurrLine $vCurrWord};
  #LIST {result} {ins} {-1} {$vCurrLine};
  #UNVAR {vCharCount};
  #UNVAR {vCurrLine};
  #UNVAR {vCurrWord};
};
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License