ManiaLib 1.0b1 API Reference

Source for file TMStrings.class.php

Documentation is available at TMStrings.class.php

  1. <?php 
  2. /**
  3.  * @author Maxime Raoust
  4.  * @copyright 2009-2010 NADEO
  5.  * @package ManiaLib
  6.  */
  7.  
  8. /** 
  9.  * Misc functions for TM styled strings
  10.  * @package ManiaLib
  11.  * @subpackage Helpers
  12.  */ 
  13. abstract class TMStrings
  14. {
  15.     /**
  16.      * Allows to safely put any TM-formatted string into another TM-formatted string
  17.      * without conflicts (conflict example: you put a nickname in the middle of the
  18.      * sentance, the nickname has some bold characters and all the end of the
  19.      * sentance becomes bold)
  20.      * @param string Unprotected string
  21.      * @param string Protected string
  22.      */
  23.     static function protectStyles($string)
  24.     {
  25.         return '$<'.$string.'$>';
  26.     }
  27.     
  28.     /**
  29.      * Removes some TM styles (wide, bold and shadowed) to avoid wide words
  30.      * @param string 
  31.      * @return string 
  32.      */
  33.     static function stripWideFonts($string)
  34.     {
  35.         return str_replace(array (
  36.             '$w',
  37.             '$o',
  38.             '$s'
  39.         )""$string);
  40.     }
  41.     
  42.     /**
  43.      * Removes TM links
  44.      * @param string 
  45.      * @return string 
  46.      */
  47.     static function stripLinks($string)
  48.     {
  49.         return preg_replace(
  50.             '/\\$[hlp](.*?)(?:\\[.*?\\](.*?))?(?:\\$[hlp]|$)/ixu''$1$2'
  51.             $string);
  52.     }
  53. }
  54.  
  55.  
  56. ?>