oxutilsstring.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxUtilsString
00007 {
00013     private static $_instance = null;
00014 
00020     public function __construct()
00021     {
00022     }
00023 
00029     public static function getInstance()
00030     {
00031         // disable caching for test modules
00032         if ( defined( 'OXID_PHP_UNIT' ) ) {
00033             self::$_instance = modInstances::getMod( __CLASS__ );
00034         }
00035 
00036         if ( !self::$_instance instanceof oxUtilsString ) {
00037 
00038 
00039             self::$_instance = oxNew( 'oxUtilsString' );
00040 
00041             if ( defined( 'OXID_PHP_UNIT' ) ) {
00042                 modInstances::addMod( __CLASS__, self::$_instance);
00043             }
00044         }
00045         return self::$_instance;
00046     }
00047 
00048 
00056     public function prepareCSVField($sInField)
00057     {
00058         $oStr = getStr();
00059         if ($oStr->strstr($sInField, '"')) {
00060             return '"'.str_replace('"', '""', $sInField).'"';
00061         } elseif ($oStr->strstr($sInField, ';')) {
00062             return '"'.$sInField.'"';
00063         }
00064         return $sInField;
00065     }
00066 
00077     public function minimizeTruncateString( $sString, $iLength )
00078     {
00079         //leading and ending whitespaces
00080         $sString = trim( $sString );
00081         $oStr = getStr();
00082 
00083         //multiple whitespaces
00084         $sString = $oStr->preg_replace( "/[ \t\n\r]+/", " ", $sString );
00085         if ( $oStr->strlen( $sString ) > $iLength && $iLength != -1 ) {
00086             $sString = $oStr->substr( $sString, 0, $iLength );
00087         }
00088 
00089         $sString = $oStr->preg_replace( "/,+$/", "", $sString );
00090         return $sString;
00091     }
00092 
00100     public function prepareStrForSearch($sSearchStr)
00101     {
00102         $oStr = getStr();
00103         if ( $oStr->hasSpecialChars( $sSearchStr ) ) {
00104             return $oStr->recodeEntities( $sSearchStr, true, array( '&amp;' ), array( '&' ) );
00105         }
00106 
00107         return '';
00108     }
00109 }