oxutilsstring.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxUtilsString
00007 {
00013     private static $_instance = null;
00014 
00020     public static function getInstance()
00021     {
00022         // disable caching for test modules
00023         if ( defined( 'OXID_PHP_UNIT' ) ) {
00024             static $inst = array();
00025             self::$_instance = $inst[oxClassCacheKey()];
00026         }
00027 
00028         if ( !self::$_instance instanceof oxUtilsString ) {
00029 
00030 
00031             self::$_instance = oxNew( 'oxUtilsString' );
00032 
00033             if ( defined( 'OXID_PHP_UNIT' ) ) {
00034                 $inst[oxClassCacheKey()] = self::$_instance;
00035             }
00036         }
00037         return self::$_instance;
00038     }
00039 
00040 
00048     public function prepareCSVField($sInField)
00049     {
00050         $oStr = getStr();
00051         if ($oStr->strstr($sInField, '"')) {
00052             return '"'.str_replace('"', '""', $sInField).'"';
00053         } elseif ($oStr->strstr($sInField, ';')) {
00054             return '"'.$sInField.'"';
00055         }
00056         return $sInField;
00057     }
00058 
00069     public function minimizeTruncateString( $sString, $iLength )
00070     {
00071         //leading and ending whitespaces
00072         $sString = trim( $sString );
00073 
00074         //multiple whitespaces
00075         $sString = ereg_replace( "[ \t\n\r]+", " ", $sString );
00076         $oStr = getStr();
00077         if ( $oStr->strlen( $sString ) > $iLength && $iLength != -1 ) {
00078             $sString = $oStr->substr( $sString, 0, $iLength );
00079         }
00080 
00081         $sString = preg_replace( "/,+$/", "", $sString );
00082         return $sString;
00083     }
00084 
00092     public function prepareStrForSearch($sSearchStr)
00093     {
00094         $oStr = getStr();
00095         if ( $oStr->hasSpecialChars( $sSearchStr ) ) {
00096             return $oStr->recodeEntities( $sSearchStr, true, array( '&amp;' ), array( '&' ) );
00097         }
00098 
00099         return '';
00100     }
00101 }

Generated on Wed Jun 17 12:09:02 2009 for OXID eShop CE by  doxygen 1.5.5